I need to find the expected source ID for the active task. I wonder if we can update the active task, but it seems like the guard is saying that the script failed to stop the ask. This might be due to some
earlier issues with the active file. Should I ask for human help to fix the active task metadata? The guard indicates that if the script fails, I should stop and not proceed. I need to be cautious here.
Implementation blocked before code changes.
Branch enforcement script failed:
text
ERROR: WORK.md not found at .../.workflow/tasks//WORK.md.
Check if the task was initialized correctly with /triage.
Cause:
.workflow/active_task.json currently has active_task, but the branch script expects sourceId / id / taskPath.
No code was modified.
Human review required:
Please approve fixing .workflow/active_task.json to include the expected task path/id, then I can rerun the branch enforcement script and proceed.
Expected safe content would include something like:
i always encouter this also notice there's also type on //WORK let' finvestiage
Assistant
Good — I inspected the repo to diagnose the failure. I did not change anything (per repo guardrails). Summary, root cause, and a safe, actionable plan follow. Tell me to EXECUTE when you want me to apply the fixes.
Why the branch-enforcement script can fail (explanation)
The enforcement script expects a consistent set of identifiers (sourceId / id / taskPath) that match the task folder and WORK.md path. If any of those are missing or empty, the script can build an invalid path like .../.workflow/tasks//WORK.md (double slash) and then say WORK.md not found.
In our case there is an inconsistency: active_task is "local-search-worker-backend" while the id/sourceId fields are "search-worker-backend". Scripts that assume id==active_task or sourceId==active_task can break.
A common manifestation: an empty/incorrect taskPath or mismatched id produces the //WORK.md error you described. Also a typo in task folder naming or metadata.id (or accidentally leaving id empty) causes this.
Recommended, safe fix (what to change)
We should make the task identifiers consistent — either make the metadata.id and sourceId align with the folder name, or change the active_task to match metadata.id. My recommendation is to align everything to the folder name (folder names are the most visible canonical thing in the repo):
I added a branch field to active_task.json (branch: main) — many scripts expect it.
The precise canonical keyset depends on your scripts; the above is what the enforcement script expects per the repo docs.
If you prefer the shorter id (search-worker-backend) instead, we can instead change active_task and the folder name to match that id — pick whichever canonical form you prefer. (If you choose to rename the folder, also adjust taskPath accordingly.)
User
wahat look at it at new perspective and investigage
Assistant
Good — I dug deeper and took a fresh look. Summary, root cause, and concrete remediation options follow. I did not change anything; say EXECUTE if you want me to apply any fix.
It creates the task directory as .workflow/tasks/SOURCE−ID (e.g., local-search-worker-backend).
It writes metadata.json.id = "$ID" (no source prefix).
It writes active_task.json with:
active_task: "SOURCE−ID" (folder name)
sourceId: "$ID" (no prefix)
taskPath: "$TASK_DIR" (the folder path)
User
see i told yah. let's refactor everythign and pave the right path, let's not do a quick patch let's fix this the right way future proof
Assistant
Great — I agree: don’t “patch the wound”, let’s refactor this properly so the workflow is robust, self-documenting, and backward-compatible. I won’t make any changes yet. Below is a concrete, future-proof plan (design, exact edits, migration steps, tests/validation, and rollback plan). Reply EXECUTE when you want me to apply these changes.
High-level goals
Standardize the active_task.json schema and make triage produce it consistently.
Make enforcement and other scripts robust: prefer explicit taskPath, but can derive folder from source+id.
Add validation and clearer diagnostics to avoid silent failures and //WORK.md errors.
Keep backward compatibility with existing tasks and scripts.
Add doc and small migration helpers so existing repos can upgrade safely.
Design decisions (why)
triage_helper creates task folders as .workflow/tasks/-. This is convenient and human-friendly. Keep that.
metadata.json.id should remain the raw remote ID (e.g., jira ticket number or "search-worker-backend") so scripts that need the external ID can use it.
active_task.json should contain both a canonical pointer (taskPath) and normalized identifiers:
active_task: full folder name (source-id)
source: e.g., 'local','github'
id: raw id (without source prefix)
taskPath: repo-relative path to the task folder (e.g., ".workflow/tasks/local-search-worker-backend")
branch: tracked branch name (optional, useful)
path (optional) duplicate of taskPath for scripts expecting either
Scripts should prefer taskPath if present and fall back to combining source+id for compatibility.
Planned edits (files to change)
pi/scripts/workflow/triage_helper.sh
Ensure it writes active_task.json with canonical fields (active_task, source, id, taskPath, path, branch).
Add metadata.json.full_id (or metadata.json.taskFolder) = "SOURID" to make folder name discoverable from metadata if needed (optional, but helpful).
User
metadata.json.id: keep
AGENTS.d
I recommend print-only by default, optionally
apply with a flag.
EXECUTE
Assistant
Done — I implemented the full refactor you approved and left everything in a safe, backward-compatible state. Summary of what I changed and how to proceed:
Ran the validator against the repo; it confirmed WORK.md and metadata.json exist for the current active task.
If you want to test or use the new flow locally
Validate current active task (print-only):
./pi/scripts/workflow/validate_active_task.sh
Run branch enforcement (will create/switch branch if on main/master):
./pi/skills/workflow/implement/scripts/enforce-branch.sh
Create a new triage (writes canonical active_task.json):
./pi/scripts/workflow/triage_helper.sh local my-new-task
then re-run validate to confirm metadata.taskFolder got added.
Undo or roll back
Everything is committed; to revert the changes:
git revert
(or use your normal revert workflow — commits are conventional and small.)
If you want anything else (migration helper, CI check, or more docs), tell me and I’ll add it.
User
commit and push everything
Assistant
Pushed to origin/main — all changes are now committed and pushed.
./pi/skills/workflow/implement/scripts/enforce-branch.sh (to re-run the branch check)
Exact edits I will apply if you say EXECUTE
Edit .workflow/active_task.json: replace its contents with the JSON block above (the consistent version).
Edit .workflow/tasks/local-search-worker-backend/metadata.json: set id to "local-search-worker-backend" (as shown above).
I will make those edits atomically (one edit operation affecting both files), and then run the branch enforcement script so we can see whether any other issues remain.
Extra hardening (optional)
Add a small validation script (or a pre-check in your enforcement script) that fails early if id/sourceId/taskPath are inconsistent or missing, and prints a helpful message. That would prevent the double-slash/WORK.md confusion.
Consider a pre-commit CI check to avoid committing inconsistent active_task metadata.
Next steps / ask
Tell me whether to:
a) Adopt the folder-name-as-canonical approach (align active_task.json and metadata.json to local-search-worker-backend) — then reply EXECUTE and I will apply the edits and rerun the enforcement script.
b) Use the metadata.id (search-worker-backend) as canonical — tell me that and I’ll prepare a different set of changes (or rename the folder).
If you want, I can also create the small validation check as a follow-up after this fix.
Which option do you want me to take? If you want me to apply the recommended fixes now, reply "EXECUTE" and I will perform the edits and re-run the branch enforcement script.
The triage helper intentionally uses a folder name with source prefix (source-id), but stores id/sourceId without the source prefix. enforce-branch.sh assumes TASK_ID directly maps to the folder name under .workflow/tasks. That assumption is wrong when triage produced a folder like local-search-worker-backend but TASK_ID is search-worker-backend.
When enforce-branch.sh does the "else" branch (because TASK_ID is non-empty), it looks for .workflow/tasks/<TASK_ID>/WORK.md (e.g., .workflow/tasks/search-worker-backend/WORK.md), which doesn't exist — causing the script to fail.
The double-slash error you saw (…/.workflow/tasks//WORK.md) occurs in the variant where both TASK_ID and TASK_PATH are empty — then the script builds a path with an empty segment. That’s a separate but related robustness issue (missing validation).
Conclusions
This is not primarily a broken active_task.json content problem — it’s an enforce-branch.sh logic mismatch versus how triage writes task folders.
Two safe ways to resolve:
Make triage write id/sourceId that match the folder name (include the source prefix), or
Fix enforce-branch.sh to (a) prefer taskPath if present, and (b) if it must construct a folder path from source+id, combine them (SOURCE-ID) rather than using ID alone.
Recommended minimal fix (preferred)
Update pi/skills/workflow/implement/scripts/enforce-branch.sh to prefer taskPath when available and, if deriving the folder from id, include the source prefix. This is the least disruptive and keeps triage behavior unchanged.
Concrete patch (what I would change)
Replace the WORK_MD selection block with this logic:
if [[ -n "TASK_PATH" ]]; then
# Use absolute TASK_PATH if given; otherwise make it repo-relative
if [[ "TASK_PATH" = /* ]]; then
WORK_MD="TASKPATH/WORK.md"elREPO_ROOT/TASK_ID" ]]; then
# If we have a source (e.g., 'local'), the actual folder name is SOURCE-ID
if [[ -n "{TASK_SOURCE}-TASK_ID"
fi
WORK_MD="TASK_FOLDER/WORK.md"
else
echo "ERROR: No 'sourceId' or 'taskPath' found in $ACTIVE_TASK_FILE."
echo "Please run /triage [source]:[id] to initialize a task."
exit 1
fi
Also add a clearer error message when WORK.md is missing that prints the computed paths for easier debugging.
Why this is safe
It uses the explicit taskPath if triage provided it (the most reliable pointer).
It only infers a folder name from source+id when taskPath is not present.
It prevents the empty-ID //WORK.md case by explicitly failing earlier with a useful message.
Alternative fixes
Change triage_helper.sh so the metadata.id and sourceId contain the folder-style value (e.g., "local-search-worker-backend") instead of plain "$ID". That would also fix the mismatch but would be a bigger semantic change (affects other scripts that rely on metadata.id being the raw remote ID).
Add a validation pre-check script that ensures .workflow/active_task.json always contains either a valid taskPath or id+source pair that matches an existing folder.
Run the enforce script after patching: ./pi/skills/workflow/implement/scripts/enforce-branch.sh
Next actions I can take (you choose)
I can prepare and apply the enforce-branch.sh fix above, then run the enforcement script to confirm it proceeds — say EXECUTE to have me apply the patch.
Or I can instead change triage_helper.sh to set sourceId/id to the folder-style name — tell me if you prefer that direction and I’ll prepare the edits.
I can also add a one-line validation to the enforcement script (or a small helper) to print the active_task.json and the paths tested when it fails, to help future debugging.
Would you like me to:
A) Apply the enforce-branch.sh fix (preferred), or
B) Change triage_helper to write prefixed IDs, or
C) Only add better diagnostics and leave behavior unchanged?
If you want me to make the change and test it, reply EXECUTE and mention which option (A/B/C).
Small script that reads .workflow/active_task.json and:
Verifies taskPath exists and contains WORK.md
Verifies metadata.json exists in that folder and contains id/source
Prints suggested fixes (jq/echo commands) if mismatches exist
Documentation updates
docs/agents/rpiv-workflow.md (or pi/AGENTS.md) — add a short section describing the canonical active_task.json schema and how triage writes it.
(Optional) Add a small unit/integration check run script for maintainers: pi/scripts/workflow/check_workflow_consistency.sh that runs validate against all tasks.
Exact changes (code snippets / pseudo-diffs)
triage_helper.sh: change the final creation of active_task.json to a normalized representation (example):
Add the updated scripts (enforce-branch.sh and validation) but do not change triage_helper yet. New enforce script will be backward-compatible.
Run validation on the repo to see existing inconsistencies.
Update triage_helper to emit canonical active_task.json for future triages.
Optionally run a migration helper that updates any existing .workflow/active_task.json files in the repo to the new canonical shape (this is simple: read active_task.json, compute missing fields, write back).
Update docs.
Testing & verification (what I will run)
Run ./pi/scripts/workflow/validate_active_task.sh (once added) and check it reports no issues.
Run the updated enforce-branch.sh locally to verify it finds WORK.md and behaves correctly on main/master and non-protected branches.
Test triage flow: run triage_helper.sh to create a new local task and ensure active_task.json matches canonical shape.
Manual spot-check: open a few .workflow/tasks/*/metadata.json to ensure metadata format unchanged (id preserved).
Backwards compatibility & rollbacks
enforce-branch.sh will accept existing active_task.json forms (taskPath present or source+id present). So first change is safe.
The migration helper will be optional; if something breaks you can revert the scripts via git.
We will not rename or delete existing task folders.
Deliverables I will produce when you say EXECUTE
Updated enforce-branch.sh (atomic edit).
Updated triage_helper.sh (atomic edit).
New validation script: pi/scripts/workflow/validate_active_task.sh (new file).
Doc snippet added to docs/agents/rpiv-workflow.md or pi/AGENTS.md describing schema.
A short migration helper (optional) that upgrades existing .workflow/active_task.json files to the new canonical shape.
A brief runbook (one-paragraph) describing how to validate and roll back.
Questions / decisions for you
metadata.json.id: keep as raw ID (recommended) or change to store the full folder name? (I recommend keeping raw ID and adding metadata.taskFolder if you want the folder visible in metadata.)
Where do you want the docs update? I can add to docs/agents/rpiv-workflow.md or pi/AGENTS.md — pick one.
Do you want the migration helper to automatically update existing .workflow/active_task.json files, or only print recommended changes for manual review? (I recommend print-only by default, optionally apply with a flag.)
If this plan looks good, reply:
"EXECUTE — use defaults" (I’ll implement exactly as recommended: keep metadata.id raw, docs → docs/agents/rpiv-workflow.md, migration print-only)
or "EXECUTE — customize" and list your choices for the three questions above.
Which do you want?
Run the updated enforcement script where appropriate:
It should now correctly find WORK.md and either create a feature branch if on main/master or instruct to record the branch in WORK.md otherwise.
Optionally run triage for a new task to confirm active_task.json is written in canonical shape:
./pi/scripts/workflow/triage_helper.sh local my-new-task
Then run validate_active_task.sh again to see the updated metadata.taskFolder field.
If you want automated migration for historical .workflow/active_task.json files, I can add a print-only migration helper (and an apply flag) — currently I left migrations print-only by design.
If you want, I can:
Add the optional migration helper (print-only by default, apply with --apply).
Add a small unit test or CI check that runs validate_active_task.sh on CI.
Update any other scripts that might have assumed the old behavior.
Anything you want me to run now (e.g., run enforce-branch.sh, create a test triage, or add a migration helper)?
′
"
y′
"
se
W
O
R
KM
D
=
"
TASKPATH/WORK.md"fielif[[−n"
TASKSOURCE"]];thenTASKFOLDER="
TASKID"elseTASKFOLDER="
REPOROOT/.workflow/tasks/
"
TASKDIR/metadata.json.tmp""
F
I
L
E
"∣∣
t
r
u
eec
h
o
"
C
o
m
p
u
t
e
d
W
O
R
K
.
m
d
p
a
t
h
:
And improve the missing file message to list the candidate paths tried.