Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f67e2bb729 | ||
|
|
a718f05689 | ||
|
|
3cbb7dcc4b | ||
|
|
e8ad1534ed | ||
|
|
5046267994 | ||
|
|
ecaf63f689 |
@@ -28,7 +28,7 @@ hooks:
|
||||
- type: command
|
||||
command: "SH=\"${CLAUDE_SKILL_DIR}/scripts/skill-hook.sh\"; [ -f \"$SH\" ] || SH=$(ls \"$HOME/.claude/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/plugins/marketplaces/planning-with-files/scripts/skill-hook.sh\" 2>/dev/null | head -1); [ -n \"$SH\" ] && [ -f \"$SH\" ] && sh \"$SH\" --event=precompact; exit 0"
|
||||
metadata:
|
||||
version: "3.17.0"
|
||||
version: "3.17.2"
|
||||
---
|
||||
|
||||
# Planning with Files
|
||||
@@ -40,7 +40,7 @@ Work like Manus: Use persistent markdown files as your "working memory on disk."
|
||||
**Before continuing**, resolve the plan this task owns:
|
||||
|
||||
1. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the task's `PLAN_ID` and `PWF_PLAN_ROOT`. Read `task_plan.md`, `progress.md`, and `findings.md` from that one selected directory. A root `task_plan.md` must not override a selected `.planning/<id>/` plan.
|
||||
2. If an explicit selector is rejected, or session isolation is armed with multiple plans and no `PLAN_ID`, stop plan recovery and correct the pin. Do not fall back to another task. Use the legacy project-root files only when no selector or named plan applies.
|
||||
2. If an explicit selector is rejected, or multiple named plans exist without `PLAN_ID`, stop plan recovery and correct the pin. Do not fall back to another task. Use the legacy project-root files only when no selector or named plan applies.
|
||||
3. Run `git diff --stat` to see code changes that may not yet be recorded in the planning files.
|
||||
|
||||
All planning filenames below refer to this selected directory, even when the shell runs elsewhere. For parallel tasks, pin each host before starting it or use separate worktrees. A worker joining an existing task uses its assigned plan; it must not create or overwrite a competing root plan.
|
||||
@@ -221,7 +221,7 @@ Helper scripts for automation:
|
||||
|
||||
- `scripts/init-session.sh` — Initialize planning files. With a name arg, creates an isolated plan under `.planning/YYYY-MM-DD-<slug>/` for parallel task workflows. Without args, writes `task_plan.md` at project root (legacy mode, backward-compatible).
|
||||
- `scripts/set-active-plan.sh` — Switch the active plan pointer (`.planning/.active_plan`). Run with a plan ID to switch; run without args to show which plan is current.
|
||||
- `scripts/resolve-plan-dir.sh` — Resolve the active plan directory. A set `$PLAN_ID` is a binding: it resolves or resolution stops, never another plan (issue #237). With no `$PLAN_ID`, checks `.planning/.active_plan`, then newest plan dir by mtime, then falls back to project root (legacy). Used internally by hooks.
|
||||
- `scripts/resolve-plan-dir.sh` — Resolve the active plan directory. A set `$PLAN_ID` is a binding: it resolves or resolution stops, never another plan (issue #237). With no `$PLAN_ID`, multiple named plans refuse selection. A single named plan may use `.planning/.active_plan` or discovery by mtime; otherwise resolution falls back to the project root (legacy). Used internally by hooks.
|
||||
- `scripts/check-complete.sh` — Verify all phases in the active plan are complete.
|
||||
- `scripts/session-catchup.py`: Explicit same-project session-record aggregation or bounded replay (`--metadata` / `--replay`); bare invocation does not access host history.
|
||||
- `scripts/attest-plan.sh` (and `.ps1`) — Lock the current `task_plan.md` content with a SHA-256 attestation (v2.37.0). Hooks then refuse to inject plan content if the file diverges from the attested hash. Use `--show` to print the stored hash, `--clear` to remove the attestation. See `/plan-attest` command.
|
||||
|
||||
@@ -404,6 +404,7 @@ function Resolve-PlanFile {
|
||||
$resolver = Join-Path $PSScriptRoot "resolve-plan-dir.ps1"
|
||||
if (-not (Test-Path -LiteralPath $resolver -PathType Leaf)) { return $null }
|
||||
$resolvedDir = @(& $resolver | Where-Object { $_ }) | Select-Object -First 1
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { return $null }
|
||||
if ($resolvedDir) {
|
||||
$planFile = Join-Path $resolvedDir "task_plan.md"
|
||||
return (Resolve-ContainedPlanFile -Candidate $planFile -ExpectedDirectory $resolvedDir)
|
||||
|
||||
@@ -45,6 +45,10 @@ resolve_plan_file() {
|
||||
plan_dir=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
plan_dir="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$plan_dir" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
printf "[plan-attest] Multiple plans are available. Set PLAN_ID=<slug>; nothing was attested.\n" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [ -n "${plan_dir}" ] && [ -f "${plan_dir}/task_plan.md" ]; then
|
||||
printf "%s\n" "${plan_dir}/task_plan.md"
|
||||
|
||||
@@ -35,6 +35,7 @@ if ($PlanFile -ne "") {
|
||||
try {
|
||||
$resolvedDir = (& $resolver 2>$null | Select-Object -First 1)
|
||||
if ($null -eq $resolvedDir) { $resolvedDir = "" }
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { exit 0 }
|
||||
} catch {
|
||||
$resolvedDir = ""
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ else
|
||||
RESOLVED_DIR=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
RESOLVED_DIR="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$RESOLVED_DIR" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ -n "${RESOLVED_DIR}" ] && [ -f "${RESOLVED_DIR}/task_plan.md" ]; then
|
||||
PLAN_FILE="${RESOLVED_DIR}/task_plan.md"
|
||||
|
||||
@@ -59,12 +59,9 @@ Windows runs the shell chain through Git Bash and nothing else:
|
||||
one turn-marker slot and one progress-guard slot per plan.
|
||||
|
||||
Known, accepted differences from the shell reference:
|
||||
* Two plan directories with the same whole-second mtime, no .active_plan
|
||||
and no PLAN_ID: the reference picks the first in the shell's glob order
|
||||
(locale collation), this twin the first in code-point order. The same
|
||||
collation difference can change which three of four or more nested
|
||||
projects the ambiguity notice names. A machine runs one implementation,
|
||||
so neither choice flips within a session.
|
||||
* Shell glob order follows locale collation; this twin uses code-point
|
||||
order. This can change which three of four or more nested projects the
|
||||
ambiguity notice names.
|
||||
* BSD sed (macOS) appends a newline to a progress.md whose last line has
|
||||
none; GNU sed and this twin do not.
|
||||
* With PWF_PLAN_ROOT set under Git Bash the shell sees the pin as typed
|
||||
@@ -837,6 +834,16 @@ class Injector(object):
|
||||
scope = ""
|
||||
explicit = bool(plan_prefix)
|
||||
plan_id = env.get("PLAN_ID", "")
|
||||
ambiguous = plan_is_ambiguous(
|
||||
plan_prefix + ".planning", plan_root_pin if plan_root_pin else ".", plan_id
|
||||
)
|
||||
if ambiguous and (context == "preflight" or not is_dir(plan_prefix + ".planning/sessions")):
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> "
|
||||
"for this session; nothing injected."
|
||||
)
|
||||
raise Bail()
|
||||
if plan_id:
|
||||
if slug_is_valid(plan_id) and is_dir(plan_prefix + ".planning/" + plan_id):
|
||||
resolved = plan_prefix + ".planning/" + plan_id
|
||||
@@ -923,30 +930,14 @@ class Injector(object):
|
||||
"single-session mode."
|
||||
)
|
||||
raise Bail()
|
||||
if not plan_id:
|
||||
plan_n = 1 if is_file(plan_prefix + "task_plan.md") else 0
|
||||
try:
|
||||
names = sorted(os.listdir(plan_prefix + ".planning"))
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if name.startswith("."):
|
||||
continue
|
||||
if not is_file(plan_prefix + ".planning/" + name + "/task_plan.md"):
|
||||
continue
|
||||
if not slug_is_valid(name):
|
||||
continue
|
||||
plan_n += 1
|
||||
if plan_n > 1:
|
||||
break
|
||||
if plan_n > 1:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
if ambiguous:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
|
||||
if not explicit:
|
||||
nested = []
|
||||
@@ -1326,6 +1317,23 @@ def inject(context, env=None):
|
||||
# Twin of resolve-plan-dir.sh (the shared resolver the dispatcher uses).
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def plan_is_ambiguous(plan_root, project_root, plan_id=""):
|
||||
"""A project pointer or mtime cannot bind a session to multiple plans."""
|
||||
if plan_id:
|
||||
return False
|
||||
count = 1 if is_dir(plan_root + "/sessions") and is_file(project_root + "/task_plan.md") else 0
|
||||
try:
|
||||
names = os.listdir(plan_root)
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if slug_is_valid(name) and is_file(plan_root + "/" + name + "/task_plan.md"):
|
||||
count += 1
|
||||
if count > 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def resolve_plan_dir(env=None):
|
||||
"""Return (spelled, filesystem) paths of the plan directory, or ("", "").
|
||||
|
||||
@@ -1360,6 +1368,9 @@ def resolve_plan_dir(env=None):
|
||||
return found(plan_id)
|
||||
return ("", "")
|
||||
|
||||
if plan_is_ambiguous(fs_root, pin if pin else "."):
|
||||
return ("", "")
|
||||
|
||||
active_file = fs_root + "/.active_plan"
|
||||
if is_file(active_file):
|
||||
try:
|
||||
@@ -1441,6 +1452,8 @@ class ClaudeDispatcher(object):
|
||||
return (spelled, fs)
|
||||
if self.env.get("PLAN_ID", "") or self.env.get("PWF_PLAN_ROOT", ""):
|
||||
return ("", "")
|
||||
if plan_is_ambiguous(".planning", "."):
|
||||
return ("", "")
|
||||
if is_file("task_plan.md"):
|
||||
return (".", ".")
|
||||
return ("", "")
|
||||
|
||||
@@ -254,6 +254,29 @@ is_within_root() {
|
||||
# The .active_plan pointer, the newest-by-mtime fallback, and the legacy root
|
||||
# task_plan.md are cwd GUESSES — only guesses are subject to the nested-root
|
||||
# conflict check below.
|
||||
# Shared .active_plan and directory mtime cannot identify this session's plan.
|
||||
# Check before selection or preflight, even when isolation was never armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_PREFIX}.planning/sessions" ] && [ -f "${PLAN_PREFIX}task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ] && { [ "$CONTEXT" = "preflight" ] || [ ! -d "${PLAN_PREFIX}.planning/sessions" ]; }; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
RESOLVED=""
|
||||
SCOPE=""
|
||||
EXPLICIT=0
|
||||
@@ -442,27 +465,13 @@ PY
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# An attachment admits a session but does not select one of several plans.
|
||||
# When isolation is armed, require PLAN_ID if more than one live same-root
|
||||
# candidate exists. PWF_PLAN_ROOT selects the project root, not a plan
|
||||
# within that root.
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
SESSION_PLAN_N=0
|
||||
[ -f "${PLAN_PREFIX}task_plan.md" ] && SESSION_PLAN_N=1
|
||||
for candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$candidate" ] || continue
|
||||
candidate_dir="${candidate%/task_plan.md}"
|
||||
candidate_slug="${candidate_dir##*/}"
|
||||
slug_is_valid "$candidate_slug" || continue
|
||||
SESSION_PLAN_N=$((SESSION_PLAN_N + 1))
|
||||
[ "$SESSION_PLAN_N" -gt 1 ] && break
|
||||
done
|
||||
if [ "$SESSION_PLAN_N" -gt 1 ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
# Attachment admits a session but does not select its plan. Preserve the
|
||||
# attachment-first notice above for sessions that never opted in.
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
# junction/symlink escape; slug validation alone blocks textual traversal.
|
||||
|
||||
param(
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning")
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning"),
|
||||
[switch]$CheckAmbiguity
|
||||
)
|
||||
|
||||
$projectRoot = (Get-Location).Path
|
||||
@@ -137,6 +138,30 @@ $activeFile = Join-Path $PlanRoot ".active_plan"
|
||||
# at rc=0. Emptiness is the fail-closed signal on this channel, matching
|
||||
# resolve-plan-dir.sh and the PWF_PLAN_ROOT pin. An empty $env:PLAN_ID is
|
||||
# falsy here and still means "unset".
|
||||
# The optional probe distinguishes ambiguity from a legacy-root fallback.
|
||||
# Multiple named plans require PLAN_ID even without a sessions directory.
|
||||
$planCount = 0
|
||||
if (-not $env:PLAN_ID) {
|
||||
if ((Test-Path -LiteralPath (Join-Path $PlanRoot "sessions") -PathType Container) -and
|
||||
(Test-Path -LiteralPath (Join-Path $projectRoot "task_plan.md") -PathType Leaf)) {
|
||||
$planCount = 1
|
||||
}
|
||||
if (Test-Path -LiteralPath $PlanRoot -PathType Container) {
|
||||
foreach ($entry in (Get-ChildItem -LiteralPath $PlanRoot -Directory -ErrorAction SilentlyContinue)) {
|
||||
if ((Test-ValidSlug $entry.Name) -and
|
||||
(Test-Path -LiteralPath (Join-Path $entry.FullName "task_plan.md") -PathType Leaf)) {
|
||||
$planCount++
|
||||
if ($planCount -gt 1) { break }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($CheckAmbiguity) {
|
||||
if ($planCount -gt 1) { Write-Output "PWF_PLAN_AMBIGUOUS_V1" }
|
||||
exit 0
|
||||
}
|
||||
if ($planCount -gt 1) { exit 0 }
|
||||
|
||||
if ($env:PLAN_ID) {
|
||||
if (Test-ValidSlug $env:PLAN_ID) {
|
||||
$candidate = Join-Path $PlanRoot $env:PLAN_ID
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
"name": "planning-with-files",
|
||||
"source": "./",
|
||||
"description": "Persistent project planning files with lifecycle hooks that inject selected plan context. Automatic recovery uses project files only. Explicit catchup modes may read same-project local session records to emit aggregate counts or bounded nonce-framed excerpts. Optional gated mode can request continuation on capable hosts and never runs commands declared in Markdown. No network upload path. Installs across 60+ agents.",
|
||||
"version": "3.17.0"
|
||||
"version": "3.17.2"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "planning-with-files",
|
||||
"version": "3.17.0",
|
||||
"version": "3.17.2",
|
||||
"description": "Persistent project planning files with lifecycle hooks that inject selected plan context. Automatic recovery uses project files only. Explicit catchup modes may read same-project local session records to emit aggregate counts or bounded nonce-framed excerpts. Optional gated mode can request continuation on capable hosts and never runs commands declared in Markdown. No network upload path. Works across 60+ agents and includes Arabic, German, Spanish, Simplified Chinese, and Traditional Chinese.",
|
||||
"author": {
|
||||
"name": "OthmanAdi",
|
||||
|
||||
@@ -36,7 +36,7 @@ hooks:
|
||||
- type: command
|
||||
command: "SH=\"\"; for c in \"${PWF_SCRIPT_DIR}/skill-hook.sh\" \"${CLAUDE_SKILL_DIR}/scripts/skill-hook.sh\" \"${CODEBUDDY_PLUGIN_ROOT}/scripts/skill-hook.sh\" \"$HOME/.codebuddy/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/plugins/marketplaces/planning-with-files/scripts/skill-hook.sh\"; do [ -f \"$c\" ] && { SH=\"$c\"; break; }; done; [ -n \"$SH\" ] && sh \"$SH\" --event=precompact; exit 0"
|
||||
metadata:
|
||||
version: "3.17.0"
|
||||
version: "3.17.2"
|
||||
|
||||
---
|
||||
|
||||
@@ -46,7 +46,7 @@ Work like Manus: Use persistent markdown files as your "working memory on disk."
|
||||
|
||||
## FIRST: Restore Project State
|
||||
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or session isolation is armed with multiple plans and no `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or multiple named plans exist without `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
|
||||
```bash
|
||||
# Linux/macOS — auto-detects skill directory (plugin env or default install path)
|
||||
|
||||
@@ -404,6 +404,7 @@ function Resolve-PlanFile {
|
||||
$resolver = Join-Path $PSScriptRoot "resolve-plan-dir.ps1"
|
||||
if (-not (Test-Path -LiteralPath $resolver -PathType Leaf)) { return $null }
|
||||
$resolvedDir = @(& $resolver | Where-Object { $_ }) | Select-Object -First 1
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { return $null }
|
||||
if ($resolvedDir) {
|
||||
$planFile = Join-Path $resolvedDir "task_plan.md"
|
||||
return (Resolve-ContainedPlanFile -Candidate $planFile -ExpectedDirectory $resolvedDir)
|
||||
|
||||
@@ -45,6 +45,10 @@ resolve_plan_file() {
|
||||
plan_dir=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
plan_dir="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$plan_dir" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
printf "[plan-attest] Multiple plans are available. Set PLAN_ID=<slug>; nothing was attested.\n" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [ -n "${plan_dir}" ] && [ -f "${plan_dir}/task_plan.md" ]; then
|
||||
printf "%s\n" "${plan_dir}/task_plan.md"
|
||||
|
||||
@@ -35,6 +35,7 @@ if ($PlanFile -ne "") {
|
||||
try {
|
||||
$resolvedDir = (& $resolver 2>$null | Select-Object -First 1)
|
||||
if ($null -eq $resolvedDir) { $resolvedDir = "" }
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { exit 0 }
|
||||
} catch {
|
||||
$resolvedDir = ""
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ else
|
||||
RESOLVED_DIR=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
RESOLVED_DIR="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$RESOLVED_DIR" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ -n "${RESOLVED_DIR}" ] && [ -f "${RESOLVED_DIR}/task_plan.md" ]; then
|
||||
PLAN_FILE="${RESOLVED_DIR}/task_plan.md"
|
||||
|
||||
@@ -59,12 +59,9 @@ Windows runs the shell chain through Git Bash and nothing else:
|
||||
one turn-marker slot and one progress-guard slot per plan.
|
||||
|
||||
Known, accepted differences from the shell reference:
|
||||
* Two plan directories with the same whole-second mtime, no .active_plan
|
||||
and no PLAN_ID: the reference picks the first in the shell's glob order
|
||||
(locale collation), this twin the first in code-point order. The same
|
||||
collation difference can change which three of four or more nested
|
||||
projects the ambiguity notice names. A machine runs one implementation,
|
||||
so neither choice flips within a session.
|
||||
* Shell glob order follows locale collation; this twin uses code-point
|
||||
order. This can change which three of four or more nested projects the
|
||||
ambiguity notice names.
|
||||
* BSD sed (macOS) appends a newline to a progress.md whose last line has
|
||||
none; GNU sed and this twin do not.
|
||||
* With PWF_PLAN_ROOT set under Git Bash the shell sees the pin as typed
|
||||
@@ -837,6 +834,16 @@ class Injector(object):
|
||||
scope = ""
|
||||
explicit = bool(plan_prefix)
|
||||
plan_id = env.get("PLAN_ID", "")
|
||||
ambiguous = plan_is_ambiguous(
|
||||
plan_prefix + ".planning", plan_root_pin if plan_root_pin else ".", plan_id
|
||||
)
|
||||
if ambiguous and (context == "preflight" or not is_dir(plan_prefix + ".planning/sessions")):
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> "
|
||||
"for this session; nothing injected."
|
||||
)
|
||||
raise Bail()
|
||||
if plan_id:
|
||||
if slug_is_valid(plan_id) and is_dir(plan_prefix + ".planning/" + plan_id):
|
||||
resolved = plan_prefix + ".planning/" + plan_id
|
||||
@@ -923,30 +930,14 @@ class Injector(object):
|
||||
"single-session mode."
|
||||
)
|
||||
raise Bail()
|
||||
if not plan_id:
|
||||
plan_n = 1 if is_file(plan_prefix + "task_plan.md") else 0
|
||||
try:
|
||||
names = sorted(os.listdir(plan_prefix + ".planning"))
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if name.startswith("."):
|
||||
continue
|
||||
if not is_file(plan_prefix + ".planning/" + name + "/task_plan.md"):
|
||||
continue
|
||||
if not slug_is_valid(name):
|
||||
continue
|
||||
plan_n += 1
|
||||
if plan_n > 1:
|
||||
break
|
||||
if plan_n > 1:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
if ambiguous:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
|
||||
if not explicit:
|
||||
nested = []
|
||||
@@ -1326,6 +1317,23 @@ def inject(context, env=None):
|
||||
# Twin of resolve-plan-dir.sh (the shared resolver the dispatcher uses).
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def plan_is_ambiguous(plan_root, project_root, plan_id=""):
|
||||
"""A project pointer or mtime cannot bind a session to multiple plans."""
|
||||
if plan_id:
|
||||
return False
|
||||
count = 1 if is_dir(plan_root + "/sessions") and is_file(project_root + "/task_plan.md") else 0
|
||||
try:
|
||||
names = os.listdir(plan_root)
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if slug_is_valid(name) and is_file(plan_root + "/" + name + "/task_plan.md"):
|
||||
count += 1
|
||||
if count > 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def resolve_plan_dir(env=None):
|
||||
"""Return (spelled, filesystem) paths of the plan directory, or ("", "").
|
||||
|
||||
@@ -1360,6 +1368,9 @@ def resolve_plan_dir(env=None):
|
||||
return found(plan_id)
|
||||
return ("", "")
|
||||
|
||||
if plan_is_ambiguous(fs_root, pin if pin else "."):
|
||||
return ("", "")
|
||||
|
||||
active_file = fs_root + "/.active_plan"
|
||||
if is_file(active_file):
|
||||
try:
|
||||
@@ -1441,6 +1452,8 @@ class ClaudeDispatcher(object):
|
||||
return (spelled, fs)
|
||||
if self.env.get("PLAN_ID", "") or self.env.get("PWF_PLAN_ROOT", ""):
|
||||
return ("", "")
|
||||
if plan_is_ambiguous(".planning", "."):
|
||||
return ("", "")
|
||||
if is_file("task_plan.md"):
|
||||
return (".", ".")
|
||||
return ("", "")
|
||||
|
||||
@@ -254,6 +254,29 @@ is_within_root() {
|
||||
# The .active_plan pointer, the newest-by-mtime fallback, and the legacy root
|
||||
# task_plan.md are cwd GUESSES — only guesses are subject to the nested-root
|
||||
# conflict check below.
|
||||
# Shared .active_plan and directory mtime cannot identify this session's plan.
|
||||
# Check before selection or preflight, even when isolation was never armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_PREFIX}.planning/sessions" ] && [ -f "${PLAN_PREFIX}task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ] && { [ "$CONTEXT" = "preflight" ] || [ ! -d "${PLAN_PREFIX}.planning/sessions" ]; }; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
RESOLVED=""
|
||||
SCOPE=""
|
||||
EXPLICIT=0
|
||||
@@ -442,27 +465,13 @@ PY
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# An attachment admits a session but does not select one of several plans.
|
||||
# When isolation is armed, require PLAN_ID if more than one live same-root
|
||||
# candidate exists. PWF_PLAN_ROOT selects the project root, not a plan
|
||||
# within that root.
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
SESSION_PLAN_N=0
|
||||
[ -f "${PLAN_PREFIX}task_plan.md" ] && SESSION_PLAN_N=1
|
||||
for candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$candidate" ] || continue
|
||||
candidate_dir="${candidate%/task_plan.md}"
|
||||
candidate_slug="${candidate_dir##*/}"
|
||||
slug_is_valid "$candidate_slug" || continue
|
||||
SESSION_PLAN_N=$((SESSION_PLAN_N + 1))
|
||||
[ "$SESSION_PLAN_N" -gt 1 ] && break
|
||||
done
|
||||
if [ "$SESSION_PLAN_N" -gt 1 ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
# Attachment admits a session but does not select its plan. Preserve the
|
||||
# attachment-first notice above for sessions that never opted in.
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
# junction/symlink escape; slug validation alone blocks textual traversal.
|
||||
|
||||
param(
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning")
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning"),
|
||||
[switch]$CheckAmbiguity
|
||||
)
|
||||
|
||||
$projectRoot = (Get-Location).Path
|
||||
@@ -137,6 +138,30 @@ $activeFile = Join-Path $PlanRoot ".active_plan"
|
||||
# at rc=0. Emptiness is the fail-closed signal on this channel, matching
|
||||
# resolve-plan-dir.sh and the PWF_PLAN_ROOT pin. An empty $env:PLAN_ID is
|
||||
# falsy here and still means "unset".
|
||||
# The optional probe distinguishes ambiguity from a legacy-root fallback.
|
||||
# Multiple named plans require PLAN_ID even without a sessions directory.
|
||||
$planCount = 0
|
||||
if (-not $env:PLAN_ID) {
|
||||
if ((Test-Path -LiteralPath (Join-Path $PlanRoot "sessions") -PathType Container) -and
|
||||
(Test-Path -LiteralPath (Join-Path $projectRoot "task_plan.md") -PathType Leaf)) {
|
||||
$planCount = 1
|
||||
}
|
||||
if (Test-Path -LiteralPath $PlanRoot -PathType Container) {
|
||||
foreach ($entry in (Get-ChildItem -LiteralPath $PlanRoot -Directory -ErrorAction SilentlyContinue)) {
|
||||
if ((Test-ValidSlug $entry.Name) -and
|
||||
(Test-Path -LiteralPath (Join-Path $entry.FullName "task_plan.md") -PathType Leaf)) {
|
||||
$planCount++
|
||||
if ($planCount -gt 1) { break }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($CheckAmbiguity) {
|
||||
if ($planCount -gt 1) { Write-Output "PWF_PLAN_AMBIGUOUS_V1" }
|
||||
exit 0
|
||||
}
|
||||
if ($planCount -gt 1) { exit 0 }
|
||||
|
||||
if ($env:PLAN_ID) {
|
||||
if (Test-ValidSlug $env:PLAN_ID) {
|
||||
$candidate = Join-Path $PlanRoot $env:PLAN_ID
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "planning-with-files",
|
||||
"version": "3.17.0",
|
||||
"version": "3.17.2",
|
||||
"description": "Persistent project planning for Codex. Opt-in lifecycle hooks inject selected plan context; automatic recovery uses project files only. Explicit catchup modes may read same-project local session records to emit aggregate counts or bounded nonce-framed excerpts. Optional gated mode can request continuation on capable hosts and never runs Markdown-declared commands. No network upload path.",
|
||||
"author": {
|
||||
"name": "OthmanAdi",
|
||||
@@ -8,6 +8,7 @@
|
||||
},
|
||||
"repository": "https://github.com/OthmanAdi/planning-with-files",
|
||||
"license": "MIT",
|
||||
"commands": [],
|
||||
"skills": "./.agents/skills/",
|
||||
"hooks": "./hooks/codex-hooks.json"
|
||||
}
|
||||
|
||||
@@ -17,8 +17,8 @@ HOOK_DIR = Path(__file__).resolve().parent
|
||||
_SAFE_LEGACY_SESSION_ID = re.compile(r"[A-Za-z0-9][A-Za-z0-9._-]{0,127}\Z")
|
||||
_PLAN_SLUG = re.compile(r"[A-Za-z0-9_][A-Za-z0-9._-]*\Z")
|
||||
SESSION_PLAN_BINDING_NOTICE = (
|
||||
"[planning-with-files] Multiple plans are available while session isolation "
|
||||
"is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
"[planning-with-files] Multiple plans are available. "
|
||||
"Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
)
|
||||
_DARWIN_SYSTEM_ALIASES = {
|
||||
Path("/var"): Path("/private/var"),
|
||||
@@ -223,23 +223,21 @@ def session_plan_requires_binding(root: Path) -> bool:
|
||||
"""Require PLAN_ID when an attached session can resolve multiple plans.
|
||||
|
||||
Session sentinels admit a session to planning context. They do not select a
|
||||
plan. Once isolation is armed, an unbound session may use legacy resolution
|
||||
only when the effective root has at most one live plan candidate.
|
||||
plan. Multiple named plans always require a pin. With isolation armed,
|
||||
a legacy root plan also counts as a competing candidate.
|
||||
"""
|
||||
if os.environ.get("PLAN_ID", ""):
|
||||
return False
|
||||
|
||||
sessions_dir = root / ".planning" / "sessions"
|
||||
try:
|
||||
sessions_info = sessions_dir.lstat()
|
||||
if _is_reparse_or_link(sessions_dir) or not stat.S_ISDIR(sessions_info.st_mode):
|
||||
return False
|
||||
except (FileNotFoundError, OSError, RuntimeError):
|
||||
armed = sessions_dir.exists() or sessions_dir.is_symlink()
|
||||
planning_dir = root / ".planning"
|
||||
if not planning_dir.exists():
|
||||
return False
|
||||
|
||||
candidates = 0
|
||||
try:
|
||||
if (root / "task_plan.md").is_file():
|
||||
if armed and (root / "task_plan.md").is_file():
|
||||
candidates += 1
|
||||
planning_dir = root / ".planning"
|
||||
for child in planning_dir.iterdir():
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
|
||||
HOOK_DIR="$(cd "$(dirname "$0")" 2>/dev/null && pwd)"
|
||||
PLAN_DIR="$(sh "${HOOK_DIR}/resolve-plan-dir.sh" 2>/dev/null)"
|
||||
if [ -z "$PLAN_DIR" ] && [ "$(sh "${HOOK_DIR}/resolve-plan-dir.sh" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
# An explicit PLAN_ID is a binding, not a hint (issue #237). When the shared
|
||||
# resolver rejected one it emits nothing, and the legacy-root fallback below
|
||||
# would answer for a plan the operator never named. Stay silent instead; the
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
|
||||
HOOK_DIR="$(cd "$(dirname "$0")" 2>/dev/null && pwd)"
|
||||
PLAN_DIR="$(sh "${HOOK_DIR}/resolve-plan-dir.sh" 2>/dev/null)"
|
||||
if [ -z "$PLAN_DIR" ] && [ "$(sh "${HOOK_DIR}/resolve-plan-dir.sh" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
# An explicit PLAN_ID is a binding, not a hint (issue #237). When the shared
|
||||
# resolver rejected one it emits nothing, and the legacy-root fallback below
|
||||
# would carry the wrong plan through compaction, which is the one moment the
|
||||
|
||||
@@ -10,6 +10,9 @@ fi
|
||||
|
||||
HOOK_DIR="$(cd "$(dirname "$0")" 2>/dev/null && pwd)"
|
||||
PLAN_DIR="$(sh "${HOOK_DIR}/resolve-plan-dir.sh" 2>/dev/null)"
|
||||
if [ -z "$PLAN_DIR" ] && [ "$(sh "${HOOK_DIR}/resolve-plan-dir.sh" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
# An explicit PLAN_ID is a binding, not a hint (issue #237). When the shared
|
||||
# resolver rejected one it emits nothing, and the legacy-root fallback below
|
||||
# would recite a plan the operator never named on every tool call. Stay silent
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
|
||||
HOOK_DIR="$(cd "$(dirname "$0")" 2>/dev/null && pwd)"
|
||||
PLAN_DIR="$(sh "${HOOK_DIR}/resolve-plan-dir.sh" 2>/dev/null)"
|
||||
if [ -z "$PLAN_DIR" ] && [ "$(sh "${HOOK_DIR}/resolve-plan-dir.sh" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
# An explicit PLAN_ID is a binding, not a hint (issue #237). When the shared
|
||||
# resolver rejected one it emits nothing, and the legacy-root fallback below
|
||||
# would decide whether this run may stop from a plan the operator never named.
|
||||
|
||||
@@ -76,6 +76,10 @@ fi
|
||||
# Resolve and confirm a contained plan before probing or executing any Python
|
||||
# candidate. No-plan hook fires remain shell-only and silent.
|
||||
PLAN_DIR="$(sh "${HOOK_DIR}/resolve-plan-dir.sh" 2>/dev/null)"
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "$PLAN_DIR" ] && [ "$(sh "${HOOK_DIR}/resolve-plan-dir.sh" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
PLAN_AMBIGUOUS=1
|
||||
fi
|
||||
if [ -n "$PLAN_DIR" ]; then
|
||||
PLAN_FILE="${PLAN_DIR}/task_plan.md"
|
||||
PROGRESS_FILE="${PLAN_DIR}/progress.md"
|
||||
@@ -92,7 +96,7 @@ else
|
||||
PLAN_FILE="${PLAN_PREFIX}task_plan.md"
|
||||
PROGRESS_FILE="${PLAN_PREFIX}progress.md"
|
||||
fi
|
||||
[ -f "$PLAN_FILE" ] || exit 0
|
||||
[ -f "$PLAN_FILE" ] || [ "$PLAN_AMBIGUOUS" = "1" ] || exit 0
|
||||
|
||||
# --- Re-arm the once-per-turn PostToolUse nudge (issue #239). ---
|
||||
# One user message is one turn, and this hook fires once per turn, so clearing
|
||||
@@ -113,7 +117,7 @@ elif [ -n "${HOME:-}" ]; then
|
||||
else
|
||||
TURN_ROOT="${TMPDIR:-/tmp}/pwf-turn"
|
||||
fi
|
||||
if [ -d "$TURN_ROOT" ]; then
|
||||
if [ "$PLAN_AMBIGUOUS" = "0" ] && [ -d "$TURN_ROOT" ]; then
|
||||
case "$TURN_PLAN_FILE" in
|
||||
/*|[A-Za-z]:*|\\\\*) TURN_KEY_SRC="$TURN_PLAN_FILE" ;;
|
||||
*) TURN_KEY_SRC="${PWD}/${TURN_PLAN_FILE}" ;;
|
||||
@@ -160,6 +164,11 @@ case "$PWF_SESSION_ADMISSION" in
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Plan-id safe-identifier check. Pure-sh case patterns; shared shape with
|
||||
# resolve-plan-dir.sh, needed below to decide whether PLAN_ID named the plan.
|
||||
slug_is_valid() {
|
||||
|
||||
@@ -36,7 +36,7 @@ hooks:
|
||||
- type: command
|
||||
command: "SH=\"\"; for c in \"${PWF_SCRIPT_DIR}/skill-hook.sh\" \"${CLAUDE_SKILL_DIR}/scripts/skill-hook.sh\" \"$HOME/.codex/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/plugins/marketplaces/planning-with-files/scripts/skill-hook.sh\"; do [ -f \"$c\" ] && { SH=\"$c\"; break; }; done; [ -n \"$SH\" ] && sh \"$SH\" --event=precompact; exit 0"
|
||||
metadata:
|
||||
version: "3.17.0"
|
||||
version: "3.17.2"
|
||||
|
||||
---
|
||||
|
||||
@@ -46,7 +46,7 @@ Work like Manus: Use persistent markdown files as your "working memory on disk."
|
||||
|
||||
## FIRST: Restore Project State
|
||||
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or session isolation is armed with multiple plans and no `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or multiple named plans exist without `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
|
||||
```bash
|
||||
# Linux/macOS (auto-detects python3 or python)
|
||||
|
||||
@@ -404,6 +404,7 @@ function Resolve-PlanFile {
|
||||
$resolver = Join-Path $PSScriptRoot "resolve-plan-dir.ps1"
|
||||
if (-not (Test-Path -LiteralPath $resolver -PathType Leaf)) { return $null }
|
||||
$resolvedDir = @(& $resolver | Where-Object { $_ }) | Select-Object -First 1
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { return $null }
|
||||
if ($resolvedDir) {
|
||||
$planFile = Join-Path $resolvedDir "task_plan.md"
|
||||
return (Resolve-ContainedPlanFile -Candidate $planFile -ExpectedDirectory $resolvedDir)
|
||||
|
||||
@@ -45,6 +45,10 @@ resolve_plan_file() {
|
||||
plan_dir=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
plan_dir="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$plan_dir" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
printf "[plan-attest] Multiple plans are available. Set PLAN_ID=<slug>; nothing was attested.\n" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [ -n "${plan_dir}" ] && [ -f "${plan_dir}/task_plan.md" ]; then
|
||||
printf "%s\n" "${plan_dir}/task_plan.md"
|
||||
|
||||
@@ -35,6 +35,7 @@ if ($PlanFile -ne "") {
|
||||
try {
|
||||
$resolvedDir = (& $resolver 2>$null | Select-Object -First 1)
|
||||
if ($null -eq $resolvedDir) { $resolvedDir = "" }
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { exit 0 }
|
||||
} catch {
|
||||
$resolvedDir = ""
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ else
|
||||
RESOLVED_DIR=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
RESOLVED_DIR="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$RESOLVED_DIR" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ -n "${RESOLVED_DIR}" ] && [ -f "${RESOLVED_DIR}/task_plan.md" ]; then
|
||||
PLAN_FILE="${RESOLVED_DIR}/task_plan.md"
|
||||
|
||||
@@ -59,12 +59,9 @@ Windows runs the shell chain through Git Bash and nothing else:
|
||||
one turn-marker slot and one progress-guard slot per plan.
|
||||
|
||||
Known, accepted differences from the shell reference:
|
||||
* Two plan directories with the same whole-second mtime, no .active_plan
|
||||
and no PLAN_ID: the reference picks the first in the shell's glob order
|
||||
(locale collation), this twin the first in code-point order. The same
|
||||
collation difference can change which three of four or more nested
|
||||
projects the ambiguity notice names. A machine runs one implementation,
|
||||
so neither choice flips within a session.
|
||||
* Shell glob order follows locale collation; this twin uses code-point
|
||||
order. This can change which three of four or more nested projects the
|
||||
ambiguity notice names.
|
||||
* BSD sed (macOS) appends a newline to a progress.md whose last line has
|
||||
none; GNU sed and this twin do not.
|
||||
* With PWF_PLAN_ROOT set under Git Bash the shell sees the pin as typed
|
||||
@@ -837,6 +834,16 @@ class Injector(object):
|
||||
scope = ""
|
||||
explicit = bool(plan_prefix)
|
||||
plan_id = env.get("PLAN_ID", "")
|
||||
ambiguous = plan_is_ambiguous(
|
||||
plan_prefix + ".planning", plan_root_pin if plan_root_pin else ".", plan_id
|
||||
)
|
||||
if ambiguous and (context == "preflight" or not is_dir(plan_prefix + ".planning/sessions")):
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> "
|
||||
"for this session; nothing injected."
|
||||
)
|
||||
raise Bail()
|
||||
if plan_id:
|
||||
if slug_is_valid(plan_id) and is_dir(plan_prefix + ".planning/" + plan_id):
|
||||
resolved = plan_prefix + ".planning/" + plan_id
|
||||
@@ -923,30 +930,14 @@ class Injector(object):
|
||||
"single-session mode."
|
||||
)
|
||||
raise Bail()
|
||||
if not plan_id:
|
||||
plan_n = 1 if is_file(plan_prefix + "task_plan.md") else 0
|
||||
try:
|
||||
names = sorted(os.listdir(plan_prefix + ".planning"))
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if name.startswith("."):
|
||||
continue
|
||||
if not is_file(plan_prefix + ".planning/" + name + "/task_plan.md"):
|
||||
continue
|
||||
if not slug_is_valid(name):
|
||||
continue
|
||||
plan_n += 1
|
||||
if plan_n > 1:
|
||||
break
|
||||
if plan_n > 1:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
if ambiguous:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
|
||||
if not explicit:
|
||||
nested = []
|
||||
@@ -1326,6 +1317,23 @@ def inject(context, env=None):
|
||||
# Twin of resolve-plan-dir.sh (the shared resolver the dispatcher uses).
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def plan_is_ambiguous(plan_root, project_root, plan_id=""):
|
||||
"""A project pointer or mtime cannot bind a session to multiple plans."""
|
||||
if plan_id:
|
||||
return False
|
||||
count = 1 if is_dir(plan_root + "/sessions") and is_file(project_root + "/task_plan.md") else 0
|
||||
try:
|
||||
names = os.listdir(plan_root)
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if slug_is_valid(name) and is_file(plan_root + "/" + name + "/task_plan.md"):
|
||||
count += 1
|
||||
if count > 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def resolve_plan_dir(env=None):
|
||||
"""Return (spelled, filesystem) paths of the plan directory, or ("", "").
|
||||
|
||||
@@ -1360,6 +1368,9 @@ def resolve_plan_dir(env=None):
|
||||
return found(plan_id)
|
||||
return ("", "")
|
||||
|
||||
if plan_is_ambiguous(fs_root, pin if pin else "."):
|
||||
return ("", "")
|
||||
|
||||
active_file = fs_root + "/.active_plan"
|
||||
if is_file(active_file):
|
||||
try:
|
||||
@@ -1441,6 +1452,8 @@ class ClaudeDispatcher(object):
|
||||
return (spelled, fs)
|
||||
if self.env.get("PLAN_ID", "") or self.env.get("PWF_PLAN_ROOT", ""):
|
||||
return ("", "")
|
||||
if plan_is_ambiguous(".planning", "."):
|
||||
return ("", "")
|
||||
if is_file("task_plan.md"):
|
||||
return (".", ".")
|
||||
return ("", "")
|
||||
|
||||
@@ -254,6 +254,29 @@ is_within_root() {
|
||||
# The .active_plan pointer, the newest-by-mtime fallback, and the legacy root
|
||||
# task_plan.md are cwd GUESSES — only guesses are subject to the nested-root
|
||||
# conflict check below.
|
||||
# Shared .active_plan and directory mtime cannot identify this session's plan.
|
||||
# Check before selection or preflight, even when isolation was never armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_PREFIX}.planning/sessions" ] && [ -f "${PLAN_PREFIX}task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ] && { [ "$CONTEXT" = "preflight" ] || [ ! -d "${PLAN_PREFIX}.planning/sessions" ]; }; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
RESOLVED=""
|
||||
SCOPE=""
|
||||
EXPLICIT=0
|
||||
@@ -442,27 +465,13 @@ PY
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# An attachment admits a session but does not select one of several plans.
|
||||
# When isolation is armed, require PLAN_ID if more than one live same-root
|
||||
# candidate exists. PWF_PLAN_ROOT selects the project root, not a plan
|
||||
# within that root.
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
SESSION_PLAN_N=0
|
||||
[ -f "${PLAN_PREFIX}task_plan.md" ] && SESSION_PLAN_N=1
|
||||
for candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$candidate" ] || continue
|
||||
candidate_dir="${candidate%/task_plan.md}"
|
||||
candidate_slug="${candidate_dir##*/}"
|
||||
slug_is_valid "$candidate_slug" || continue
|
||||
SESSION_PLAN_N=$((SESSION_PLAN_N + 1))
|
||||
[ "$SESSION_PLAN_N" -gt 1 ] && break
|
||||
done
|
||||
if [ "$SESSION_PLAN_N" -gt 1 ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
# Attachment admits a session but does not select its plan. Preserve the
|
||||
# attachment-first notice above for sessions that never opted in.
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
# junction/symlink escape; slug validation alone blocks textual traversal.
|
||||
|
||||
param(
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning")
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning"),
|
||||
[switch]$CheckAmbiguity
|
||||
)
|
||||
|
||||
$projectRoot = (Get-Location).Path
|
||||
@@ -137,6 +138,30 @@ $activeFile = Join-Path $PlanRoot ".active_plan"
|
||||
# at rc=0. Emptiness is the fail-closed signal on this channel, matching
|
||||
# resolve-plan-dir.sh and the PWF_PLAN_ROOT pin. An empty $env:PLAN_ID is
|
||||
# falsy here and still means "unset".
|
||||
# The optional probe distinguishes ambiguity from a legacy-root fallback.
|
||||
# Multiple named plans require PLAN_ID even without a sessions directory.
|
||||
$planCount = 0
|
||||
if (-not $env:PLAN_ID) {
|
||||
if ((Test-Path -LiteralPath (Join-Path $PlanRoot "sessions") -PathType Container) -and
|
||||
(Test-Path -LiteralPath (Join-Path $projectRoot "task_plan.md") -PathType Leaf)) {
|
||||
$planCount = 1
|
||||
}
|
||||
if (Test-Path -LiteralPath $PlanRoot -PathType Container) {
|
||||
foreach ($entry in (Get-ChildItem -LiteralPath $PlanRoot -Directory -ErrorAction SilentlyContinue)) {
|
||||
if ((Test-ValidSlug $entry.Name) -and
|
||||
(Test-Path -LiteralPath (Join-Path $entry.FullName "task_plan.md") -PathType Leaf)) {
|
||||
$planCount++
|
||||
if ($planCount -gt 1) { break }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($CheckAmbiguity) {
|
||||
if ($planCount -gt 1) { Write-Output "PWF_PLAN_AMBIGUOUS_V1" }
|
||||
exit 0
|
||||
}
|
||||
if ($planCount -gt 1) { exit 0 }
|
||||
|
||||
if ($env:PLAN_ID) {
|
||||
if (Test-ValidSlug $env:PLAN_ID) {
|
||||
$candidate = Join-Path $PlanRoot $env:PLAN_ID
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
@@ -404,6 +404,7 @@ function Resolve-PlanFile {
|
||||
$resolver = Join-Path $PSScriptRoot "resolve-plan-dir.ps1"
|
||||
if (-not (Test-Path -LiteralPath $resolver -PathType Leaf)) { return $null }
|
||||
$resolvedDir = @(& $resolver | Where-Object { $_ }) | Select-Object -First 1
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { return $null }
|
||||
if ($resolvedDir) {
|
||||
$planFile = Join-Path $resolvedDir "task_plan.md"
|
||||
return (Resolve-ContainedPlanFile -Candidate $planFile -ExpectedDirectory $resolvedDir)
|
||||
|
||||
@@ -45,6 +45,10 @@ resolve_plan_file() {
|
||||
plan_dir=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
plan_dir="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$plan_dir" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
printf "[plan-attest] Multiple plans are available. Set PLAN_ID=<slug>; nothing was attested.\n" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [ -n "${plan_dir}" ] && [ -f "${plan_dir}/task_plan.md" ]; then
|
||||
printf "%s\n" "${plan_dir}/task_plan.md"
|
||||
|
||||
@@ -35,6 +35,7 @@ if ($PlanFile -ne "") {
|
||||
try {
|
||||
$resolvedDir = (& $resolver 2>$null | Select-Object -First 1)
|
||||
if ($null -eq $resolvedDir) { $resolvedDir = "" }
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { exit 0 }
|
||||
} catch {
|
||||
$resolvedDir = ""
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ else
|
||||
RESOLVED_DIR=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
RESOLVED_DIR="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$RESOLVED_DIR" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ -n "${RESOLVED_DIR}" ] && [ -f "${RESOLVED_DIR}/task_plan.md" ]; then
|
||||
PLAN_FILE="${RESOLVED_DIR}/task_plan.md"
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
# junction/symlink escape; slug validation alone blocks textual traversal.
|
||||
|
||||
param(
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning")
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning"),
|
||||
[switch]$CheckAmbiguity
|
||||
)
|
||||
|
||||
$projectRoot = (Get-Location).Path
|
||||
@@ -137,6 +138,30 @@ $activeFile = Join-Path $PlanRoot ".active_plan"
|
||||
# at rc=0. Emptiness is the fail-closed signal on this channel, matching
|
||||
# resolve-plan-dir.sh and the PWF_PLAN_ROOT pin. An empty $env:PLAN_ID is
|
||||
# falsy here and still means "unset".
|
||||
# The optional probe distinguishes ambiguity from a legacy-root fallback.
|
||||
# Multiple named plans require PLAN_ID even without a sessions directory.
|
||||
$planCount = 0
|
||||
if (-not $env:PLAN_ID) {
|
||||
if ((Test-Path -LiteralPath (Join-Path $PlanRoot "sessions") -PathType Container) -and
|
||||
(Test-Path -LiteralPath (Join-Path $projectRoot "task_plan.md") -PathType Leaf)) {
|
||||
$planCount = 1
|
||||
}
|
||||
if (Test-Path -LiteralPath $PlanRoot -PathType Container) {
|
||||
foreach ($entry in (Get-ChildItem -LiteralPath $PlanRoot -Directory -ErrorAction SilentlyContinue)) {
|
||||
if ((Test-ValidSlug $entry.Name) -and
|
||||
(Test-Path -LiteralPath (Join-Path $entry.FullName "task_plan.md") -PathType Leaf)) {
|
||||
$planCount++
|
||||
if ($planCount -gt 1) { break }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($CheckAmbiguity) {
|
||||
if ($planCount -gt 1) { Write-Output "PWF_PLAN_AMBIGUOUS_V1" }
|
||||
exit 0
|
||||
}
|
||||
if ($planCount -gt 1) { exit 0 }
|
||||
|
||||
if ($env:PLAN_ID) {
|
||||
if (Test-ValidSlug $env:PLAN_ID) {
|
||||
$candidate = Join-Path $PlanRoot $env:PLAN_ID
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
@@ -36,7 +36,7 @@ hooks:
|
||||
- type: command
|
||||
command: "SH=\"\"; for c in \"${PWF_SCRIPT_DIR}/skill-hook.sh\" \"${CLAUDE_SKILL_DIR}/scripts/skill-hook.sh\" \"$HOME/.cursor/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/plugins/marketplaces/planning-with-files/scripts/skill-hook.sh\"; do [ -f \"$c\" ] && { SH=\"$c\"; break; }; done; [ -n \"$SH\" ] && sh \"$SH\" --event=precompact; exit 0"
|
||||
metadata:
|
||||
version: "3.17.0"
|
||||
version: "3.17.2"
|
||||
|
||||
---
|
||||
|
||||
@@ -46,7 +46,7 @@ Work like Manus: Use persistent markdown files as your "working memory on disk."
|
||||
|
||||
## FIRST: Restore Project State
|
||||
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or session isolation is armed with multiple plans and no `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or multiple named plans exist without `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
|
||||
```bash
|
||||
# Linux/macOS (auto-detects python3 or python)
|
||||
|
||||
@@ -404,6 +404,7 @@ function Resolve-PlanFile {
|
||||
$resolver = Join-Path $PSScriptRoot "resolve-plan-dir.ps1"
|
||||
if (-not (Test-Path -LiteralPath $resolver -PathType Leaf)) { return $null }
|
||||
$resolvedDir = @(& $resolver | Where-Object { $_ }) | Select-Object -First 1
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { return $null }
|
||||
if ($resolvedDir) {
|
||||
$planFile = Join-Path $resolvedDir "task_plan.md"
|
||||
return (Resolve-ContainedPlanFile -Candidate $planFile -ExpectedDirectory $resolvedDir)
|
||||
|
||||
@@ -45,6 +45,10 @@ resolve_plan_file() {
|
||||
plan_dir=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
plan_dir="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$plan_dir" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
printf "[plan-attest] Multiple plans are available. Set PLAN_ID=<slug>; nothing was attested.\n" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [ -n "${plan_dir}" ] && [ -f "${plan_dir}/task_plan.md" ]; then
|
||||
printf "%s\n" "${plan_dir}/task_plan.md"
|
||||
|
||||
@@ -35,6 +35,7 @@ if ($PlanFile -ne "") {
|
||||
try {
|
||||
$resolvedDir = (& $resolver 2>$null | Select-Object -First 1)
|
||||
if ($null -eq $resolvedDir) { $resolvedDir = "" }
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { exit 0 }
|
||||
} catch {
|
||||
$resolvedDir = ""
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ else
|
||||
RESOLVED_DIR=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
RESOLVED_DIR="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$RESOLVED_DIR" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ -n "${RESOLVED_DIR}" ] && [ -f "${RESOLVED_DIR}/task_plan.md" ]; then
|
||||
PLAN_FILE="${RESOLVED_DIR}/task_plan.md"
|
||||
|
||||
@@ -59,12 +59,9 @@ Windows runs the shell chain through Git Bash and nothing else:
|
||||
one turn-marker slot and one progress-guard slot per plan.
|
||||
|
||||
Known, accepted differences from the shell reference:
|
||||
* Two plan directories with the same whole-second mtime, no .active_plan
|
||||
and no PLAN_ID: the reference picks the first in the shell's glob order
|
||||
(locale collation), this twin the first in code-point order. The same
|
||||
collation difference can change which three of four or more nested
|
||||
projects the ambiguity notice names. A machine runs one implementation,
|
||||
so neither choice flips within a session.
|
||||
* Shell glob order follows locale collation; this twin uses code-point
|
||||
order. This can change which three of four or more nested projects the
|
||||
ambiguity notice names.
|
||||
* BSD sed (macOS) appends a newline to a progress.md whose last line has
|
||||
none; GNU sed and this twin do not.
|
||||
* With PWF_PLAN_ROOT set under Git Bash the shell sees the pin as typed
|
||||
@@ -837,6 +834,16 @@ class Injector(object):
|
||||
scope = ""
|
||||
explicit = bool(plan_prefix)
|
||||
plan_id = env.get("PLAN_ID", "")
|
||||
ambiguous = plan_is_ambiguous(
|
||||
plan_prefix + ".planning", plan_root_pin if plan_root_pin else ".", plan_id
|
||||
)
|
||||
if ambiguous and (context == "preflight" or not is_dir(plan_prefix + ".planning/sessions")):
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> "
|
||||
"for this session; nothing injected."
|
||||
)
|
||||
raise Bail()
|
||||
if plan_id:
|
||||
if slug_is_valid(plan_id) and is_dir(plan_prefix + ".planning/" + plan_id):
|
||||
resolved = plan_prefix + ".planning/" + plan_id
|
||||
@@ -923,30 +930,14 @@ class Injector(object):
|
||||
"single-session mode."
|
||||
)
|
||||
raise Bail()
|
||||
if not plan_id:
|
||||
plan_n = 1 if is_file(plan_prefix + "task_plan.md") else 0
|
||||
try:
|
||||
names = sorted(os.listdir(plan_prefix + ".planning"))
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if name.startswith("."):
|
||||
continue
|
||||
if not is_file(plan_prefix + ".planning/" + name + "/task_plan.md"):
|
||||
continue
|
||||
if not slug_is_valid(name):
|
||||
continue
|
||||
plan_n += 1
|
||||
if plan_n > 1:
|
||||
break
|
||||
if plan_n > 1:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
if ambiguous:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
|
||||
if not explicit:
|
||||
nested = []
|
||||
@@ -1326,6 +1317,23 @@ def inject(context, env=None):
|
||||
# Twin of resolve-plan-dir.sh (the shared resolver the dispatcher uses).
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def plan_is_ambiguous(plan_root, project_root, plan_id=""):
|
||||
"""A project pointer or mtime cannot bind a session to multiple plans."""
|
||||
if plan_id:
|
||||
return False
|
||||
count = 1 if is_dir(plan_root + "/sessions") and is_file(project_root + "/task_plan.md") else 0
|
||||
try:
|
||||
names = os.listdir(plan_root)
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if slug_is_valid(name) and is_file(plan_root + "/" + name + "/task_plan.md"):
|
||||
count += 1
|
||||
if count > 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def resolve_plan_dir(env=None):
|
||||
"""Return (spelled, filesystem) paths of the plan directory, or ("", "").
|
||||
|
||||
@@ -1360,6 +1368,9 @@ def resolve_plan_dir(env=None):
|
||||
return found(plan_id)
|
||||
return ("", "")
|
||||
|
||||
if plan_is_ambiguous(fs_root, pin if pin else "."):
|
||||
return ("", "")
|
||||
|
||||
active_file = fs_root + "/.active_plan"
|
||||
if is_file(active_file):
|
||||
try:
|
||||
@@ -1441,6 +1452,8 @@ class ClaudeDispatcher(object):
|
||||
return (spelled, fs)
|
||||
if self.env.get("PLAN_ID", "") or self.env.get("PWF_PLAN_ROOT", ""):
|
||||
return ("", "")
|
||||
if plan_is_ambiguous(".planning", "."):
|
||||
return ("", "")
|
||||
if is_file("task_plan.md"):
|
||||
return (".", ".")
|
||||
return ("", "")
|
||||
|
||||
@@ -254,6 +254,29 @@ is_within_root() {
|
||||
# The .active_plan pointer, the newest-by-mtime fallback, and the legacy root
|
||||
# task_plan.md are cwd GUESSES — only guesses are subject to the nested-root
|
||||
# conflict check below.
|
||||
# Shared .active_plan and directory mtime cannot identify this session's plan.
|
||||
# Check before selection or preflight, even when isolation was never armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_PREFIX}.planning/sessions" ] && [ -f "${PLAN_PREFIX}task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ] && { [ "$CONTEXT" = "preflight" ] || [ ! -d "${PLAN_PREFIX}.planning/sessions" ]; }; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
RESOLVED=""
|
||||
SCOPE=""
|
||||
EXPLICIT=0
|
||||
@@ -442,27 +465,13 @@ PY
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# An attachment admits a session but does not select one of several plans.
|
||||
# When isolation is armed, require PLAN_ID if more than one live same-root
|
||||
# candidate exists. PWF_PLAN_ROOT selects the project root, not a plan
|
||||
# within that root.
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
SESSION_PLAN_N=0
|
||||
[ -f "${PLAN_PREFIX}task_plan.md" ] && SESSION_PLAN_N=1
|
||||
for candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$candidate" ] || continue
|
||||
candidate_dir="${candidate%/task_plan.md}"
|
||||
candidate_slug="${candidate_dir##*/}"
|
||||
slug_is_valid "$candidate_slug" || continue
|
||||
SESSION_PLAN_N=$((SESSION_PLAN_N + 1))
|
||||
[ "$SESSION_PLAN_N" -gt 1 ] && break
|
||||
done
|
||||
if [ "$SESSION_PLAN_N" -gt 1 ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
# Attachment admits a session but does not select its plan. Preserve the
|
||||
# attachment-first notice above for sessions that never opted in.
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
# junction/symlink escape; slug validation alone blocks textual traversal.
|
||||
|
||||
param(
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning")
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning"),
|
||||
[switch]$CheckAmbiguity
|
||||
)
|
||||
|
||||
$projectRoot = (Get-Location).Path
|
||||
@@ -137,6 +138,30 @@ $activeFile = Join-Path $PlanRoot ".active_plan"
|
||||
# at rc=0. Emptiness is the fail-closed signal on this channel, matching
|
||||
# resolve-plan-dir.sh and the PWF_PLAN_ROOT pin. An empty $env:PLAN_ID is
|
||||
# falsy here and still means "unset".
|
||||
# The optional probe distinguishes ambiguity from a legacy-root fallback.
|
||||
# Multiple named plans require PLAN_ID even without a sessions directory.
|
||||
$planCount = 0
|
||||
if (-not $env:PLAN_ID) {
|
||||
if ((Test-Path -LiteralPath (Join-Path $PlanRoot "sessions") -PathType Container) -and
|
||||
(Test-Path -LiteralPath (Join-Path $projectRoot "task_plan.md") -PathType Leaf)) {
|
||||
$planCount = 1
|
||||
}
|
||||
if (Test-Path -LiteralPath $PlanRoot -PathType Container) {
|
||||
foreach ($entry in (Get-ChildItem -LiteralPath $PlanRoot -Directory -ErrorAction SilentlyContinue)) {
|
||||
if ((Test-ValidSlug $entry.Name) -and
|
||||
(Test-Path -LiteralPath (Join-Path $entry.FullName "task_plan.md") -PathType Leaf)) {
|
||||
$planCount++
|
||||
if ($planCount -gt 1) { break }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($CheckAmbiguity) {
|
||||
if ($planCount -gt 1) { Write-Output "PWF_PLAN_AMBIGUOUS_V1" }
|
||||
exit 0
|
||||
}
|
||||
if ($planCount -gt 1) { exit 0 }
|
||||
|
||||
if ($env:PLAN_ID) {
|
||||
if (Test-ValidSlug $env:PLAN_ID) {
|
||||
$candidate = Join-Path $PlanRoot $env:PLAN_ID
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
@@ -36,7 +36,7 @@ hooks:
|
||||
- type: command
|
||||
command: "SH=\"\"; for c in \"${PWF_SCRIPT_DIR}/skill-hook.sh\" \"${CLAUDE_SKILL_DIR}/scripts/skill-hook.sh\" \"$HOME/.factory/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/plugins/marketplaces/planning-with-files/scripts/skill-hook.sh\"; do [ -f \"$c\" ] && { SH=\"$c\"; break; }; done; [ -n \"$SH\" ] && sh \"$SH\" --event=precompact; exit 0"
|
||||
metadata:
|
||||
version: "3.17.0"
|
||||
version: "3.17.2"
|
||||
---
|
||||
|
||||
# Planning with Files
|
||||
@@ -45,7 +45,7 @@ Work like Manus: Use persistent markdown files as your "working memory on disk."
|
||||
|
||||
## FIRST: Restore Project State
|
||||
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or session isolation is armed with multiple plans and no `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or multiple named plans exist without `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
|
||||
```bash
|
||||
$(command -v python3 || command -v python) .factory/skills/planning-with-files/scripts/session-catchup.py --metadata "$(pwd)"
|
||||
|
||||
@@ -404,6 +404,7 @@ function Resolve-PlanFile {
|
||||
$resolver = Join-Path $PSScriptRoot "resolve-plan-dir.ps1"
|
||||
if (-not (Test-Path -LiteralPath $resolver -PathType Leaf)) { return $null }
|
||||
$resolvedDir = @(& $resolver | Where-Object { $_ }) | Select-Object -First 1
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { return $null }
|
||||
if ($resolvedDir) {
|
||||
$planFile = Join-Path $resolvedDir "task_plan.md"
|
||||
return (Resolve-ContainedPlanFile -Candidate $planFile -ExpectedDirectory $resolvedDir)
|
||||
|
||||
@@ -45,6 +45,10 @@ resolve_plan_file() {
|
||||
plan_dir=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
plan_dir="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$plan_dir" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
printf "[plan-attest] Multiple plans are available. Set PLAN_ID=<slug>; nothing was attested.\n" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [ -n "${plan_dir}" ] && [ -f "${plan_dir}/task_plan.md" ]; then
|
||||
printf "%s\n" "${plan_dir}/task_plan.md"
|
||||
|
||||
@@ -35,6 +35,7 @@ if ($PlanFile -ne "") {
|
||||
try {
|
||||
$resolvedDir = (& $resolver 2>$null | Select-Object -First 1)
|
||||
if ($null -eq $resolvedDir) { $resolvedDir = "" }
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { exit 0 }
|
||||
} catch {
|
||||
$resolvedDir = ""
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ else
|
||||
RESOLVED_DIR=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
RESOLVED_DIR="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$RESOLVED_DIR" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ -n "${RESOLVED_DIR}" ] && [ -f "${RESOLVED_DIR}/task_plan.md" ]; then
|
||||
PLAN_FILE="${RESOLVED_DIR}/task_plan.md"
|
||||
|
||||
@@ -59,12 +59,9 @@ Windows runs the shell chain through Git Bash and nothing else:
|
||||
one turn-marker slot and one progress-guard slot per plan.
|
||||
|
||||
Known, accepted differences from the shell reference:
|
||||
* Two plan directories with the same whole-second mtime, no .active_plan
|
||||
and no PLAN_ID: the reference picks the first in the shell's glob order
|
||||
(locale collation), this twin the first in code-point order. The same
|
||||
collation difference can change which three of four or more nested
|
||||
projects the ambiguity notice names. A machine runs one implementation,
|
||||
so neither choice flips within a session.
|
||||
* Shell glob order follows locale collation; this twin uses code-point
|
||||
order. This can change which three of four or more nested projects the
|
||||
ambiguity notice names.
|
||||
* BSD sed (macOS) appends a newline to a progress.md whose last line has
|
||||
none; GNU sed and this twin do not.
|
||||
* With PWF_PLAN_ROOT set under Git Bash the shell sees the pin as typed
|
||||
@@ -837,6 +834,16 @@ class Injector(object):
|
||||
scope = ""
|
||||
explicit = bool(plan_prefix)
|
||||
plan_id = env.get("PLAN_ID", "")
|
||||
ambiguous = plan_is_ambiguous(
|
||||
plan_prefix + ".planning", plan_root_pin if plan_root_pin else ".", plan_id
|
||||
)
|
||||
if ambiguous and (context == "preflight" or not is_dir(plan_prefix + ".planning/sessions")):
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> "
|
||||
"for this session; nothing injected."
|
||||
)
|
||||
raise Bail()
|
||||
if plan_id:
|
||||
if slug_is_valid(plan_id) and is_dir(plan_prefix + ".planning/" + plan_id):
|
||||
resolved = plan_prefix + ".planning/" + plan_id
|
||||
@@ -923,30 +930,14 @@ class Injector(object):
|
||||
"single-session mode."
|
||||
)
|
||||
raise Bail()
|
||||
if not plan_id:
|
||||
plan_n = 1 if is_file(plan_prefix + "task_plan.md") else 0
|
||||
try:
|
||||
names = sorted(os.listdir(plan_prefix + ".planning"))
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if name.startswith("."):
|
||||
continue
|
||||
if not is_file(plan_prefix + ".planning/" + name + "/task_plan.md"):
|
||||
continue
|
||||
if not slug_is_valid(name):
|
||||
continue
|
||||
plan_n += 1
|
||||
if plan_n > 1:
|
||||
break
|
||||
if plan_n > 1:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
if ambiguous:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
|
||||
if not explicit:
|
||||
nested = []
|
||||
@@ -1326,6 +1317,23 @@ def inject(context, env=None):
|
||||
# Twin of resolve-plan-dir.sh (the shared resolver the dispatcher uses).
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def plan_is_ambiguous(plan_root, project_root, plan_id=""):
|
||||
"""A project pointer or mtime cannot bind a session to multiple plans."""
|
||||
if plan_id:
|
||||
return False
|
||||
count = 1 if is_dir(plan_root + "/sessions") and is_file(project_root + "/task_plan.md") else 0
|
||||
try:
|
||||
names = os.listdir(plan_root)
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if slug_is_valid(name) and is_file(plan_root + "/" + name + "/task_plan.md"):
|
||||
count += 1
|
||||
if count > 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def resolve_plan_dir(env=None):
|
||||
"""Return (spelled, filesystem) paths of the plan directory, or ("", "").
|
||||
|
||||
@@ -1360,6 +1368,9 @@ def resolve_plan_dir(env=None):
|
||||
return found(plan_id)
|
||||
return ("", "")
|
||||
|
||||
if plan_is_ambiguous(fs_root, pin if pin else "."):
|
||||
return ("", "")
|
||||
|
||||
active_file = fs_root + "/.active_plan"
|
||||
if is_file(active_file):
|
||||
try:
|
||||
@@ -1441,6 +1452,8 @@ class ClaudeDispatcher(object):
|
||||
return (spelled, fs)
|
||||
if self.env.get("PLAN_ID", "") or self.env.get("PWF_PLAN_ROOT", ""):
|
||||
return ("", "")
|
||||
if plan_is_ambiguous(".planning", "."):
|
||||
return ("", "")
|
||||
if is_file("task_plan.md"):
|
||||
return (".", ".")
|
||||
return ("", "")
|
||||
|
||||
@@ -254,6 +254,29 @@ is_within_root() {
|
||||
# The .active_plan pointer, the newest-by-mtime fallback, and the legacy root
|
||||
# task_plan.md are cwd GUESSES — only guesses are subject to the nested-root
|
||||
# conflict check below.
|
||||
# Shared .active_plan and directory mtime cannot identify this session's plan.
|
||||
# Check before selection or preflight, even when isolation was never armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_PREFIX}.planning/sessions" ] && [ -f "${PLAN_PREFIX}task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ] && { [ "$CONTEXT" = "preflight" ] || [ ! -d "${PLAN_PREFIX}.planning/sessions" ]; }; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
RESOLVED=""
|
||||
SCOPE=""
|
||||
EXPLICIT=0
|
||||
@@ -442,27 +465,13 @@ PY
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# An attachment admits a session but does not select one of several plans.
|
||||
# When isolation is armed, require PLAN_ID if more than one live same-root
|
||||
# candidate exists. PWF_PLAN_ROOT selects the project root, not a plan
|
||||
# within that root.
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
SESSION_PLAN_N=0
|
||||
[ -f "${PLAN_PREFIX}task_plan.md" ] && SESSION_PLAN_N=1
|
||||
for candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$candidate" ] || continue
|
||||
candidate_dir="${candidate%/task_plan.md}"
|
||||
candidate_slug="${candidate_dir##*/}"
|
||||
slug_is_valid "$candidate_slug" || continue
|
||||
SESSION_PLAN_N=$((SESSION_PLAN_N + 1))
|
||||
[ "$SESSION_PLAN_N" -gt 1 ] && break
|
||||
done
|
||||
if [ "$SESSION_PLAN_N" -gt 1 ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
# Attachment admits a session but does not select its plan. Preserve the
|
||||
# attachment-first notice above for sessions that never opted in.
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
# junction/symlink escape; slug validation alone blocks textual traversal.
|
||||
|
||||
param(
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning")
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning"),
|
||||
[switch]$CheckAmbiguity
|
||||
)
|
||||
|
||||
$projectRoot = (Get-Location).Path
|
||||
@@ -137,6 +138,30 @@ $activeFile = Join-Path $PlanRoot ".active_plan"
|
||||
# at rc=0. Emptiness is the fail-closed signal on this channel, matching
|
||||
# resolve-plan-dir.sh and the PWF_PLAN_ROOT pin. An empty $env:PLAN_ID is
|
||||
# falsy here and still means "unset".
|
||||
# The optional probe distinguishes ambiguity from a legacy-root fallback.
|
||||
# Multiple named plans require PLAN_ID even without a sessions directory.
|
||||
$planCount = 0
|
||||
if (-not $env:PLAN_ID) {
|
||||
if ((Test-Path -LiteralPath (Join-Path $PlanRoot "sessions") -PathType Container) -and
|
||||
(Test-Path -LiteralPath (Join-Path $projectRoot "task_plan.md") -PathType Leaf)) {
|
||||
$planCount = 1
|
||||
}
|
||||
if (Test-Path -LiteralPath $PlanRoot -PathType Container) {
|
||||
foreach ($entry in (Get-ChildItem -LiteralPath $PlanRoot -Directory -ErrorAction SilentlyContinue)) {
|
||||
if ((Test-ValidSlug $entry.Name) -and
|
||||
(Test-Path -LiteralPath (Join-Path $entry.FullName "task_plan.md") -PathType Leaf)) {
|
||||
$planCount++
|
||||
if ($planCount -gt 1) { break }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($CheckAmbiguity) {
|
||||
if ($planCount -gt 1) { Write-Output "PWF_PLAN_AMBIGUOUS_V1" }
|
||||
exit 0
|
||||
}
|
||||
if ($planCount -gt 1) { exit 0 }
|
||||
|
||||
if ($env:PLAN_ID) {
|
||||
if (Test-ValidSlug $env:PLAN_ID) {
|
||||
$candidate = Join-Path $PlanRoot $env:PLAN_ID
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
@@ -404,6 +404,7 @@ function Resolve-PlanFile {
|
||||
$resolver = Join-Path $PSScriptRoot "resolve-plan-dir.ps1"
|
||||
if (-not (Test-Path -LiteralPath $resolver -PathType Leaf)) { return $null }
|
||||
$resolvedDir = @(& $resolver | Where-Object { $_ }) | Select-Object -First 1
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { return $null }
|
||||
if ($resolvedDir) {
|
||||
$planFile = Join-Path $resolvedDir "task_plan.md"
|
||||
return (Resolve-ContainedPlanFile -Candidate $planFile -ExpectedDirectory $resolvedDir)
|
||||
|
||||
@@ -45,6 +45,10 @@ resolve_plan_file() {
|
||||
plan_dir=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
plan_dir="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$plan_dir" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
printf "[plan-attest] Multiple plans are available. Set PLAN_ID=<slug>; nothing was attested.\n" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [ -n "${plan_dir}" ] && [ -f "${plan_dir}/task_plan.md" ]; then
|
||||
printf "%s\n" "${plan_dir}/task_plan.md"
|
||||
|
||||
@@ -35,6 +35,7 @@ if ($PlanFile -ne "") {
|
||||
try {
|
||||
$resolvedDir = (& $resolver 2>$null | Select-Object -First 1)
|
||||
if ($null -eq $resolvedDir) { $resolvedDir = "" }
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { exit 0 }
|
||||
} catch {
|
||||
$resolvedDir = ""
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ else
|
||||
RESOLVED_DIR=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
RESOLVED_DIR="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$RESOLVED_DIR" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ -n "${RESOLVED_DIR}" ] && [ -f "${RESOLVED_DIR}/task_plan.md" ]; then
|
||||
PLAN_FILE="${RESOLVED_DIR}/task_plan.md"
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
# junction/symlink escape; slug validation alone blocks textual traversal.
|
||||
|
||||
param(
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning")
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning"),
|
||||
[switch]$CheckAmbiguity
|
||||
)
|
||||
|
||||
$projectRoot = (Get-Location).Path
|
||||
@@ -137,6 +138,30 @@ $activeFile = Join-Path $PlanRoot ".active_plan"
|
||||
# at rc=0. Emptiness is the fail-closed signal on this channel, matching
|
||||
# resolve-plan-dir.sh and the PWF_PLAN_ROOT pin. An empty $env:PLAN_ID is
|
||||
# falsy here and still means "unset".
|
||||
# The optional probe distinguishes ambiguity from a legacy-root fallback.
|
||||
# Multiple named plans require PLAN_ID even without a sessions directory.
|
||||
$planCount = 0
|
||||
if (-not $env:PLAN_ID) {
|
||||
if ((Test-Path -LiteralPath (Join-Path $PlanRoot "sessions") -PathType Container) -and
|
||||
(Test-Path -LiteralPath (Join-Path $projectRoot "task_plan.md") -PathType Leaf)) {
|
||||
$planCount = 1
|
||||
}
|
||||
if (Test-Path -LiteralPath $PlanRoot -PathType Container) {
|
||||
foreach ($entry in (Get-ChildItem -LiteralPath $PlanRoot -Directory -ErrorAction SilentlyContinue)) {
|
||||
if ((Test-ValidSlug $entry.Name) -and
|
||||
(Test-Path -LiteralPath (Join-Path $entry.FullName "task_plan.md") -PathType Leaf)) {
|
||||
$planCount++
|
||||
if ($planCount -gt 1) { break }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($CheckAmbiguity) {
|
||||
if ($planCount -gt 1) { Write-Output "PWF_PLAN_AMBIGUOUS_V1" }
|
||||
exit 0
|
||||
}
|
||||
if ($planCount -gt 1) { exit 0 }
|
||||
|
||||
if ($env:PLAN_ID) {
|
||||
if (Test-ValidSlug $env:PLAN_ID) {
|
||||
$candidate = Join-Path $PlanRoot $env:PLAN_ID
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
name: planning-with-files
|
||||
description: "Persistent file-based planning for multi-step AI-agent work. Keeps task_plan.md, findings.md, and progress.md on disk; lifecycle hooks inject selected project planning context. Automatic recovery reads project planning files only. Explicit session-catchup.py --metadata reads same-project local agent session records and emits aggregate counts only; --replay may emit bounded nonce-framed excerpts. Optional gated mode can request continuation only when the host supports it and never runs commands declared in Markdown. The skill has no network upload path. Use for research or work needing 5+ tool calls."
|
||||
metadata:
|
||||
version: "3.17.0"
|
||||
version: "3.17.2"
|
||||
hermes:
|
||||
tags: [planning, long-running-tasks, context-engineering, workflow]
|
||||
---
|
||||
|
||||
@@ -36,7 +36,7 @@ hooks:
|
||||
- type: command
|
||||
command: "SH=\"\"; for c in \"${PWF_SCRIPT_DIR}/skill-hook.sh\" \"${CLAUDE_SKILL_DIR}/scripts/skill-hook.sh\" \"$HOME/.mastracode/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/plugins/marketplaces/planning-with-files/scripts/skill-hook.sh\"; do [ -f \"$c\" ] && { SH=\"$c\"; break; }; done; [ -n \"$SH\" ] && sh \"$SH\" --event=precompact; exit 0"
|
||||
metadata:
|
||||
version: "3.17.0"
|
||||
version: "3.17.2"
|
||||
|
||||
---
|
||||
|
||||
@@ -46,7 +46,7 @@ Work like Manus: Use persistent markdown files as your "working memory on disk."
|
||||
|
||||
## FIRST: Restore Project State
|
||||
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or session isolation is armed with multiple plans and no `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or multiple named plans exist without `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
|
||||
```bash
|
||||
# Linux/macOS
|
||||
|
||||
@@ -59,12 +59,9 @@ Windows runs the shell chain through Git Bash and nothing else:
|
||||
one turn-marker slot and one progress-guard slot per plan.
|
||||
|
||||
Known, accepted differences from the shell reference:
|
||||
* Two plan directories with the same whole-second mtime, no .active_plan
|
||||
and no PLAN_ID: the reference picks the first in the shell's glob order
|
||||
(locale collation), this twin the first in code-point order. The same
|
||||
collation difference can change which three of four or more nested
|
||||
projects the ambiguity notice names. A machine runs one implementation,
|
||||
so neither choice flips within a session.
|
||||
* Shell glob order follows locale collation; this twin uses code-point
|
||||
order. This can change which three of four or more nested projects the
|
||||
ambiguity notice names.
|
||||
* BSD sed (macOS) appends a newline to a progress.md whose last line has
|
||||
none; GNU sed and this twin do not.
|
||||
* With PWF_PLAN_ROOT set under Git Bash the shell sees the pin as typed
|
||||
@@ -837,6 +834,16 @@ class Injector(object):
|
||||
scope = ""
|
||||
explicit = bool(plan_prefix)
|
||||
plan_id = env.get("PLAN_ID", "")
|
||||
ambiguous = plan_is_ambiguous(
|
||||
plan_prefix + ".planning", plan_root_pin if plan_root_pin else ".", plan_id
|
||||
)
|
||||
if ambiguous and (context == "preflight" or not is_dir(plan_prefix + ".planning/sessions")):
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> "
|
||||
"for this session; nothing injected."
|
||||
)
|
||||
raise Bail()
|
||||
if plan_id:
|
||||
if slug_is_valid(plan_id) and is_dir(plan_prefix + ".planning/" + plan_id):
|
||||
resolved = plan_prefix + ".planning/" + plan_id
|
||||
@@ -923,30 +930,14 @@ class Injector(object):
|
||||
"single-session mode."
|
||||
)
|
||||
raise Bail()
|
||||
if not plan_id:
|
||||
plan_n = 1 if is_file(plan_prefix + "task_plan.md") else 0
|
||||
try:
|
||||
names = sorted(os.listdir(plan_prefix + ".planning"))
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if name.startswith("."):
|
||||
continue
|
||||
if not is_file(plan_prefix + ".planning/" + name + "/task_plan.md"):
|
||||
continue
|
||||
if not slug_is_valid(name):
|
||||
continue
|
||||
plan_n += 1
|
||||
if plan_n > 1:
|
||||
break
|
||||
if plan_n > 1:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
if ambiguous:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
|
||||
if not explicit:
|
||||
nested = []
|
||||
@@ -1326,6 +1317,23 @@ def inject(context, env=None):
|
||||
# Twin of resolve-plan-dir.sh (the shared resolver the dispatcher uses).
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def plan_is_ambiguous(plan_root, project_root, plan_id=""):
|
||||
"""A project pointer or mtime cannot bind a session to multiple plans."""
|
||||
if plan_id:
|
||||
return False
|
||||
count = 1 if is_dir(plan_root + "/sessions") and is_file(project_root + "/task_plan.md") else 0
|
||||
try:
|
||||
names = os.listdir(plan_root)
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if slug_is_valid(name) and is_file(plan_root + "/" + name + "/task_plan.md"):
|
||||
count += 1
|
||||
if count > 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def resolve_plan_dir(env=None):
|
||||
"""Return (spelled, filesystem) paths of the plan directory, or ("", "").
|
||||
|
||||
@@ -1360,6 +1368,9 @@ def resolve_plan_dir(env=None):
|
||||
return found(plan_id)
|
||||
return ("", "")
|
||||
|
||||
if plan_is_ambiguous(fs_root, pin if pin else "."):
|
||||
return ("", "")
|
||||
|
||||
active_file = fs_root + "/.active_plan"
|
||||
if is_file(active_file):
|
||||
try:
|
||||
@@ -1441,6 +1452,8 @@ class ClaudeDispatcher(object):
|
||||
return (spelled, fs)
|
||||
if self.env.get("PLAN_ID", "") or self.env.get("PWF_PLAN_ROOT", ""):
|
||||
return ("", "")
|
||||
if plan_is_ambiguous(".planning", "."):
|
||||
return ("", "")
|
||||
if is_file("task_plan.md"):
|
||||
return (".", ".")
|
||||
return ("", "")
|
||||
|
||||
@@ -254,6 +254,29 @@ is_within_root() {
|
||||
# The .active_plan pointer, the newest-by-mtime fallback, and the legacy root
|
||||
# task_plan.md are cwd GUESSES — only guesses are subject to the nested-root
|
||||
# conflict check below.
|
||||
# Shared .active_plan and directory mtime cannot identify this session's plan.
|
||||
# Check before selection or preflight, even when isolation was never armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_PREFIX}.planning/sessions" ] && [ -f "${PLAN_PREFIX}task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ] && { [ "$CONTEXT" = "preflight" ] || [ ! -d "${PLAN_PREFIX}.planning/sessions" ]; }; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
RESOLVED=""
|
||||
SCOPE=""
|
||||
EXPLICIT=0
|
||||
@@ -442,27 +465,13 @@ PY
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# An attachment admits a session but does not select one of several plans.
|
||||
# When isolation is armed, require PLAN_ID if more than one live same-root
|
||||
# candidate exists. PWF_PLAN_ROOT selects the project root, not a plan
|
||||
# within that root.
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
SESSION_PLAN_N=0
|
||||
[ -f "${PLAN_PREFIX}task_plan.md" ] && SESSION_PLAN_N=1
|
||||
for candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$candidate" ] || continue
|
||||
candidate_dir="${candidate%/task_plan.md}"
|
||||
candidate_slug="${candidate_dir##*/}"
|
||||
slug_is_valid "$candidate_slug" || continue
|
||||
SESSION_PLAN_N=$((SESSION_PLAN_N + 1))
|
||||
[ "$SESSION_PLAN_N" -gt 1 ] && break
|
||||
done
|
||||
if [ "$SESSION_PLAN_N" -gt 1 ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
# Attachment admits a session but does not select its plan. Preserve the
|
||||
# attachment-first notice above for sessions that never opted in.
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
@@ -36,7 +36,7 @@ hooks:
|
||||
- type: command
|
||||
command: "SH=\"\"; for c in \"${PWF_SCRIPT_DIR}/skill-hook.sh\" \"${CLAUDE_SKILL_DIR}/scripts/skill-hook.sh\" \"$HOME/.config/opencode/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.opencode/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/skills/planning-with-files/scripts/skill-hook.sh\" \"$HOME/.claude/plugins/marketplaces/planning-with-files/scripts/skill-hook.sh\"; do [ -f \"$c\" ] && { SH=\"$c\"; break; }; done; [ -n \"$SH\" ] && sh \"$SH\" --event=precompact; exit 0"
|
||||
metadata:
|
||||
version: "3.17.0"
|
||||
version: "3.17.2"
|
||||
|
||||
---
|
||||
|
||||
@@ -46,7 +46,7 @@ Work like Manus: Use persistent markdown files as your "working memory on disk."
|
||||
|
||||
## FIRST: Restore Project State
|
||||
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or session isolation is armed with multiple plans and no `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
**Before continuing**, resolve the plan this task owns. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the host's `PLAN_ID` and `PWF_PLAN_ROOT`, then read `task_plan.md`, `progress.md`, and `findings.md` from that selected directory. If an explicit selector is rejected, or multiple named plans exist without `PLAN_ID`, correct the pin and do not fall back to another task. Run `git diff --stat` for code changes not yet recorded there. All planning filenames below mean that selected directory. For parallel tasks, pin each host before it starts or use separate worktrees; a child process export does not change its host. One orchestrator owns a shared plan and summaries, while workers use assigned files or ledgers.
|
||||
|
||||
```bash
|
||||
# Linux/macOS (auto-detects python3 or python)
|
||||
|
||||
@@ -59,12 +59,9 @@ Windows runs the shell chain through Git Bash and nothing else:
|
||||
one turn-marker slot and one progress-guard slot per plan.
|
||||
|
||||
Known, accepted differences from the shell reference:
|
||||
* Two plan directories with the same whole-second mtime, no .active_plan
|
||||
and no PLAN_ID: the reference picks the first in the shell's glob order
|
||||
(locale collation), this twin the first in code-point order. The same
|
||||
collation difference can change which three of four or more nested
|
||||
projects the ambiguity notice names. A machine runs one implementation,
|
||||
so neither choice flips within a session.
|
||||
* Shell glob order follows locale collation; this twin uses code-point
|
||||
order. This can change which three of four or more nested projects the
|
||||
ambiguity notice names.
|
||||
* BSD sed (macOS) appends a newline to a progress.md whose last line has
|
||||
none; GNU sed and this twin do not.
|
||||
* With PWF_PLAN_ROOT set under Git Bash the shell sees the pin as typed
|
||||
@@ -837,6 +834,16 @@ class Injector(object):
|
||||
scope = ""
|
||||
explicit = bool(plan_prefix)
|
||||
plan_id = env.get("PLAN_ID", "")
|
||||
ambiguous = plan_is_ambiguous(
|
||||
plan_prefix + ".planning", plan_root_pin if plan_root_pin else ".", plan_id
|
||||
)
|
||||
if ambiguous and (context == "preflight" or not is_dir(plan_prefix + ".planning/sessions")):
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> "
|
||||
"for this session; nothing injected."
|
||||
)
|
||||
raise Bail()
|
||||
if plan_id:
|
||||
if slug_is_valid(plan_id) and is_dir(plan_prefix + ".planning/" + plan_id):
|
||||
resolved = plan_prefix + ".planning/" + plan_id
|
||||
@@ -923,30 +930,14 @@ class Injector(object):
|
||||
"single-session mode."
|
||||
)
|
||||
raise Bail()
|
||||
if not plan_id:
|
||||
plan_n = 1 if is_file(plan_prefix + "task_plan.md") else 0
|
||||
try:
|
||||
names = sorted(os.listdir(plan_prefix + ".planning"))
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if name.startswith("."):
|
||||
continue
|
||||
if not is_file(plan_prefix + ".planning/" + name + "/task_plan.md"):
|
||||
continue
|
||||
if not slug_is_valid(name):
|
||||
continue
|
||||
plan_n += 1
|
||||
if plan_n > 1:
|
||||
break
|
||||
if plan_n > 1:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
if ambiguous:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
|
||||
if not explicit:
|
||||
nested = []
|
||||
@@ -1326,6 +1317,23 @@ def inject(context, env=None):
|
||||
# Twin of resolve-plan-dir.sh (the shared resolver the dispatcher uses).
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def plan_is_ambiguous(plan_root, project_root, plan_id=""):
|
||||
"""A project pointer or mtime cannot bind a session to multiple plans."""
|
||||
if plan_id:
|
||||
return False
|
||||
count = 1 if is_dir(plan_root + "/sessions") and is_file(project_root + "/task_plan.md") else 0
|
||||
try:
|
||||
names = os.listdir(plan_root)
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if slug_is_valid(name) and is_file(plan_root + "/" + name + "/task_plan.md"):
|
||||
count += 1
|
||||
if count > 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def resolve_plan_dir(env=None):
|
||||
"""Return (spelled, filesystem) paths of the plan directory, or ("", "").
|
||||
|
||||
@@ -1360,6 +1368,9 @@ def resolve_plan_dir(env=None):
|
||||
return found(plan_id)
|
||||
return ("", "")
|
||||
|
||||
if plan_is_ambiguous(fs_root, pin if pin else "."):
|
||||
return ("", "")
|
||||
|
||||
active_file = fs_root + "/.active_plan"
|
||||
if is_file(active_file):
|
||||
try:
|
||||
@@ -1441,6 +1452,8 @@ class ClaudeDispatcher(object):
|
||||
return (spelled, fs)
|
||||
if self.env.get("PLAN_ID", "") or self.env.get("PWF_PLAN_ROOT", ""):
|
||||
return ("", "")
|
||||
if plan_is_ambiguous(".planning", "."):
|
||||
return ("", "")
|
||||
if is_file("task_plan.md"):
|
||||
return (".", ".")
|
||||
return ("", "")
|
||||
|
||||
@@ -254,6 +254,29 @@ is_within_root() {
|
||||
# The .active_plan pointer, the newest-by-mtime fallback, and the legacy root
|
||||
# task_plan.md are cwd GUESSES — only guesses are subject to the nested-root
|
||||
# conflict check below.
|
||||
# Shared .active_plan and directory mtime cannot identify this session's plan.
|
||||
# Check before selection or preflight, even when isolation was never armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_PREFIX}.planning/sessions" ] && [ -f "${PLAN_PREFIX}task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ] && { [ "$CONTEXT" = "preflight" ] || [ ! -d "${PLAN_PREFIX}.planning/sessions" ]; }; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
RESOLVED=""
|
||||
SCOPE=""
|
||||
EXPLICIT=0
|
||||
@@ -442,27 +465,13 @@ PY
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# An attachment admits a session but does not select one of several plans.
|
||||
# When isolation is armed, require PLAN_ID if more than one live same-root
|
||||
# candidate exists. PWF_PLAN_ROOT selects the project root, not a plan
|
||||
# within that root.
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
SESSION_PLAN_N=0
|
||||
[ -f "${PLAN_PREFIX}task_plan.md" ] && SESSION_PLAN_N=1
|
||||
for candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$candidate" ] || continue
|
||||
candidate_dir="${candidate%/task_plan.md}"
|
||||
candidate_slug="${candidate_dir##*/}"
|
||||
slug_is_valid "$candidate_slug" || continue
|
||||
SESSION_PLAN_N=$((SESSION_PLAN_N + 1))
|
||||
[ "$SESSION_PLAN_N" -gt 1 ] && break
|
||||
done
|
||||
if [ "$SESSION_PLAN_N" -gt 1 ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
# Attachment admits a session but does not select its plan. Preserve the
|
||||
# attachment-first notice above for sessions that never opted in.
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
@@ -1,13 +1,25 @@
|
||||
# planning-with-files
|
||||
<div align="center">
|
||||
<img src="https://raw.githubusercontent.com/OthmanAdi/planning-with-files/master/media/v3-banner-1400.jpg" alt="planning-with-files: task_plan.md, findings.md, and progress.md as three stone tablets" width="100%">
|
||||
</div>
|
||||
|
||||
> **Your agent's context window dies. The plan does not.**
|
||||
<h1 align="center">Planning with Files</h1>
|
||||
|
||||
Persistent file-based planning for AI coding agents. The skill keeps `task_plan.md`, `findings.md` and `progress.md` on disk. After `/plan-execute`, Pi lifecycle hooks inject selected project planning context so the plan survives context loss, `/clear`, crashes and compaction. Automatic recovery reads project files only. Reading same-project local session records for aggregate counts or bounded replay requires an explicit catchup mode.
|
||||
<p align="center">
|
||||
<strong>The planning skill your agent cannot ignore.</strong><br>
|
||||
Your agent's context window dies. The plan does not.
|
||||
</p>
|
||||
|
||||
This is the npm distribution of [OthmanAdi/planning-with-files](https://github.com/OthmanAdi/planning-with-files), which installs across 60+ agents via the Agent Skills standard. The package ships:
|
||||
Persistent file-based planning for AI coding agents. Keep the plan, research and progress in your project so work can continue after context loss, `/clear`, crashes or compaction.
|
||||
|
||||
- the planning skill itself: `SKILL.md`, `scripts/` and `templates/`
|
||||
- a [Pi Coding Agent](https://pi.dev) extension providing Claude-style lifecycle automation
|
||||
| File | Purpose |
|
||||
| --- | --- |
|
||||
| `task_plan.md` | Goals, phases and decisions |
|
||||
| `findings.md` | Research and discoveries |
|
||||
| `progress.md` | Work completed, checks and next steps |
|
||||
|
||||
This is the npm distribution of [OthmanAdi/planning-with-files](https://github.com/OthmanAdi/planning-with-files), available across 60+ agents via the Agent Skills standard. It includes the planning skill, scripts and templates. Supported agent integrations add lifecycle hooks that bring selected planning context back into the session.
|
||||
|
||||
Automatic recovery reads project files only. Reading same-project local session records for aggregate counts or bounded replay requires an explicit catchup mode.
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -19,19 +31,40 @@ npm install planning-with-files
|
||||
|
||||
Places the skill, scripts and templates under `node_modules/planning-with-files/`. Use this to pin an exact version into a project, or to copy `SKILL.md` and `scripts/` into your agent's skills directory yourself. It does not register hooks on its own.
|
||||
|
||||
### Pi Install
|
||||
### Agent integrations
|
||||
|
||||
Claude Code gets the full surface (skill, hooks, slash commands) through the plugin route, and 60+ other agents install in one line. See the [main README](https://github.com/OthmanAdi/planning-with-files#quick-install).
|
||||
|
||||
## Usage
|
||||
|
||||
Once the skill is installed for your agent, start with:
|
||||
|
||||
```text
|
||||
Use the planning-with-files skill to help me with this task.
|
||||
```
|
||||
|
||||
The workflow centers on three files in your project:
|
||||
|
||||
```text
|
||||
your-project/
|
||||
├── task_plan.md
|
||||
├── findings.md
|
||||
└── progress.md
|
||||
```
|
||||
|
||||
## Pi Coding Agent integration
|
||||
|
||||
The package also bundles a [Pi Coding Agent](https://pi.dev) extension for lifecycle automation and a planning status bar.
|
||||
|
||||
### Install in Pi
|
||||
|
||||
```bash
|
||||
pi install npm:planning-with-files
|
||||
```
|
||||
|
||||
Wires up the skill, the extension and the status bar automatically.
|
||||
Pi discovers the skill and extension from the installed package.
|
||||
|
||||
### Other agents
|
||||
|
||||
Claude Code gets the full surface (skill, hooks, slash commands) through the plugin route, and 60+ other agents install in one line. See the [main README](https://github.com/OthmanAdi/planning-with-files#quick-install).
|
||||
|
||||
### Manual Install
|
||||
For a local repository checkout:
|
||||
|
||||
```bash
|
||||
# From the planning-with-files repo root
|
||||
@@ -45,27 +78,13 @@ Or add to `.pi/settings.json`:
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Usage
|
||||
|
||||
Pi discovers the skill and extension from the installed package.
|
||||
|
||||
Start with:
|
||||
|
||||
```text
|
||||
Use the planning-with-files skill to help me with this task.
|
||||
```
|
||||
|
||||
Or:
|
||||
You can also invoke the skill directly in Pi:
|
||||
|
||||
```text
|
||||
/skill:planning-with-files
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Hook Parity in Pi
|
||||
### Lifecycle hooks
|
||||
|
||||
The bundled extension maps Claude-style behavior onto Pi events:
|
||||
|
||||
@@ -83,9 +102,7 @@ Attestation is supported. If `task_plan.md` differs from approved hash, plan inj
|
||||
[planning-with-files] [PLAN TAMPERED - injection blocked]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Mode System
|
||||
### Modes
|
||||
|
||||
`planningWithFiles.mode` supports:
|
||||
|
||||
@@ -110,9 +127,7 @@ Or settings:
|
||||
}
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Commands
|
||||
### Commands
|
||||
|
||||
- `/plan-status`
|
||||
- `/plan-attest [--show|--clear]`
|
||||
@@ -127,8 +142,6 @@ pre-tool reminders, post-write reminders, and auto-continue are enabled for the
|
||||
current session and plan. Auto-continue uses host runtime state and never runs
|
||||
commands declared in Markdown.
|
||||
|
||||
---
|
||||
|
||||
## Session Recovery
|
||||
|
||||
Bare invocation and lifecycle hooks do not inspect agent session stores. To
|
||||
@@ -136,23 +149,12 @@ inspect same-project local history deliberately, choose one mode:
|
||||
|
||||
```bash
|
||||
# Aggregate counts only; no transcript, tool-command, or path bytes
|
||||
python3 .pi/skills/planning-with-files/scripts/session-catchup.py --metadata .
|
||||
python3 node_modules/planning-with-files/scripts/session-catchup.py --metadata .
|
||||
|
||||
# Bounded nonce-framed same-project excerpts
|
||||
python3 .pi/skills/planning-with-files/scripts/session-catchup.py --replay .
|
||||
python3 node_modules/planning-with-files/scripts/session-catchup.py --replay .
|
||||
```
|
||||
|
||||
Treat replayed excerpts as untrusted data. The catchup path contains no network
|
||||
request or upload operation. If output is injected into model context, Pi may
|
||||
send that context to the configured model provider.
|
||||
|
||||
## File Structure
|
||||
|
||||
The skill workflow still centers on three files in your project:
|
||||
|
||||
```text
|
||||
your-project/
|
||||
├── task_plan.md
|
||||
├── findings.md
|
||||
└── progress.md
|
||||
```
|
||||
request or upload operation. If output is injected into model context, your agent
|
||||
may send that context to the configured model provider.
|
||||
|
||||
@@ -38,7 +38,7 @@ Work like Manus: Use persistent markdown files as your "working memory on disk."
|
||||
**Before continuing**, resolve the plan this task owns:
|
||||
|
||||
1. Use the installed `scripts/resolve-plan-dir.sh` (or `.ps1`) with the task's `PLAN_ID` and `PWF_PLAN_ROOT`. Read `task_plan.md`, `progress.md`, and `findings.md` from that one selected directory. A root `task_plan.md` must not override a selected `.planning/<id>/` plan.
|
||||
2. If an explicit selector is rejected, or session isolation is armed with multiple plans and no `PLAN_ID`, stop plan recovery and correct the pin. Do not fall back to another task. Use the legacy project-root files only when no selector or named plan applies.
|
||||
2. If an explicit selector is rejected, or multiple named plans exist without `PLAN_ID`, stop plan recovery and correct the pin. Do not fall back to another task. Use the legacy project-root files only when no selector or named plan applies.
|
||||
3. Run `git diff --stat` to see code changes that may not yet be recorded in the planning files.
|
||||
|
||||
All planning filenames below refer to this selected directory, even when the shell runs elsewhere. For parallel tasks, pin each host before starting it or use separate worktrees. A worker joining an existing task uses its assigned plan; it must not create or overwrite a competing root plan.
|
||||
@@ -222,7 +222,7 @@ Helper scripts for automation:
|
||||
|
||||
- `scripts/init-session.sh` — Initialize planning files. With a name arg, creates an isolated plan under `.planning/YYYY-MM-DD-<slug>/` for parallel task workflows. Without args, writes `task_plan.md` at project root (legacy mode, backward-compatible).
|
||||
- `scripts/set-active-plan.sh` — Switch the active plan pointer (`.planning/.active_plan`). Run with a plan ID to switch; run without args to show which plan is current.
|
||||
- `scripts/resolve-plan-dir.sh` — Resolve the active plan directory. A set `$PLAN_ID` is a binding: it resolves or resolution stops, never another plan (issue #237). With no `$PLAN_ID`, checks `.planning/.active_plan`, then newest plan dir by mtime, then falls back to project root (legacy). Used internally by hooks.
|
||||
- `scripts/resolve-plan-dir.sh` — Resolve the active plan directory. A set `$PLAN_ID` is a binding: it resolves or resolution stops, never another plan (issue #237). With no `$PLAN_ID`, multiple named plans refuse selection. A single named plan may use `.planning/.active_plan` or discovery by mtime; otherwise resolution falls back to the project root (legacy). Used internally by hooks.
|
||||
- `scripts/check-complete.sh` — Verify all phases in the active plan are complete.
|
||||
- `scripts/session-catchup.py`: Explicit same-project session-record aggregation or bounded replay (`--metadata` / `--replay`); bare invocation does not access host history.
|
||||
- `scripts/attest-plan.sh` (and `.ps1`) — Lock the current `task_plan.md` content with a SHA-256 attestation (v2.37.0). Hooks then refuse to inject plan content if the file diverges from the attested hash. Use `--show` to print the stored hash, `--clear` to remove the attestation. See `/plan-attest` command.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "planning-with-files",
|
||||
"version": "3.17.0",
|
||||
"version": "3.17.2",
|
||||
"description": "Persistent project planning with selected context injection. Automatic recovery uses project files only; explicit catchup modes read same-project local session records for aggregate counts or bounded replay. The host-aware gate never runs Markdown-declared commands. No network upload path. Ships the skill plus a Pi Coding Agent extension.",
|
||||
"keywords": [
|
||||
"pi-package",
|
||||
|
||||
@@ -404,6 +404,7 @@ function Resolve-PlanFile {
|
||||
$resolver = Join-Path $PSScriptRoot "resolve-plan-dir.ps1"
|
||||
if (-not (Test-Path -LiteralPath $resolver -PathType Leaf)) { return $null }
|
||||
$resolvedDir = @(& $resolver | Where-Object { $_ }) | Select-Object -First 1
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { return $null }
|
||||
if ($resolvedDir) {
|
||||
$planFile = Join-Path $resolvedDir "task_plan.md"
|
||||
return (Resolve-ContainedPlanFile -Candidate $planFile -ExpectedDirectory $resolvedDir)
|
||||
|
||||
@@ -45,6 +45,10 @@ resolve_plan_file() {
|
||||
plan_dir=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
plan_dir="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$plan_dir" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
printf "[plan-attest] Multiple plans are available. Set PLAN_ID=<slug>; nothing was attested.\n" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [ -n "${plan_dir}" ] && [ -f "${plan_dir}/task_plan.md" ]; then
|
||||
printf "%s\n" "${plan_dir}/task_plan.md"
|
||||
|
||||
@@ -35,6 +35,7 @@ if ($PlanFile -ne "") {
|
||||
try {
|
||||
$resolvedDir = (& $resolver 2>$null | Select-Object -First 1)
|
||||
if ($null -eq $resolvedDir) { $resolvedDir = "" }
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { exit 0 }
|
||||
} catch {
|
||||
$resolvedDir = ""
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ else
|
||||
RESOLVED_DIR=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
RESOLVED_DIR="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$RESOLVED_DIR" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ -n "${RESOLVED_DIR}" ] && [ -f "${RESOLVED_DIR}/task_plan.md" ]; then
|
||||
PLAN_FILE="${RESOLVED_DIR}/task_plan.md"
|
||||
|
||||
@@ -59,12 +59,9 @@ Windows runs the shell chain through Git Bash and nothing else:
|
||||
one turn-marker slot and one progress-guard slot per plan.
|
||||
|
||||
Known, accepted differences from the shell reference:
|
||||
* Two plan directories with the same whole-second mtime, no .active_plan
|
||||
and no PLAN_ID: the reference picks the first in the shell's glob order
|
||||
(locale collation), this twin the first in code-point order. The same
|
||||
collation difference can change which three of four or more nested
|
||||
projects the ambiguity notice names. A machine runs one implementation,
|
||||
so neither choice flips within a session.
|
||||
* Shell glob order follows locale collation; this twin uses code-point
|
||||
order. This can change which three of four or more nested projects the
|
||||
ambiguity notice names.
|
||||
* BSD sed (macOS) appends a newline to a progress.md whose last line has
|
||||
none; GNU sed and this twin do not.
|
||||
* With PWF_PLAN_ROOT set under Git Bash the shell sees the pin as typed
|
||||
@@ -837,6 +834,16 @@ class Injector(object):
|
||||
scope = ""
|
||||
explicit = bool(plan_prefix)
|
||||
plan_id = env.get("PLAN_ID", "")
|
||||
ambiguous = plan_is_ambiguous(
|
||||
plan_prefix + ".planning", plan_root_pin if plan_root_pin else ".", plan_id
|
||||
)
|
||||
if ambiguous and (context == "preflight" or not is_dir(plan_prefix + ".planning/sessions")):
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> "
|
||||
"for this session; nothing injected."
|
||||
)
|
||||
raise Bail()
|
||||
if plan_id:
|
||||
if slug_is_valid(plan_id) and is_dir(plan_prefix + ".planning/" + plan_id):
|
||||
resolved = plan_prefix + ".planning/" + plan_id
|
||||
@@ -923,30 +930,14 @@ class Injector(object):
|
||||
"single-session mode."
|
||||
)
|
||||
raise Bail()
|
||||
if not plan_id:
|
||||
plan_n = 1 if is_file(plan_prefix + "task_plan.md") else 0
|
||||
try:
|
||||
names = sorted(os.listdir(plan_prefix + ".planning"))
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if name.startswith("."):
|
||||
continue
|
||||
if not is_file(plan_prefix + ".planning/" + name + "/task_plan.md"):
|
||||
continue
|
||||
if not slug_is_valid(name):
|
||||
continue
|
||||
plan_n += 1
|
||||
if plan_n > 1:
|
||||
break
|
||||
if plan_n > 1:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
if ambiguous:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
|
||||
if not explicit:
|
||||
nested = []
|
||||
@@ -1326,6 +1317,23 @@ def inject(context, env=None):
|
||||
# Twin of resolve-plan-dir.sh (the shared resolver the dispatcher uses).
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def plan_is_ambiguous(plan_root, project_root, plan_id=""):
|
||||
"""A project pointer or mtime cannot bind a session to multiple plans."""
|
||||
if plan_id:
|
||||
return False
|
||||
count = 1 if is_dir(plan_root + "/sessions") and is_file(project_root + "/task_plan.md") else 0
|
||||
try:
|
||||
names = os.listdir(plan_root)
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if slug_is_valid(name) and is_file(plan_root + "/" + name + "/task_plan.md"):
|
||||
count += 1
|
||||
if count > 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def resolve_plan_dir(env=None):
|
||||
"""Return (spelled, filesystem) paths of the plan directory, or ("", "").
|
||||
|
||||
@@ -1360,6 +1368,9 @@ def resolve_plan_dir(env=None):
|
||||
return found(plan_id)
|
||||
return ("", "")
|
||||
|
||||
if plan_is_ambiguous(fs_root, pin if pin else "."):
|
||||
return ("", "")
|
||||
|
||||
active_file = fs_root + "/.active_plan"
|
||||
if is_file(active_file):
|
||||
try:
|
||||
@@ -1441,6 +1452,8 @@ class ClaudeDispatcher(object):
|
||||
return (spelled, fs)
|
||||
if self.env.get("PLAN_ID", "") or self.env.get("PWF_PLAN_ROOT", ""):
|
||||
return ("", "")
|
||||
if plan_is_ambiguous(".planning", "."):
|
||||
return ("", "")
|
||||
if is_file("task_plan.md"):
|
||||
return (".", ".")
|
||||
return ("", "")
|
||||
|
||||
@@ -254,6 +254,29 @@ is_within_root() {
|
||||
# The .active_plan pointer, the newest-by-mtime fallback, and the legacy root
|
||||
# task_plan.md are cwd GUESSES — only guesses are subject to the nested-root
|
||||
# conflict check below.
|
||||
# Shared .active_plan and directory mtime cannot identify this session's plan.
|
||||
# Check before selection or preflight, even when isolation was never armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_PREFIX}.planning/sessions" ] && [ -f "${PLAN_PREFIX}task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ] && { [ "$CONTEXT" = "preflight" ] || [ ! -d "${PLAN_PREFIX}.planning/sessions" ]; }; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
RESOLVED=""
|
||||
SCOPE=""
|
||||
EXPLICIT=0
|
||||
@@ -442,27 +465,13 @@ PY
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# An attachment admits a session but does not select one of several plans.
|
||||
# When isolation is armed, require PLAN_ID if more than one live same-root
|
||||
# candidate exists. PWF_PLAN_ROOT selects the project root, not a plan
|
||||
# within that root.
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
SESSION_PLAN_N=0
|
||||
[ -f "${PLAN_PREFIX}task_plan.md" ] && SESSION_PLAN_N=1
|
||||
for candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$candidate" ] || continue
|
||||
candidate_dir="${candidate%/task_plan.md}"
|
||||
candidate_slug="${candidate_dir##*/}"
|
||||
slug_is_valid "$candidate_slug" || continue
|
||||
SESSION_PLAN_N=$((SESSION_PLAN_N + 1))
|
||||
[ "$SESSION_PLAN_N" -gt 1 ] && break
|
||||
done
|
||||
if [ "$SESSION_PLAN_N" -gt 1 ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
# Attachment admits a session but does not select its plan. Preserve the
|
||||
# attachment-first notice above for sessions that never opted in.
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
# junction/symlink escape; slug validation alone blocks textual traversal.
|
||||
|
||||
param(
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning")
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning"),
|
||||
[switch]$CheckAmbiguity
|
||||
)
|
||||
|
||||
$projectRoot = (Get-Location).Path
|
||||
@@ -137,6 +138,30 @@ $activeFile = Join-Path $PlanRoot ".active_plan"
|
||||
# at rc=0. Emptiness is the fail-closed signal on this channel, matching
|
||||
# resolve-plan-dir.sh and the PWF_PLAN_ROOT pin. An empty $env:PLAN_ID is
|
||||
# falsy here and still means "unset".
|
||||
# The optional probe distinguishes ambiguity from a legacy-root fallback.
|
||||
# Multiple named plans require PLAN_ID even without a sessions directory.
|
||||
$planCount = 0
|
||||
if (-not $env:PLAN_ID) {
|
||||
if ((Test-Path -LiteralPath (Join-Path $PlanRoot "sessions") -PathType Container) -and
|
||||
(Test-Path -LiteralPath (Join-Path $projectRoot "task_plan.md") -PathType Leaf)) {
|
||||
$planCount = 1
|
||||
}
|
||||
if (Test-Path -LiteralPath $PlanRoot -PathType Container) {
|
||||
foreach ($entry in (Get-ChildItem -LiteralPath $PlanRoot -Directory -ErrorAction SilentlyContinue)) {
|
||||
if ((Test-ValidSlug $entry.Name) -and
|
||||
(Test-Path -LiteralPath (Join-Path $entry.FullName "task_plan.md") -PathType Leaf)) {
|
||||
$planCount++
|
||||
if ($planCount -gt 1) { break }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($CheckAmbiguity) {
|
||||
if ($planCount -gt 1) { Write-Output "PWF_PLAN_AMBIGUOUS_V1" }
|
||||
exit 0
|
||||
}
|
||||
if ($planCount -gt 1) { exit 0 }
|
||||
|
||||
if ($env:PLAN_ID) {
|
||||
if (Test-ValidSlug $env:PLAN_ID) {
|
||||
$candidate = Join-Path $PlanRoot $env:PLAN_ID
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
@@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [3.17.2] - 2026-09-09
|
||||
|
||||
### Fixed
|
||||
- The native Codex plugin explicitly disables legacy command migration with `"commands": []`. Codex no longer turns the 13 top-level Claude commands into redundant `source-command-*` skills when installing the plugin. The canonical planning skill and Codex hooks remain configured, and Claude retains its commands (#241).
|
||||
|
||||
### Thanks
|
||||
- @sunznx, for reporting the duplicate skills, tracing the fallback, and proposing the scoped manifest fix in #241.
|
||||
|
||||
## [3.17.1] - 2026-09-08
|
||||
|
||||
### Fixed
|
||||
- Multiple named plans now require `PLAN_ID` even when `.planning/sessions/` does not exist. A shared `.active_plan` pointer or directory modification time can no longer silently redirect a Codex session after compaction (#240).
|
||||
- Shell, PowerShell and Python selection paths refuse ambiguous plans. UserPromptSubmit explains the missing pin; per-tool and PreCompact hooks remain quiet, and Stop and attestation do not fall back to an unrelated root plan. Explicit pins, single named plans and legacy root plans remain supported.
|
||||
|
||||
### Thanks
|
||||
- @sunznx, for the same-cwd Codex regression report and reproduction in #240.
|
||||
|
||||
## [3.17.0] - 2026-09-07
|
||||
|
||||
Every Claude Code hook fire forked about 130 processes. On Windows that took longer than the hook timeout, so the plan never reached the model. Found on the maintainer's own machine the day after 3.16.1 shipped.
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ authors:
|
||||
- family-names: Adi
|
||||
given-names: Ahmad Othman Ammar
|
||||
alias: OthmanAdi
|
||||
version: "3.17.0"
|
||||
date-released: "2026-08-31"
|
||||
version: "3.17.2"
|
||||
date-released: "2026-09-09"
|
||||
license: MIT
|
||||
url: "https://github.com/OthmanAdi/planning-with-files"
|
||||
repository-code: "https://github.com/OthmanAdi/planning-with-files"
|
||||
|
||||
+6
-2
@@ -106,6 +106,10 @@ These amazing people have contributed code, documentation, or significant improv
|
||||
|
||||
### Other Contributors
|
||||
|
||||
- **[@sunznx](https://github.com/sunznx)**, [Issue #240](https://github.com/OthmanAdi/planning-with-files/issues/240), [Issue #241](https://github.com/OthmanAdi/planning-with-files/issues/241)
|
||||
- Reported and reproduced named-plan crossover between Codex sessions sharing a working directory after compaction.
|
||||
- Reported the 13 duplicate Codex command skills, traced the legacy command fallback, and proposed the native manifest setting that disables it.
|
||||
|
||||
- **[@hzura](https://github.com/hzura)**, [Issue #50](https://github.com/OthmanAdi/planning-with-files/issues/50)
|
||||
- Raised the same-repository parallel-task workflow that led to explicit plan selection and shared-file ownership guidance.
|
||||
|
||||
@@ -421,6 +425,6 @@ If you've contributed and don't see your name here, please open an issue! We wan
|
||||
|
||||
---
|
||||
|
||||
**Total Contributors:** 58+ and growing!
|
||||
**Total Contributors:** 59+ and growing!
|
||||
|
||||
*Last updated: 2026-09-05*
|
||||
*Last updated: 2026-09-09*
|
||||
|
||||
@@ -354,6 +354,8 @@ One hook fire measures 289ms wall-clock since the v3.6.0 optimization, down from
|
||||
|
||||
| Version | Highlights |
|
||||
|---------|------------|
|
||||
| **v3.17.2** | Fixes #241: the native Codex manifest disables legacy command migration, removing 13 redundant `source-command-*` skills from plugin installs. The canonical planning skill, Codex hooks, and Claude commands remain available. |
|
||||
| **v3.17.1** | Fixes #240: two named plans in the same project now require `PLAN_ID`, even without `.planning/sessions/`. A shared pointer or newest-plan guess cannot redirect a Codex session across compaction. Ambiguous hooks inject no plan and Stop does not gate against a guessed plan. |
|
||||
| **v3.17.0** | **Every Claude Code hook fire forked about 130 processes, and under Git Bash on Windows that took 7 to 12 seconds against the 10 second hook timeout.** Claude Code discarded the plan context ("UserPromptSubmit hook timed out after 10s") and every Bash, Read, Grep and Edit call waited 5 more seconds in PreToolUse before it ran. Linux and macOS never showed it because a fork costs milliseconds there. The events now run in one Python process, `scripts/inject-plan.py`, a byte-identical twin of the shell chain proven by a parity suite on all three CI legs, with the shell chain kept as the reference and as the fallback for hosts without Python: 0.3 s per prompt and per tool call on the reporting machine. Hook interpreters now start in isolated mode, so a repository's own `secrets.py` or `hashlib.py` is never imported by a hook. `PWF_FAST_PATH=0` forces the shell chain. |
|
||||
| **v3.16.1** | Attached Codex, Hermes and Pi sessions require an explicit plan when several tasks share an armed project. Standalone hooks deliver model context through the proper event fields, preserve native session identity and throttle progress reminders. Packages include the loop template and Stop dependencies; recovery and security guidance state the selected-plan and trust boundaries. |
|
||||
| **v3.16.0** | **The PostToolUse progress reminder was shown to you and never to Claude** (closes #239, reported by @sortakool). It was emitted as `systemMessage`, which Claude Code delivers to the user, so a sentence addressed to the model reached the person instead, after every `Write`, `Edit` and `Bash` call for a whole session. Both the plugin dispatcher and the Codex adapter now emit `hookSpecificOutput.additionalContext`, the shape the session-start path in the same file already used. The reminder is also throttled to once per turn instead of once per tool call, and `Bash` is off the PostToolUse matchers so `ls` and `git status` stop tripping a "record what you changed" nudge. PreToolUse keeps `Bash`. Fixing this surfaced one more copy of the #237 fallback in the plugin dispatcher, now closed. |
|
||||
|
||||
@@ -228,3 +228,9 @@ Use the workspace install (Method 1) on Windows: the `commandWindows` entries us
|
||||
- **GitHub Issues:** https://github.com/OthmanAdi/planning-with-files/issues
|
||||
- **OpenAI Codex Hooks Docs:** https://developers.openai.com/codex/hooks
|
||||
- **OpenAI Codex Skills Docs:** https://developers.openai.com/codex/skills
|
||||
|
||||
### Multiple named plans in one project
|
||||
|
||||
As of v3.17.1, a project with more than one live named plan requires `PLAN_ID` for each Codex session, whether or not `.planning/sessions/` exists. Set the pin in the environment that launches the host. Exporting it inside a tool subprocess cannot change an already-running host. A shared `.planning/.active_plan` pointer cannot select a plan for that session.
|
||||
|
||||
When no pin is available, UserPromptSubmit explains the ambiguity and injects no plan. Per-tool and PreCompact hooks remain quiet, and Stop allows the session to end without evaluating a guessed plan. Explicit pins, single named plans and legacy root plans remain supported.
|
||||
|
||||
@@ -164,6 +164,9 @@ active_plan_dir() {
|
||||
_resolved=""
|
||||
if [ -f "$RESOLVE_PLAN_DIR" ]; then
|
||||
_resolved=$(sh "$RESOLVE_PLAN_DIR" 2>/dev/null) || _resolved=""
|
||||
if [ -z "$_resolved" ] && [ "$(sh "$RESOLVE_PLAN_DIR" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
if [ -n "$_resolved" ] && [ -f "${_resolved}/task_plan.md" ]; then
|
||||
printf '%s\n' "$_resolved"
|
||||
|
||||
@@ -404,6 +404,7 @@ function Resolve-PlanFile {
|
||||
$resolver = Join-Path $PSScriptRoot "resolve-plan-dir.ps1"
|
||||
if (-not (Test-Path -LiteralPath $resolver -PathType Leaf)) { return $null }
|
||||
$resolvedDir = @(& $resolver | Where-Object { $_ }) | Select-Object -First 1
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { return $null }
|
||||
if ($resolvedDir) {
|
||||
$planFile = Join-Path $resolvedDir "task_plan.md"
|
||||
return (Resolve-ContainedPlanFile -Candidate $planFile -ExpectedDirectory $resolvedDir)
|
||||
|
||||
@@ -45,6 +45,10 @@ resolve_plan_file() {
|
||||
plan_dir=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
plan_dir="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$plan_dir" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
printf "[plan-attest] Multiple plans are available. Set PLAN_ID=<slug>; nothing was attested.\n" >&2
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
if [ -n "${plan_dir}" ] && [ -f "${plan_dir}/task_plan.md" ]; then
|
||||
printf "%s\n" "${plan_dir}/task_plan.md"
|
||||
|
||||
@@ -35,6 +35,7 @@ if ($PlanFile -ne "") {
|
||||
try {
|
||||
$resolvedDir = (& $resolver 2>$null | Select-Object -First 1)
|
||||
if ($null -eq $resolvedDir) { $resolvedDir = "" }
|
||||
if (-not $resolvedDir -and ((& $resolver -CheckAmbiguity) -eq "PWF_PLAN_AMBIGUOUS_V1")) { exit 0 }
|
||||
} catch {
|
||||
$resolvedDir = ""
|
||||
}
|
||||
|
||||
@@ -56,6 +56,9 @@ else
|
||||
RESOLVED_DIR=""
|
||||
if [ -f "${RESOLVER}" ]; then
|
||||
RESOLVED_DIR="$(sh "${RESOLVER}" 2>/dev/null)"
|
||||
if [ -z "$RESOLVED_DIR" ] && [ "$(sh "${RESOLVER}" --check-ambiguity 2>/dev/null)" = "PWF_PLAN_AMBIGUOUS_V1" ]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
if [ -n "${RESOLVED_DIR}" ] && [ -f "${RESOLVED_DIR}/task_plan.md" ]; then
|
||||
PLAN_FILE="${RESOLVED_DIR}/task_plan.md"
|
||||
|
||||
+43
-30
@@ -59,12 +59,9 @@ Windows runs the shell chain through Git Bash and nothing else:
|
||||
one turn-marker slot and one progress-guard slot per plan.
|
||||
|
||||
Known, accepted differences from the shell reference:
|
||||
* Two plan directories with the same whole-second mtime, no .active_plan
|
||||
and no PLAN_ID: the reference picks the first in the shell's glob order
|
||||
(locale collation), this twin the first in code-point order. The same
|
||||
collation difference can change which three of four or more nested
|
||||
projects the ambiguity notice names. A machine runs one implementation,
|
||||
so neither choice flips within a session.
|
||||
* Shell glob order follows locale collation; this twin uses code-point
|
||||
order. This can change which three of four or more nested projects the
|
||||
ambiguity notice names.
|
||||
* BSD sed (macOS) appends a newline to a progress.md whose last line has
|
||||
none; GNU sed and this twin do not.
|
||||
* With PWF_PLAN_ROOT set under Git Bash the shell sees the pin as typed
|
||||
@@ -837,6 +834,16 @@ class Injector(object):
|
||||
scope = ""
|
||||
explicit = bool(plan_prefix)
|
||||
plan_id = env.get("PLAN_ID", "")
|
||||
ambiguous = plan_is_ambiguous(
|
||||
plan_prefix + ".planning", plan_root_pin if plan_root_pin else ".", plan_id
|
||||
)
|
||||
if ambiguous and (context == "preflight" or not is_dir(plan_prefix + ".planning/sessions")):
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> "
|
||||
"for this session; nothing injected."
|
||||
)
|
||||
raise Bail()
|
||||
if plan_id:
|
||||
if slug_is_valid(plan_id) and is_dir(plan_prefix + ".planning/" + plan_id):
|
||||
resolved = plan_prefix + ".planning/" + plan_id
|
||||
@@ -923,30 +930,14 @@ class Injector(object):
|
||||
"single-session mode."
|
||||
)
|
||||
raise Bail()
|
||||
if not plan_id:
|
||||
plan_n = 1 if is_file(plan_prefix + "task_plan.md") else 0
|
||||
try:
|
||||
names = sorted(os.listdir(plan_prefix + ".planning"))
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if name.startswith("."):
|
||||
continue
|
||||
if not is_file(plan_prefix + ".planning/" + name + "/task_plan.md"):
|
||||
continue
|
||||
if not slug_is_valid(name):
|
||||
continue
|
||||
plan_n += 1
|
||||
if plan_n > 1:
|
||||
break
|
||||
if plan_n > 1:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
if ambiguous:
|
||||
if context == "userprompt":
|
||||
self.echo(
|
||||
"[planning-with-files] Multiple plans are available while session "
|
||||
"isolation is armed. Set PLAN_ID=<slug> for this session; nothing "
|
||||
"injected."
|
||||
)
|
||||
raise Bail()
|
||||
|
||||
if not explicit:
|
||||
nested = []
|
||||
@@ -1326,6 +1317,23 @@ def inject(context, env=None):
|
||||
# Twin of resolve-plan-dir.sh (the shared resolver the dispatcher uses).
|
||||
# --------------------------------------------------------------------------
|
||||
|
||||
def plan_is_ambiguous(plan_root, project_root, plan_id=""):
|
||||
"""A project pointer or mtime cannot bind a session to multiple plans."""
|
||||
if plan_id:
|
||||
return False
|
||||
count = 1 if is_dir(plan_root + "/sessions") and is_file(project_root + "/task_plan.md") else 0
|
||||
try:
|
||||
names = os.listdir(plan_root)
|
||||
except OSError:
|
||||
names = []
|
||||
for name in names:
|
||||
if slug_is_valid(name) and is_file(plan_root + "/" + name + "/task_plan.md"):
|
||||
count += 1
|
||||
if count > 1:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def resolve_plan_dir(env=None):
|
||||
"""Return (spelled, filesystem) paths of the plan directory, or ("", "").
|
||||
|
||||
@@ -1360,6 +1368,9 @@ def resolve_plan_dir(env=None):
|
||||
return found(plan_id)
|
||||
return ("", "")
|
||||
|
||||
if plan_is_ambiguous(fs_root, pin if pin else "."):
|
||||
return ("", "")
|
||||
|
||||
active_file = fs_root + "/.active_plan"
|
||||
if is_file(active_file):
|
||||
try:
|
||||
@@ -1441,6 +1452,8 @@ class ClaudeDispatcher(object):
|
||||
return (spelled, fs)
|
||||
if self.env.get("PLAN_ID", "") or self.env.get("PWF_PLAN_ROOT", ""):
|
||||
return ("", "")
|
||||
if plan_is_ambiguous(".planning", "."):
|
||||
return ("", "")
|
||||
if is_file("task_plan.md"):
|
||||
return (".", ".")
|
||||
return ("", "")
|
||||
|
||||
+29
-20
@@ -254,6 +254,29 @@ is_within_root() {
|
||||
# The .active_plan pointer, the newest-by-mtime fallback, and the legacy root
|
||||
# task_plan.md are cwd GUESSES — only guesses are subject to the nested-root
|
||||
# conflict check below.
|
||||
# Shared .active_plan and directory mtime cannot identify this session's plan.
|
||||
# Check before selection or preflight, even when isolation was never armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_PREFIX}.planning/sessions" ] && [ -f "${PLAN_PREFIX}task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ] && { [ "$CONTEXT" = "preflight" ] || [ ! -d "${PLAN_PREFIX}.planning/sessions" ]; }; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
|
||||
RESOLVED=""
|
||||
SCOPE=""
|
||||
EXPLICIT=0
|
||||
@@ -442,27 +465,13 @@ PY
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# An attachment admits a session but does not select one of several plans.
|
||||
# When isolation is armed, require PLAN_ID if more than one live same-root
|
||||
# candidate exists. PWF_PLAN_ROOT selects the project root, not a plan
|
||||
# within that root.
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
SESSION_PLAN_N=0
|
||||
[ -f "${PLAN_PREFIX}task_plan.md" ] && SESSION_PLAN_N=1
|
||||
for candidate in "${PLAN_PREFIX}".planning/*/task_plan.md; do
|
||||
[ -f "$candidate" ] || continue
|
||||
candidate_dir="${candidate%/task_plan.md}"
|
||||
candidate_slug="${candidate_dir##*/}"
|
||||
slug_is_valid "$candidate_slug" || continue
|
||||
SESSION_PLAN_N=$((SESSION_PLAN_N + 1))
|
||||
[ "$SESSION_PLAN_N" -gt 1 ] && break
|
||||
done
|
||||
if [ "$SESSION_PLAN_N" -gt 1 ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
# Attachment admits a session but does not select its plan. Preserve the
|
||||
# attachment-first notice above for sessions that never opted in.
|
||||
if [ "$PLAN_AMBIGUOUS" = "1" ]; then
|
||||
if [ "$CONTEXT" = "userprompt" ]; then
|
||||
echo "[planning-with-files] Multiple plans are available while session isolation is armed. Set PLAN_ID=<slug> for this session; nothing injected."
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
@@ -13,7 +13,8 @@
|
||||
# junction/symlink escape; slug validation alone blocks textual traversal.
|
||||
|
||||
param(
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning")
|
||||
[string]$PlanRoot = (Join-Path (Get-Location) ".planning"),
|
||||
[switch]$CheckAmbiguity
|
||||
)
|
||||
|
||||
$projectRoot = (Get-Location).Path
|
||||
@@ -137,6 +138,30 @@ $activeFile = Join-Path $PlanRoot ".active_plan"
|
||||
# at rc=0. Emptiness is the fail-closed signal on this channel, matching
|
||||
# resolve-plan-dir.sh and the PWF_PLAN_ROOT pin. An empty $env:PLAN_ID is
|
||||
# falsy here and still means "unset".
|
||||
# The optional probe distinguishes ambiguity from a legacy-root fallback.
|
||||
# Multiple named plans require PLAN_ID even without a sessions directory.
|
||||
$planCount = 0
|
||||
if (-not $env:PLAN_ID) {
|
||||
if ((Test-Path -LiteralPath (Join-Path $PlanRoot "sessions") -PathType Container) -and
|
||||
(Test-Path -LiteralPath (Join-Path $projectRoot "task_plan.md") -PathType Leaf)) {
|
||||
$planCount = 1
|
||||
}
|
||||
if (Test-Path -LiteralPath $PlanRoot -PathType Container) {
|
||||
foreach ($entry in (Get-ChildItem -LiteralPath $PlanRoot -Directory -ErrorAction SilentlyContinue)) {
|
||||
if ((Test-ValidSlug $entry.Name) -and
|
||||
(Test-Path -LiteralPath (Join-Path $entry.FullName "task_plan.md") -PathType Leaf)) {
|
||||
$planCount++
|
||||
if ($planCount -gt 1) { break }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($CheckAmbiguity) {
|
||||
if ($planCount -gt 1) { Write-Output "PWF_PLAN_AMBIGUOUS_V1" }
|
||||
exit 0
|
||||
}
|
||||
if ($planCount -gt 1) { exit 0 }
|
||||
|
||||
if ($env:PLAN_ID) {
|
||||
if (Test-ValidSlug $env:PLAN_ID) {
|
||||
$candidate = Join-Path $PlanRoot $env:PLAN_ID
|
||||
|
||||
@@ -15,6 +15,13 @@
|
||||
|
||||
set -u
|
||||
|
||||
# Optional probe distinguishes ambiguity from the empty legacy-root result.
|
||||
# Both modes keep stdout data-only and always exit zero.
|
||||
CHECK_AMBIGUITY=0
|
||||
if [ "${1:-}" = "--check-ambiguity" ]; then
|
||||
CHECK_AMBIGUITY=1
|
||||
shift
|
||||
fi
|
||||
PLAN_ROOT="${1:-${PWD}/.planning}"
|
||||
|
||||
# --- PWF_PLAN_ROOT: absolute plan-root binding (issue #212). ---
|
||||
@@ -321,6 +328,29 @@ resolve_latest_dir() {
|
||||
# the fail-closed signal on this channel, exactly as the PWF_PLAN_ROOT guard
|
||||
# above already does it; a non-zero status would kill callers running under
|
||||
# set -e for a condition that is not an internal error.
|
||||
# A shared pointer or mtime is not a per-session binding (issue #240).
|
||||
# Count conservatively, just like injection: slug-valid live plan files.
|
||||
# The legacy root joins the count only when session isolation is armed.
|
||||
PLAN_AMBIGUOUS=0
|
||||
if [ -z "${PLAN_ID:-}" ]; then
|
||||
PLAN_COUNT=0
|
||||
if [ -d "${PLAN_ROOT}/sessions" ] && [ -f "${PWF_ROOT_PIN:-.}/task_plan.md" ]; then
|
||||
PLAN_COUNT=1
|
||||
fi
|
||||
for plan_candidate in "${PLAN_ROOT}"/*/task_plan.md; do
|
||||
[ -f "$plan_candidate" ] || continue
|
||||
plan_candidate_dir="${plan_candidate%/task_plan.md}"
|
||||
slug_is_valid "${plan_candidate_dir##*/}" || continue
|
||||
PLAN_COUNT=$((PLAN_COUNT + 1))
|
||||
if [ "$PLAN_COUNT" -gt 1 ]; then PLAN_AMBIGUOUS=1; break; fi
|
||||
done
|
||||
fi
|
||||
if [ "$CHECK_AMBIGUITY" = "1" ]; then
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && printf '%s\n' 'PWF_PLAN_AMBIGUOUS_V1'
|
||||
exit 0
|
||||
fi
|
||||
[ "$PLAN_AMBIGUOUS" = "1" ] && exit 0
|
||||
|
||||
if [ -n "${PLAN_ID:-}" ]; then
|
||||
resolve_from_env && exit 0
|
||||
exit 0
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user