mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-17 04:45:33 -08:00
Port upstream skill scripts into v2.4.1: deterministic workflow steps run as Node scripts beside each SKILL.md (specs, pathfinder, feedback payload, commit message, review scope, agent files, handoff path) with tests, the prompt limit rises to 20,000 chars, upstream review fixes are folded in (linked agent files never overwrite AGENTS.md, review stops with no base, paste-safe commit commands, Pathfinder number high-water mark and dry runs), and web console workspace folders are remembered per project and spec, with Finalize forgetting an archived spec's list
AI Assisted
This commit is contained in:
1 parent
c0ea70e838
commit
6a66440095
243 files changed
+23698
-1607
No files matched your search
@@ -10,6 +10,14 @@ Senior software engineer implementing solutions exactly as specified. Follow spe
|
||||
|
||||
The FIRST thing you do, before anything else in this file — before reading a spec, before Phase 1: ask **web console** (browser page, suggested) or **terminal**? Console → run `node "<D>/console.mjs" open --workflow implement` before reading (<D>: references/web-console/ beside this SKILL.md — ~/.agents/skills/plan2code-3-implement/references/web-console/ globally — or the dir in ~/.plan2code/console/console-dir), then <D>/console.md and <D>/building.md; progress, every question and the sign-off go through it. Switchable anytime. If the argument already says which — `--web` or `Use the web console for this session.` — take it and do not ask; drop the flag. Launched by the dashboard? Its session is already open — resume it (console.md → Launches), then the spec.
|
||||
|
||||
## Scripts
|
||||
|
||||
`<S>` is `scripts/` beside this SKILL.md (`~/.agents/skills/plan2code-3-implement/scripts/` globally; for Implement + Review, its own skill's `scripts/`). Run them from the project root. Each prints one JSON object; on a non-zero exit read `message` and do what `next` says.
|
||||
|
||||
- `node "<S>/specs.mjs" status <spec>`: the Phase Checklist, parallel groups, every phase's task counts by marker, goal, the phase-selection verdict (`next`) and consistency `checks`.
|
||||
- `node "<S>/specs.mjs" mark <spec> --phase <N> --to in-progress|done`: the overview checkbox (and on `done`, the phase file's Status line). It refuses to reset `[/]` to `[ ]`.
|
||||
- `node "<S>/commit-msg.mjs" --subject "<subject>" --add-all`: the commit command, ticket taken from the branch.
|
||||
|
||||
## Rules
|
||||
|
||||
- Follow `./AGENTS.md` if it exists
|
||||
@@ -25,28 +33,15 @@ The FIRST thing you do, before anything else in this file — before reading a s
|
||||
|
||||
## Required Context
|
||||
|
||||
⚠️ IMPORTANT: `specs/` is gitignored — NEVER use Glob (silently fails). Shell only: `ls specs/` (Bash) or `Get-ChildItem specs/` (PS).
|
||||
Need implementation spec files to proceed. `specs/` is gitignored, so never search it with Glob; the script reads the disk directly and never looks in `specs--completed/`.
|
||||
|
||||
Need implementation spec files to proceed.
|
||||
**Option 1: User provides an overview.md path** → `specs.mjs status <that path>`.
|
||||
|
||||
**IMPORTANT:** Never look in `specs--completed/` (archived only). Only check active spec folders under `specs/`.
|
||||
**Option 2: Auto-detect** → `specs.mjs list`. Exactly one spec with phases (`phaseFiles` > 0) → `status` it.
|
||||
|
||||
**Option 1: User provides overview.md path**
|
||||
1. Read the overview.md file
|
||||
2. Find "Phase Checklist" section
|
||||
3. Identify workable phases: `[ ]` (pending) or `[/]` (in-progress)
|
||||
4. Check for parallel execution options
|
||||
5. Apply phase selection logic
|
||||
6. Read corresponding `phase-X.md` from same directory
|
||||
7. Begin implementation
|
||||
**Option 3: Several specs or none** → ask: "Please provide the path to the overview.md file (e.g., `specs/user-authentication/overview.md`)"
|
||||
|
||||
**Option 2: Auto-detect from specs folder**
|
||||
If no file provided, look for single `specs/<feature-name>` folder. If found, read its `overview.md` and follow Option 1.
|
||||
|
||||
**Option 3: Multiple specs or nothing found**
|
||||
Ask user: "Please provide the path to the overview.md file (e.g., `specs/user-authentication/overview.md`)"
|
||||
|
||||
Do not proceed without successfully reading overview.md and determining the next phase.
|
||||
Then read overview.md and act on `next` (Parallel Phase Selection below). Any `error` in `checks` (a phase marked `[x]` with open tasks, a checklist row with no phase file) is worth one line to the user before you start. Do not proceed without a readable overview.md and a `next` verdict.
|
||||
|
||||
## Phase Status Tracking
|
||||
|
||||
@@ -70,16 +65,16 @@ Never reset `[/]` to `[ ]`. Started work stays marked for conscious resume decis
|
||||
|
||||
## Parallel Phase Selection
|
||||
|
||||
Check overview.md for "Parallel Execution Groups" section. Find workable phases (`[ ]` or `[/]`).
|
||||
`status` applies the selection rules (workable = `[ ]` or `[/]`; consecutive incomplete phases of one parallel group are offered together) and returns `next`:
|
||||
|
||||
| Condition | Action |
|
||||
| `next.action` | Action |
|
||||
|-----------|--------|
|
||||
| 2+ workable phases in same parallel group | Show selection prompt listing each with status. TIP: run another agent on a different phase simultaneously. If all are `[/]`, warn about duplication. |
|
||||
| Single `[/]` phase | Prompt: "Phase X is in progress. Resume? (yes/no)" |
|
||||
| Single `[ ]` phase | Auto-start: mark `[/]` and begin |
|
||||
| No parallel groups section | Sequential mode (single-phase rules above) |
|
||||
| `choose` | Show a selection prompt listing each of `options` with its status. TIP: run another agent on a different phase simultaneously. Relay `warning` (all already `[/]`: duplicated work) when present. |
|
||||
| `ask-resume` | Prompt: "Phase X is in progress. Resume? (yes/no)" Relay `warning` when present. |
|
||||
| `auto-start` | Mark it `[/]` and begin. Relay `warning` when present. |
|
||||
| `none` | Nothing to implement: say why (`reason`). Every phase complete → `/plan2code-4-finalize --web` |
|
||||
|
||||
Only show consecutive same-group incomplete phases. After selection, mark `[/]`, read `phase-X.md`, begin.
|
||||
After selection, `mark --to in-progress`, read `phase-X.md`, begin.
|
||||
|
||||
## Code Consistency Rules
|
||||
|
||||
@@ -103,11 +98,9 @@ Only show consecutive same-group incomplete phases. After selection, mark `[/]`,
|
||||
|
||||
### 1. Identify and Claim Phase
|
||||
|
||||
Review `overview.md`, find workable phases (`[ ]` or `[/]`). Apply parallel selection logic.
|
||||
Act on `status`'s `next` (Parallel Phase Selection above).
|
||||
|
||||
**Once selected:**
|
||||
- If `[ ]`: Update to `[/]` in overview.md
|
||||
- If `[/]`: No change needed
|
||||
**Once selected:** `specs.mjs mark <spec> --phase <N> --to in-progress` (a no-op when it is already `[/]`).
|
||||
|
||||
State: `⚡ [PHASE X: Phase Name] - Marking in-progress and starting`
|
||||
|
||||
@@ -168,7 +161,7 @@ See "After Approval / Session End" section below.
|
||||
| Minor spec gap | Proceed with interpretation, note decision | `> SPEC NOTE: [what was assumed]` |
|
||||
| Major spec conflict | STOP and ask user — do NOT guess on architecture | `SPEC CONFLICT: [details]. Please clarify.` |
|
||||
|
||||
Default: ONE phase per conversation. Small phase (<5 tasks): ask if should continue with next. Large (>40): warn at start.
|
||||
Default: ONE phase per conversation. Small phase (<5 tasks in `status`): ask if should continue with next. Large (>40): warn at start.
|
||||
|
||||
## Templates
|
||||
|
||||
@@ -205,18 +198,17 @@ Sections: Summary (2-3 sentences), Tasks Completed (Y/Z + blocked list), Test Re
|
||||
### After Approval / Session End
|
||||
|
||||
On user "approved":
|
||||
1. Mark `[/]` → `[x]` in overview.md, update phase-X.md status to "Complete"
|
||||
1. `specs.mjs mark <spec> --phase <N> --to done`: overview `[/]` → `[x]` and phase-X.md Status "Complete"
|
||||
2. Show Planny art with completion message
|
||||
3. Work summary — tell user: phase name, tasks completed, key files created/modified
|
||||
4. **Upcoming phases** — read overview.md Phase Checklist, find next 2-3 pending (`[ ]`) phases. For each, peek at its `phase-X.md` for task count and goal. Present a table so the user can assess stopping points and review gates:
|
||||
4. **Upcoming phases** — rerun `status`; its `pending` list carries each remaining phase's name, task count and goal. Present the next 2-3 as a table so the user can assess stopping points and review gates (tighten a goal to one sentence if it runs long):
|
||||
|
||||
| Phase | Tasks | Goal |
|
||||
|-------|-------|------|
|
||||
| Phase X: [Name] | Y | [One-sentence goal] |
|
||||
| Phase X+1: [Name] | Z | [One-sentence goal] |
|
||||
|
||||
5. Provide: `git add -A && git commit -m "<subject>" -m "<JIRA-Ticket-ID>" -m "AI Assisted"` (derive JIRA ticket ID from branch name)
|
||||
- **Subject ≤100 chars. EXACTLY THREE -m flags — no body. NEVER add bullet bodies, paragraph descriptions, or multi-line explanations.** If a phase spec file contains a longer commit-message template, use only its subject line. The diff is the body; the PR is the explanation.
|
||||
5. Write a one-line subject for the phase, then give the user the `command` from `commit-msg.mjs --subject "<subject>" --add-all`. It enforces the format: subject ≤100 chars and EXACTLY THREE -m flags (subject, ticket, `AI Assisted`), no body. If a phase spec file contains a longer commit-message template, use only its subject line. The diff is the body; the PR is the explanation. On Windows PowerShell 5.1 (no `&&`), give `add` and `commit` as two commands instead. Exit 4 `no-ticket`: ask the user for the ticket and rerun with `--ticket`, or show the command with `<JIRA-Ticket-ID>` for them to fill in.
|
||||
6. **If more phases:** "NEXT STEP: Start NEW conversation and run: `/plan2code-3-implement --web`"
|
||||
7. **If final phase:** "NEXT STEP: Start NEW conversation and run: `/plan2code-4-finalize --web`"
|
||||
8. Mention `/plan2code-1b-revise-plan --web` option
|
||||
|
||||
@@ -10,6 +10,14 @@ Critical review specialist -- experienced senior engineer providing independent
|
||||
|
||||
The FIRST thing you do, before anything else in this file — before the scope detection: ask **web console** (browser page, suggested) or **terminal**? Console → run `node "<D>/console.mjs" open --workflow review` before reading (<D>: references/web-console/ beside this SKILL.md — ~/.agents/skills/plan2code-review/references/web-console/ globally — or the dir in ~/.plan2code/console/console-dir), then read <D>/console.md. Scope questions, the findings report and the pick-what-gets-fixed menu all go through it; the report lands on the page as a doc. Switchable anytime. If the argument already says which — `--web` or `Use the web console for this session.` — take it and do not ask; drop the flag. Launched by the dashboard? Its session is already open — resume it (console.md → Launches), then Process. Read inside a build session for its review button? Skip this section — building.md's overrides govern, the session is already running. On the console, a `__stop` action is the person ending the session (console.md → Stop requests); at every session end post `finish` BEFORE `stop`; unless it is a pause, the finish carries `"dashboard": true` (the Back to the dashboard button) and you keep waiting for the press (console.md → Finishing).
|
||||
|
||||
## Scripts
|
||||
|
||||
`<S>` is `scripts/` beside the SKILL.md that loaded this file (`~/.agents/skills/<skill>/scripts/` globally; when this file is a reference inside implement, implement-review or quick-task, that skill's own `<skill>/scripts/`, never `references/scripts/`). Run from the project root. Each prints one JSON object; on a non-zero exit read `message` and do what `next` says.
|
||||
|
||||
- `node "<S>/review-scope.mjs" [--base <branch>]`: the branch-review scope from git (Step 1).
|
||||
- `node "<S>/specs.mjs" list` / `status <spec>`: spec state on disk (Step 2, Session End routing).
|
||||
- `node "<S>/commit-msg.mjs" --subject "<subject>" --files <path> [--files <path> ...]`: the commit command (one `--files` per path).
|
||||
|
||||
## Rules
|
||||
|
||||
- Follow `./AGENTS.md` if it exists -- use all rules and conventions. If missing, warn and proceed with caution.
|
||||
@@ -40,7 +48,7 @@ Three levels -- auto-detected, always respect explicit user override:
|
||||
|
||||
**User override:** If user specifies scope, use exactly that. Never silently narrow.
|
||||
|
||||
**Doc review:** >70% doc files = editorial critique. >70% code = also verify related docs match.
|
||||
**Doc review:** >70% doc files = editorial critique. >70% code = also verify related docs match. (`review-scope.mjs` reports this as `mix`: `docs`, `code` or `mixed`; for a Focused scope, count the named files the same way.)
|
||||
|
||||
## Process
|
||||
|
||||
@@ -54,7 +62,7 @@ Three levels -- auto-detected, always respect explicit user override:
|
||||
|
||||
1. **User prompt** — use it.
|
||||
2. **Conversation context** — recent work? Those artifacts. Scope: `focused`.
|
||||
3. **Git fallback** — `git status`, `git diff`, `git log main..HEAD --oneline`, `git diff --name-only main..HEAD`. Nothing? Ask user.
|
||||
3. **Git fallback** — run `review-scope.mjs`. It compares the branch with its base (`main`, else `master`; `--base` overrides; `base` says which it used) and adds staged, unstaged and untracked changes: `files` (status, lines), `counts`, `commits`, `mix`, `batchByRisk`. `empty: true`? Ask user. Exit 3 `no-base` (no `main` or `master`, or no such `--base`)? Rerun with `--base <trunk>`, asking the user which branch is the trunk if unclear. Exit 3 `not-a-repo`? Ask user which files to review.
|
||||
|
||||
**Classify review type** from context (auto-detect; use `ask_user_question` only if ambiguous):
|
||||
|
||||
@@ -69,13 +77,13 @@ Three levels -- auto-detected, always respect explicit user override:
|
||||
| >70% .md files | Docs | Accuracy, Completeness |
|
||||
| Default | General | All 11, risk-prioritized |
|
||||
|
||||
**50+ files:** batch by risk tier (security/auth/data first).
|
||||
**50+ files** (`batchByRisk`): batch by risk tier (security/auth/data first).
|
||||
|
||||
> 🔬 [Review Mode] [X] files, ~[Y] lines. Type: [type]. Focus: [prioritized dimensions].
|
||||
|
||||
### Step 2: Context
|
||||
|
||||
1. **Specs?** Read `overview.md` + recent `phase-X.md`.
|
||||
1. **Specs?** `specs.mjs list` (it reads gitignored `specs/`, which file search skips), then read `overview.md` + recent `phase-X.md`.
|
||||
2. **AGENTS.md** for conventions.
|
||||
3. **Tech stack** -- check for deprecations, CVEs, breaking changes.
|
||||
4. **Classify:** >70% docs = doc review. >70% code = verify docs match.
|
||||
@@ -167,9 +175,9 @@ Work summary — tell user: scope reviewed, findings count by severity (Critical
|
||||
|
||||
Read references/session-end.md
|
||||
|
||||
> Fallback: route plan2code artifacts (plan/spec docs/phases) on the reviewed feature's own `specs/<feature>/` state to the earliest unmet pipeline stage whose input exists — `PLAN-*` or `overview.md` without `phase-*.md` → `/plan2code-2-document`; unchecked `- [ ]` phase tasks → `/plan2code-3-implement`; all checked → `/plan2code-4-finalize`; archived → complete, summary only. Verify `specs/` on disk with a terminal `ls`/`Get-ChildItem` — it's gitignored, so search tools miss it and an empty result proves nothing. Non-pipeline artifacts (code/PRs/docs/logs) → summary only. Unresolved Criticals → fixing them (H/A/S) is the next step. Ambiguous or multiple candidate specs → ask one targeted question. Output: "Next (NEW conversation): `/plan2code-<step>` — [why + how you know]", appending ` --web` when the routed step offers the web console; else "Review complete -- [summary]."
|
||||
> Fallback: route plan2code artifacts (plan/spec docs/phases) on the reviewed feature's own `specs/<feature>/` state to the earliest unmet pipeline stage whose input exists — `PLAN-*` or `overview.md` without `phase-*.md` → `/plan2code-2-document`; unchecked `- [ ]` phase tasks → `/plan2code-3-implement`; all checked → `/plan2code-4-finalize`; archived → complete, summary only. Read the state with `specs.mjs status <spec>` (gitignored `specs/` defeats search tools). Non-pipeline artifacts (code/PRs/docs/logs) → summary only. Unresolved Criticals → fixing them (H/A/S) is the next step. Ambiguous or multiple candidate specs → ask one targeted question. Output: "Next (NEW conversation): `/plan2code-<step>` — [why + how you know]", appending ` --web` when the routed step offers the web console; else "Review complete -- [summary]."
|
||||
|
||||
- **Commit** (code changes): `git add [files] && git commit -m "fix: [desc]" -m "<JIRA>" -m "AI Assisted"` -- derive JIRA from branch.
|
||||
- **Commit** (code changes): the `command` from `commit-msg.mjs --subject "fix: [desc]" --files <file>` repeated once per fixed file (ticket from the branch; exit 4 `no-ticket`: show it with `<JIRA>` for the user to fill in). On Windows PowerShell 5.1 (no `&&`), give `add` and `commit` as two commands.
|
||||
|
||||
```
|
||||
⋅
|
||||
|
||||
@@ -5,7 +5,7 @@ Principles to reason from, not a lookup table — adapt; when a case doesn't fit
|
||||
cleanly, say what you verified and ask.
|
||||
|
||||
- **Plan2Code Workflow Pipeline:** `/plan2code-1-plan` → `PLAN-*` files · `/plan2code-2-document` → `overview.md` + `phase-*.md` (the "spec docs") in `specs/<feature>/` · `/plan2code-3-implement` → checks off phase tasks, one phase per run · `/plan2code-4-finalize` → archives to `specs--completed/`.
|
||||
- **Find specs (any OS/shell):** `specs/` is gitignored, and search tools (Glob/Grep/project search) skip gitignored paths on many platforms — an empty search result is not evidence either way. Check with a terminal listing: `ls specs/<feature>/` (bash/zsh) · `Get-ChildItem specs/<feature>` (PowerShell) · `dir specs\<feature>` (cmd). Feature dir unknown? List `specs/` first. Command errors? Try another shell's form, then read the expected files directly — file reads see gitignored paths. Conclude "no specs" only after a terminal listing or a failed direct read.
|
||||
- **Find specs (any OS/shell):** `specs/` is gitignored, and search tools (Glob/Grep/project search) skip gitignored paths on many platforms — an empty search result is not evidence either way. Use `node "<S>/specs.mjs" list` (`<S>`: see Review Mode → Scripts) (feature dir unknown, or to see what is archived in `completed`) and `node "<S>/specs.mjs" status <spec>`: they read the disk directly. Its fields map onto the routing below: `planDrafts` with no `overview` · `overview` with no phases · each phase's `tasks.open` · a name in `completed`. If the script cannot run, read the expected files directly — file reads see gitignored paths. Conclude "no specs" only after `list` or a failed direct read.
|
||||
- **Reconcile three signals:** session context (what this conversation was doing — a fresh session may have none), user intent (what they asked reviewed), the disk check above. Disk wins on state; context wins on intent and on disk silence; no context → intent + disk decide.
|
||||
- **plan2code artifact reviewed (a plan, the spec docs, phases) — route on the reviewed feature's own `specs/<feature>/` state (another feature's specs prove nothing here), to the earliest unmet stage, suggesting only a step whose input exists:**
|
||||
- `PLAN-*` without `overview.md` → `/plan2code-2-document`
|
||||
|
||||
@@ -556,8 +556,15 @@ enforces it, so never tell someone to keep asking past it.
|
||||
The person can add folders beside the one the session started in (a shared
|
||||
library, a design folder), from the footer's folder label. Together they are
|
||||
the session's **workspace**: context for every skill run in this console
|
||||
session, each folder addressed by a short `@name`. It outlives dashboard hops;
|
||||
a new console session starts with the original folder alone.
|
||||
session, each folder addressed by a short `@name`. It outlives dashboard hops,
|
||||
and it is remembered: every change is saved to `workspaces.json` beside
|
||||
`looks.json` (never into the project), keyed by the folder the session runs
|
||||
in and then by spec. A session with a spec opens on that spec's list, one with
|
||||
none on the project's; a spec with nothing saved starts as a copy of the
|
||||
project's list. The dashboard's picker swaps the list as the selection moves,
|
||||
and a `specDir` you post mid-run takes the current list with it. There is
|
||||
nothing for you to load: `open` prints the list, and a switch of spec on a
|
||||
resume reaches you as ordinary workspace changes on your next `wait`.
|
||||
|
||||
### What you are told
|
||||
|
||||
@@ -767,7 +774,7 @@ that is what the person is there to download. The finish carries no
|
||||
sees the Trail Footer, and without this their last screen promises a question
|
||||
that is never coming.
|
||||
- Post `run` `pathfinder-chart` (id `map`) when a new map is first written,
|
||||
and `pathfinder-research` (id = the question's file slug) as each research
|
||||
and `pathfinder-research` (id = the question's file slug; on `github`, `q<issue-number>`) as each research
|
||||
subagent reports back, or when you resolve a `research` question yourself
|
||||
(Posting an update → Session meter). Other questions score through their
|
||||
answers, so there is nothing to post for them.
|
||||
@@ -820,7 +827,7 @@ know:
|
||||
| 3, Implementation Summary | Written to `overview.md` as usual; mirror it as a doc (marked `saved`) so the page reader sees it land. |
|
||||
| 4, Documentation Review | The proposed-updates table as a doc, and a `multi` naming the documents to update — every option ticked is "approve", unticked ones are skipped. A `review` works instead when the set is all-or-nothing. |
|
||||
| 5, User Feedback | Optional items, `required: false`: the rating as a `choice` of 1 to 10 or a `text`, the three reasons as `text`. The submit-to-maintainer consent is a `confirm`. |
|
||||
| 6, Spec Cleanup | A `confirm` before moving anything, the archive paths in `consequences`. |
|
||||
| 6, Spec Cleanup | A `confirm` before moving anything, the archive paths in `consequences`, and a line that the spec's remembered workspace folders are forgotten too (`console.mjs forget --spec specs/<feature>` after the move). |
|
||||
|
||||
Pass `--spec specs/<feature>` to `open`, or post `specDir` once you know it.
|
||||
Stopping mid-finalize loses nothing
|
||||
|
||||
@@ -41,6 +41,7 @@ import {
|
||||
die,
|
||||
ensureDir,
|
||||
fileStamp,
|
||||
forgetWorkspace,
|
||||
handOff,
|
||||
handleFile,
|
||||
healthOk,
|
||||
@@ -65,6 +66,7 @@ import {
|
||||
readLedger,
|
||||
readWorkspace,
|
||||
reapHandles,
|
||||
rememberedWorkspace,
|
||||
remoteWarning,
|
||||
removeScratch,
|
||||
removeSessions,
|
||||
@@ -73,6 +75,7 @@ import {
|
||||
SESSION_MAX_AGE_MS,
|
||||
sessionDir,
|
||||
sleepSync,
|
||||
specKey,
|
||||
staleScratch,
|
||||
staleSessions,
|
||||
sweepUploads,
|
||||
@@ -317,7 +320,7 @@ async function cmdOpen() {
|
||||
if (launched) appendLedger(dir, { kind: "launch", id: nextLaunchId(readLedger(dir)), workflow: state.workflow });
|
||||
for (const line of ledgerFromPost(dir, openRun, openIssue, state.workflow)) appendLedger(dir, line);
|
||||
} catch {}
|
||||
const workspace = workspaceOnOpen(dir, worktree);
|
||||
const workspace = workspaceOnOpen(dir, worktree, state.specDir);
|
||||
|
||||
// Month-old sessions and scratch files: listed before the print so the
|
||||
// agent can see what went, removed after it so the page waits for nothing.
|
||||
@@ -403,10 +406,11 @@ async function cmdOpen() {
|
||||
* The workspace as `open` hands it to the agent, and the cursor seeded to
|
||||
* match: the agent now has the whole list, so no change up to here is owed.
|
||||
* Read-only on workspace.json, which only the server writes; on a fresh
|
||||
* session the server has not made it yet, so the original folder stands in.
|
||||
* session the server has not made it yet, so what was remembered for this
|
||||
* folder and spec stands in, the same list the server is about to make.
|
||||
*/
|
||||
function workspaceOnOpen(dir, worktree) {
|
||||
const ws = readWorkspace(dir) || initialWorkspace(worktree);
|
||||
function workspaceOnOpen(dir, worktree, specDir) {
|
||||
const ws = readWorkspace(dir) || initialWorkspace(worktree, rememberedWorkspace(worktree, specDir).entry);
|
||||
const missing = ws.folders.filter((f) => !isFolder(f.path)).map((f) => f.id);
|
||||
try {
|
||||
writeWorkspaceCursor(dir, ws.version || 0);
|
||||
@@ -946,6 +950,18 @@ function realNearest(p) {
|
||||
return path.join(fs.realpathSync(existing), path.relative(existing, p));
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------- forget */
|
||||
|
||||
// Drop the folder list remembered for one spec (Finalize, once the spec is
|
||||
// archived). The project's own list and every other spec's are untouched.
|
||||
function cmdForget() {
|
||||
if (typeof args.spec !== "string" || !args.spec.trim()) die("forget needs --spec specs/<idea>", 2);
|
||||
let spec = specKey(args.spec);
|
||||
if (/\.md$/i.test(spec)) spec = spec.slice(0, spec.lastIndexOf("/"));
|
||||
const worktree = repoRoots().worktree;
|
||||
print({ ok: true, spec, forgot: forgetWorkspace(worktree, spec) });
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------- help */
|
||||
|
||||
function cmdHelp() {
|
||||
@@ -961,7 +977,8 @@ port, and the filesystem as transport; this CLI is the whole agent surface.
|
||||
first post. --file is optional, and --title defaults to the
|
||||
project's folder name. Also prints workspace: { folders: [{ name,
|
||||
path, description?, original? }], missing? }, the folders this
|
||||
console session reads as context, addressed as @name.
|
||||
console session reads as context, addressed as @name. The list is
|
||||
remembered per folder and spec in workspaces.json beside looks.json.
|
||||
post --session <sid> --file <patch.json>
|
||||
Merge a patch into the session. Prints terminalLine while the
|
||||
server is live. Exit 3 = rejected; stderr says why. A patch may
|
||||
@@ -988,6 +1005,10 @@ port, and the filesystem as transport; this CLI is the whole agent surface.
|
||||
Copy a cited note attachment into specs/<idea>/attachments/. Prints
|
||||
{ ok, path, link, image, reused }; exit 2 = bad usage, 3 = refused or
|
||||
missing. Paste link as it is.
|
||||
forget --spec specs/<idea>
|
||||
Drop the workspace folders remembered for that spec, in this
|
||||
folder (Finalize, after archiving it). Prints { ok, spec, forgot };
|
||||
forgot is false when nothing was saved. Exit 2 = bad usage.
|
||||
status [--session <sid>] [--all]
|
||||
One session, or every session belonging to this project.
|
||||
stop --session <sid> | --all
|
||||
@@ -1206,6 +1227,7 @@ const COMMANDS = {
|
||||
wait: cmdWait,
|
||||
chat: cmdChat,
|
||||
keep: cmdKeep,
|
||||
forget: cmdForget,
|
||||
status: cmdStatus,
|
||||
stop: cmdStop,
|
||||
help: cmdHelp,
|
||||
|
||||
@@ -178,8 +178,8 @@ function lockStale(lock) {
|
||||
// Run fn while holding the session's state lock, and release it however fn
|
||||
// ends. fn must not call process.exit(): the release would never run, and the
|
||||
// next writer would wait out the stale age.
|
||||
export function withStateLock(dir, fn) {
|
||||
const lock = path.join(dir, STATE_LOCK_FILE);
|
||||
export function withStateLock(dir, fn, lockName = STATE_LOCK_FILE) {
|
||||
const lock = path.join(dir, lockName);
|
||||
const deadline = Date.now() + LOCK_WAIT_MS;
|
||||
let fd = null;
|
||||
for (let attempt = 0; fd === null; attempt++) {
|
||||
@@ -188,7 +188,7 @@ export function withStateLock(dir, fn) {
|
||||
} catch (err) {
|
||||
// EPERM / EACCES: on Windows, a lock being deleted still blocks a create.
|
||||
if (!["EEXIST", "EPERM", "EACCES", "EBUSY"].includes(err.code)) throw err;
|
||||
if (Date.now() > deadline) throw new Error("state.json is busy with another writer; try again");
|
||||
if (Date.now() > deadline) throw new Error(`${lockName.replace(/.lock$/, "")} is busy with another writer; try again`);
|
||||
if (err.code === "EEXIST" && lockStale(lock)) {
|
||||
try {
|
||||
fs.rmSync(lock, { force: true });
|
||||
@@ -487,8 +487,9 @@ export async function removeSessions(sessionsDir, sids) {
|
||||
}
|
||||
|
||||
// The console folder's own files that no sweep may ever remove: the person's
|
||||
// looks and the pointer to this console's directory.
|
||||
export const PROTECTED_CONSOLE_FILES = new Set(["looks.json", "console-dir"]);
|
||||
// looks, the folders remembered per project and spec, and the pointer to
|
||||
// this console's directory.
|
||||
export const PROTECTED_CONSOLE_FILES = new Set(["looks.json", "workspaces.json", "console-dir"]);
|
||||
|
||||
function isScratchName(name) {
|
||||
return (
|
||||
@@ -1619,17 +1620,125 @@ export function readWorkspace(dir) {
|
||||
return readJson(path.join(dir, WORKSPACE_FILE), null);
|
||||
}
|
||||
|
||||
// A fresh workspace: just the original folder, named after itself.
|
||||
export function initialWorkspace(worktree) {
|
||||
// A fresh workspace: the original folder, named after itself, plus whatever
|
||||
// was remembered for this folder and spec (rememberedWorkspace() below).
|
||||
export function initialWorkspace(worktree, remembered = null) {
|
||||
const original = { id: "f0", path: worktree, name: defaultName(worktree), description: "", original: true };
|
||||
if (remembered && remembered.original) {
|
||||
if (remembered.original.name) original.name = remembered.original.name;
|
||||
if (remembered.original.description) original.description = remembered.original.description;
|
||||
}
|
||||
const added = ((remembered && remembered.folders) || []).map((f, i) => ({
|
||||
id: "f" + (i + 1),
|
||||
path: f.path,
|
||||
name: f.name,
|
||||
description: f.description || "",
|
||||
...(f.nested ? { nested: true } : {}),
|
||||
}));
|
||||
return { version: 0, folders: [original, ...added], missing: [], changes: [], remote: "" };
|
||||
}
|
||||
|
||||
/* ------------------------------------------------ remembered workspaces */
|
||||
|
||||
// The folder list outlives the console session: one file for the person,
|
||||
// beside looks.json, keyed by the folder a session runs in and then by spec.
|
||||
// Never under specs/: the paths are this machine's, and the server never
|
||||
// writes into a project.
|
||||
//
|
||||
// { "projects": { "<folded worktree>": {
|
||||
// "path": "<worktree>",
|
||||
// "project": { original, folders, at }, // no spec picked
|
||||
// "specs": { "specs/<name>": { original, folders, at } } } } }
|
||||
//
|
||||
// `original` holds the first folder's name and description only (its path is
|
||||
// always the session's own); `folders` the added ones as { path, name,
|
||||
// description, nested? }. Two writers, the server on every change and
|
||||
// `console.mjs forget`, each a read-modify-write of one key.
|
||||
export const WORKSPACES_FILE = path.join(HOME_DIR, "workspaces.json");
|
||||
|
||||
const foldKey = (p) => {
|
||||
const resolved = path.resolve(String(p || ""));
|
||||
return process.platform === "win32" || process.platform === "darwin" ? resolved.toLowerCase() : resolved;
|
||||
};
|
||||
|
||||
// `specs/<name>` with forward slashes and no trailing slash, or "" for none.
|
||||
export function specKey(specDir) {
|
||||
return String(specDir || "")
|
||||
.trim()
|
||||
.replace(/\\/g, "/")
|
||||
.replace(/^\.\//, "")
|
||||
.replace(/\/+$/, "");
|
||||
}
|
||||
|
||||
function readStore() {
|
||||
const saved = readJson(WORKSPACES_FILE, null);
|
||||
return saved && typeof saved.projects === "object" && saved.projects ? saved : { projects: {} };
|
||||
}
|
||||
|
||||
/**
|
||||
* What was remembered for this folder and spec: `{ entry, from }`, where
|
||||
* `from` is "spec" when the spec has its own list, "project" when it falls
|
||||
* back to the project's (a spec's list starts as a copy of it), and null
|
||||
* when nothing was ever saved.
|
||||
*/
|
||||
export function rememberedWorkspace(worktree, specDir) {
|
||||
const project = readStore().projects[foldKey(worktree)];
|
||||
if (!project) return { entry: null, from: null };
|
||||
const spec = specKey(specDir);
|
||||
if (spec && project.specs && project.specs[spec]) return { entry: project.specs[spec], from: "spec" };
|
||||
return project.project ? { entry: project.project, from: "project" } : { entry: null, from: null };
|
||||
}
|
||||
|
||||
// The workspace's folders as the store keeps them.
|
||||
export function rememberable(ws) {
|
||||
const folders = (ws && ws.folders) || [];
|
||||
const first = folders.find((f) => f.original) || {};
|
||||
return {
|
||||
version: 0,
|
||||
folders: [{ id: "f0", path: worktree, name: defaultName(worktree), description: "", original: true }],
|
||||
missing: [],
|
||||
changes: [],
|
||||
remote: "",
|
||||
original: { name: first.name || "", description: first.description || "" },
|
||||
folders: folders
|
||||
.filter((f) => !f.original)
|
||||
.map((f) => ({ path: f.path, name: f.name, description: f.description || "", ...(f.nested ? { nested: true } : {}) })),
|
||||
at: nowIso(),
|
||||
};
|
||||
}
|
||||
|
||||
// Every server and `console.mjs forget` writes the one file, so each
|
||||
// read-modify-write holds this lock beside it.
|
||||
const WORKSPACES_LOCK = "workspaces.json.lock";
|
||||
|
||||
// Save the list for this folder and spec ("" for the project's own).
|
||||
export function rememberWorkspace(worktree, specDir, ws) {
|
||||
ensureDir(path.dirname(WORKSPACES_FILE));
|
||||
withStateLock(path.dirname(WORKSPACES_FILE), () => saveRemembered(worktree, specDir, ws), WORKSPACES_LOCK);
|
||||
}
|
||||
|
||||
function saveRemembered(worktree, specDir, ws) {
|
||||
const store = readStore();
|
||||
const key = foldKey(worktree);
|
||||
const project = store.projects[key] || { path: path.resolve(worktree) };
|
||||
const spec = specKey(specDir);
|
||||
if (spec) project.specs = { ...(project.specs || {}), [spec]: rememberable(ws) };
|
||||
else project.project = rememberable(ws);
|
||||
store.projects[key] = project;
|
||||
writeJsonAtomic(WORKSPACES_FILE, store);
|
||||
}
|
||||
|
||||
// Drop one spec's list (Finalize, once the spec is archived). True when there was one.
|
||||
export function forgetWorkspace(worktree, specDir) {
|
||||
const spec = specKey(specDir);
|
||||
if (!spec || !fs.existsSync(WORKSPACES_FILE)) return false;
|
||||
return withStateLock(path.dirname(WORKSPACES_FILE), () => dropRemembered(worktree, spec), WORKSPACES_LOCK);
|
||||
}
|
||||
|
||||
function dropRemembered(worktree, spec) {
|
||||
const store = readStore();
|
||||
const project = store.projects[foldKey(worktree)];
|
||||
if (!spec || !project || !project.specs || !project.specs[spec]) return false;
|
||||
delete project.specs[spec];
|
||||
writeJsonAtomic(WORKSPACES_FILE, store);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Single-writer rule: only server.mjs may call this.
|
||||
export function writeWorkspace(dir, ws) {
|
||||
return writeJsonAtomic(path.join(dir, WORKSPACE_FILE), ws);
|
||||
|
||||
@@ -2505,6 +2505,9 @@ a.icon-btn { box-sizing: border-box; text-decoration: none; }
|
||||
actions stay put. */
|
||||
.modal.workspace { max-width: 680px; }
|
||||
.modal.workspace[open] { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
|
||||
.workspace .modal-blurb { margin-bottom: 6px; }
|
||||
.workspace-scope { margin: 0 0 16px; color: var(--ink-3, var(--ink-2)); font-size: 12.5px; }
|
||||
|
||||
.workspace-list {
|
||||
list-style: none; margin: 0; padding: 0;
|
||||
display: grid; gap: 12px;
|
||||
|
||||
@@ -2542,6 +2542,7 @@ function renderDashboard(main) {
|
||||
const specs = specList();
|
||||
if (specs.length) wrap.appendChild(renderSpecPicker(specs));
|
||||
wrap.appendChild(hideUnavailableToggle());
|
||||
if (!local.launching && !launchScoping) syncWorkspaceScope();
|
||||
|
||||
// "Unavailable" is the scan's verdict for the selected spec, not the
|
||||
// momentary greying while a launch is in flight or the server is away, so
|
||||
@@ -2963,6 +2964,11 @@ async function launchSkill(entry) {
|
||||
// cards that take no spec (utilities, setup) launch untargeted even while
|
||||
// a spec is selected.
|
||||
if (target) action.spec = target.dir;
|
||||
// The skill opens on the folders remembered for what it was launched for.
|
||||
// Held until the launch is in flight: the swap's own frame re-renders the
|
||||
// dashboard, which would otherwise sync back to the picker's spec.
|
||||
launchScoping = true;
|
||||
await syncWorkspaceScope(target ? target.dir : "");
|
||||
try {
|
||||
const res = await fetch("/submit", {
|
||||
method: "POST",
|
||||
@@ -2973,6 +2979,7 @@ async function launchSkill(entry) {
|
||||
}),
|
||||
});
|
||||
if (res.status === 409) {
|
||||
launchScoping = false;
|
||||
pendingResult = true;
|
||||
banner("Your last pick is still being picked up. One moment.", "info");
|
||||
return;
|
||||
@@ -2980,10 +2987,12 @@ async function launchSkill(entry) {
|
||||
if (!res.ok) throw new Error(String(res.status));
|
||||
sound("startSkill");
|
||||
local.launching = { skill: entry.skill, title: entry.title, at: Date.now() };
|
||||
launchScoping = false;
|
||||
pendingResult = true;
|
||||
save();
|
||||
render();
|
||||
} catch {
|
||||
launchScoping = false;
|
||||
banner("That did not go through. Nothing was lost; try again.", "warn");
|
||||
}
|
||||
}
|
||||
@@ -5854,6 +5863,32 @@ async function postJson(url, body) {
|
||||
}
|
||||
}
|
||||
|
||||
/* The workspace follows the dashboard's picker: the folders remembered for
|
||||
the selected spec, or the project's own under "Start from scratch". The
|
||||
server swaps the list and remembers every change after it. */
|
||||
let scopeAsked = null;
|
||||
// True from a launch's scope sync until its send has gone (or failed).
|
||||
let launchScoping = false;
|
||||
async function syncWorkspaceScope(spec) {
|
||||
if (!S || S.workflow !== "dashboard" || gone || !wsFrame) return;
|
||||
const want = spec === undefined ? (selSpec() && selSpec().dir) || "" : spec;
|
||||
if ((wsFrame.scope || "") === want || scopeAsked === want) return;
|
||||
scopeAsked = want;
|
||||
const { status, body } = await postJson("/workspace/scope", { spec: want });
|
||||
if (status === 200 && body && Array.isArray(body.folders)) wsFrame = { ...wsFrame, ...body };
|
||||
scopeAsked = null;
|
||||
if ($("workspace-modal").open) renderWorkspace();
|
||||
}
|
||||
|
||||
// The dialog's "Remembered for" line: whose list this is.
|
||||
function workspaceScopeText() {
|
||||
const scope = (wsFrame && wsFrame.scope) || "";
|
||||
if (!scope) return "Remembered for this project, so your next console session here starts with these folders.";
|
||||
const spec = specList().find((s) => s.dir === scope);
|
||||
const name = spec ? spec.name : scope.split("/").pop();
|
||||
return `Remembered for the ${name} spec, and loaded again whenever it is picked.`;
|
||||
}
|
||||
|
||||
const NAME_RULE = "Names use lowercase letters, numbers and hyphens.";
|
||||
const BROWSE_UNAVAILABLE = "Browse isn't available here — type or paste the path.";
|
||||
// The folder whose Remove is waiting on its inline confirm, by id.
|
||||
@@ -5893,6 +5928,7 @@ function renderWorkspace() {
|
||||
}
|
||||
folders.forEach((f, i) => paintWorkspaceRow(list.children[i], f));
|
||||
$("workspace-browse").hidden = Boolean(wsFrame && wsFrame.remote);
|
||||
$("workspace-scope").textContent = workspaceScopeText();
|
||||
}
|
||||
|
||||
function workspaceRow(f) {
|
||||
|
||||
@@ -833,10 +833,28 @@
|
||||
Click the folder name in the middle of the bottom bar. It shows your
|
||||
folder's name and branch, such as <strong>shop · main</strong>, and
|
||||
<strong>shop + 2 folders · main</strong> once you have added some.
|
||||
The workspace lasts for this console session only: it carries across
|
||||
steps you start from the dashboard, and a new console session starts
|
||||
with just the folder you started in.
|
||||
It carries across steps you start from the dashboard.
|
||||
</p>
|
||||
<h4>Remembered for next time</h4>
|
||||
<ul>
|
||||
<li>
|
||||
Every change is saved as you make it, so the next console session in
|
||||
this folder starts with the same folders.
|
||||
</li>
|
||||
<li>
|
||||
Each spec keeps its own list. The first time you pick a spec on the
|
||||
dashboard it starts as a copy of the project's list (the one shown
|
||||
under <strong>Start from scratch</strong>), and after that the two
|
||||
are separate. Picking a spec loads its list; the line under the
|
||||
dialog's title says whose list you are looking at.
|
||||
</li>
|
||||
<li>
|
||||
The lists live in <code>workspaces.json</code> in your own
|
||||
Plan2Code settings folder, beside your look and feel, never in the
|
||||
project. Finalize offers to forget a spec's list when it archives the
|
||||
spec.
|
||||
</li>
|
||||
</ul>
|
||||
<h4>Adding a folder</h4>
|
||||
<ul>
|
||||
<li>
|
||||
@@ -1363,9 +1381,10 @@
|
||||
<h4>What it counts</h4>
|
||||
<p>
|
||||
Each step you run here adds points: a plan or a set of documents
|
||||
weighs more than a single answered question, and a built phase more
|
||||
still, by how many tasks it completed: a big phase adds more than a
|
||||
small one. Every two questions you answer add a point too, so a long
|
||||
weighs more than a quick task, and a built phase more still, by how
|
||||
many tasks it completed: a big phase adds more than a small one.
|
||||
Every two questions you answer within one step add a point too
|
||||
(rounded down, so a single answer adds nothing), so a long
|
||||
back-and-forth counts for more than a short one. Click the ring to see the count and a list of each step that added
|
||||
points, with what it added. It is a rule of thumb, not a
|
||||
reading of Plan2Code's real memory: long sessions tend to make it
|
||||
@@ -2003,6 +2022,7 @@
|
||||
The folders the agent uses as context this session. It reads the extra ones for
|
||||
reference and only changes them if you ask.
|
||||
</p>
|
||||
<p class="workspace-scope" id="workspace-scope"></p>
|
||||
<ul class="workspace-list" id="workspace-list"></ul>
|
||||
<div class="workspace-add">
|
||||
<label class="workspace-add-label" for="workspace-path">Add a folder</label>
|
||||
|
||||
@@ -45,7 +45,10 @@ import {
|
||||
readLedger,
|
||||
readOverview,
|
||||
readWorkspace,
|
||||
rememberWorkspace,
|
||||
rememberedWorkspace,
|
||||
remoteWarning,
|
||||
specKey,
|
||||
typedCount,
|
||||
withStateLock,
|
||||
writeJsonAtomic,
|
||||
@@ -326,7 +329,9 @@ function workspaceNow() {
|
||||
return ws;
|
||||
}
|
||||
const root = sessionWorktree();
|
||||
const fresh = { ...initialWorkspace(root || PROJECT), remote: remoteWarning().remote || "" };
|
||||
const scope = specKey(stateNow?.specDir);
|
||||
const remembered = root ? rememberedWorkspace(root, scope).entry : null;
|
||||
const fresh = { ...initialWorkspace(root || PROJECT, remembered), scope, remote: remoteWarning().remote || "" };
|
||||
// There but unreadable for now (a scanner's lock): never written over, and
|
||||
// never cached, so the next call reads it again.
|
||||
if (stamp) return workspaceSeen.ws || fresh;
|
||||
@@ -347,13 +352,87 @@ function saveWorkspace(ws) {
|
||||
|
||||
// One change: a new version, an entry in the change log the agent is handed,
|
||||
// the file, and every open page.
|
||||
function bumpWorkspace(ws, change) {
|
||||
function bumpWorkspace(ws, change, { remember = true } = {}) {
|
||||
ws.version = (ws.version || 0) + 1;
|
||||
ws.changes = [...(ws.changes || []), { ...change, version: ws.version }];
|
||||
saveWorkspace(ws);
|
||||
// Remembered for the next console session too. A folder gone missing or
|
||||
// found again is not a change of mind, so it is not saved.
|
||||
if (remember) rememberNow(ws);
|
||||
pushState();
|
||||
}
|
||||
|
||||
function rememberNow(ws) {
|
||||
const root = sessionWorktree();
|
||||
if (!root) return;
|
||||
try {
|
||||
rememberWorkspace(root, ws.scope || "", ws);
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Point the workspace at another spec ("" for the project's own list) and
|
||||
* swap in what was remembered there, logging each difference as a change so
|
||||
* the agent's cursor stays truthful. A spec with nothing saved starts from
|
||||
* the project's list (`seed: "project"`, the dashboard picker) or keeps the
|
||||
* list it has and saves it as the spec's (`seed: "current"`, a spec created
|
||||
* mid-run). Folders keep their ids when their path stays.
|
||||
*/
|
||||
function setScope(ws, spec, seed = "project") {
|
||||
const root = sessionWorktree();
|
||||
const next = specKey(spec);
|
||||
if (!root || (ws.scope || "") === next) return false;
|
||||
const found = rememberedWorkspace(root, next);
|
||||
ws.scope = next;
|
||||
if (next && found.from !== "spec" && seed === "current") {
|
||||
saveWorkspace(ws);
|
||||
rememberNow(ws);
|
||||
pushState();
|
||||
return true;
|
||||
}
|
||||
const want = initialWorkspace(root, found.entry).folders;
|
||||
const byPath = new Map(ws.folders.map((f) => [foldPath(path.resolve(f.path)), f]));
|
||||
const kept = new Set();
|
||||
const folders = [];
|
||||
const changes = [];
|
||||
for (const w of want) {
|
||||
const have = w.original ? ws.folders.find((f) => f.original) : byPath.get(foldPath(path.resolve(w.path)));
|
||||
if (!have) {
|
||||
folders.push({ ...w, id: "pending" });
|
||||
changes.push({ kind: "added", name: w.name, path: w.path, description: w.description });
|
||||
continue;
|
||||
}
|
||||
kept.add(have);
|
||||
if (have.name !== w.name) changes.push({ kind: "renamed", from: have.name, name: w.name, path: have.path });
|
||||
if ((have.description || "") !== (w.description || "")) {
|
||||
changes.push({ kind: "described", name: w.name, path: have.path, description: w.description || "" });
|
||||
}
|
||||
folders.push({ ...have, name: w.name, description: w.description || "" });
|
||||
}
|
||||
for (const f of ws.folders) {
|
||||
if (!kept.has(f)) changes.unshift({ kind: "removed", name: f.name, path: f.path });
|
||||
}
|
||||
ws.folders = folders.filter((f) => f.id !== "pending");
|
||||
for (const f of folders.filter((f) => f.id === "pending")) ws.folders.push({ ...f, id: nextFolderId(ws) });
|
||||
ws.missing = (ws.missing || []).filter((id) => ws.folders.some((f) => f.id === id));
|
||||
if (!changes.length) {
|
||||
saveWorkspace(ws);
|
||||
pushState();
|
||||
}
|
||||
for (const c of changes) bumpWorkspace(ws, c, { remember: false });
|
||||
checkFolders(ws);
|
||||
return true;
|
||||
}
|
||||
|
||||
// A spec posted mid-run (Pathfinder or Plan making its folder, a skill that
|
||||
// learns its spec late) takes the workspace with it.
|
||||
function followSpecDir(state) {
|
||||
const spec = specKey(state && state.specDir);
|
||||
if (!spec || !fileStamp(WORKSPACE_PATH)) return;
|
||||
const ws = workspaceNow();
|
||||
if ((ws.scope || "") !== spec) setScope(ws, spec, "current");
|
||||
}
|
||||
|
||||
function isFolder(p) {
|
||||
try {
|
||||
return fs.statSync(p).isDirectory();
|
||||
@@ -370,10 +449,10 @@ function checkFolders(ws) {
|
||||
const marked = ws.missing.includes(f.id);
|
||||
if (!there && !marked) {
|
||||
ws.missing = [...ws.missing, f.id];
|
||||
bumpWorkspace(ws, { kind: "missing", name: f.name, path: f.path });
|
||||
bumpWorkspace(ws, { kind: "missing", name: f.name, path: f.path }, { remember: false });
|
||||
} else if (there && marked) {
|
||||
ws.missing = ws.missing.filter((id) => id !== f.id);
|
||||
bumpWorkspace(ws, { kind: "found", name: f.name, path: f.path });
|
||||
bumpWorkspace(ws, { kind: "found", name: f.name, path: f.path }, { remember: false });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -402,8 +481,8 @@ function folderIssues(entries) {
|
||||
}
|
||||
|
||||
function workspaceView() {
|
||||
const { folders, missing, remote } = workspaceNow();
|
||||
return { folders, missing: missing || [], remote: remote || "", issues: folderIssues(ledgerEntries()) };
|
||||
const { folders, missing, remote, scope } = workspaceNow();
|
||||
return { folders, missing: missing || [], remote: remote || "", scope: scope || "", issues: folderIssues(ledgerEntries()) };
|
||||
}
|
||||
|
||||
// Whether child sits strictly under parent.
|
||||
@@ -492,6 +571,7 @@ function bootWorkspace() {
|
||||
saveWorkspace(ws);
|
||||
}
|
||||
checkFolders(ws);
|
||||
followSpecDir(stateNow);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1403,6 +1483,24 @@ const server = http.createServer((req, res) => {
|
||||
});
|
||||
}
|
||||
|
||||
// Which list the workspace is: a spec's, or the project's (`spec` empty).
|
||||
// The dashboard's picker sends it as the selection moves and before a
|
||||
// launch, so a skill opens on the list of the spec it was launched for.
|
||||
if (pathname === "/workspace/scope" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
return readBody(req, (err, body) => {
|
||||
if (err || !body || typeof body !== "object" || Array.isArray(body)) return json(res, 400, { error: "bad" });
|
||||
const spec = typeof body.spec === "string" ? body.spec : "";
|
||||
if (spec && !/^specs\/[^/\\]+$/.test(specKey(spec))) return json(res, 400, { reason: "bad-spec" });
|
||||
try {
|
||||
setScope(workspaceNow(), spec, "project");
|
||||
} catch (e) {
|
||||
return json(res, 500, { error: String(e.message) });
|
||||
}
|
||||
return json(res, 200, workspaceView());
|
||||
});
|
||||
}
|
||||
|
||||
// Only ever returns a path: the page then adds it through /workspace/add.
|
||||
if (pathname === "/workspace/browse" && req.method === "POST") {
|
||||
if (!originOk(req, port)) return json(res, 403, { error: "bad origin" });
|
||||
@@ -1561,6 +1659,9 @@ function checkState() {
|
||||
try {
|
||||
ensureConversation(parsed);
|
||||
} catch {}
|
||||
try {
|
||||
followSpecDir(parsed);
|
||||
} catch {}
|
||||
pushState();
|
||||
}
|
||||
lastStateStamp = stamp;
|
||||
|
||||
@@ -17,6 +17,6 @@
|
||||
"url": "https://github.com/jparkerweb/plan2code"
|
||||
},
|
||||
"homepage": "https://github.com/jparkerweb/plan2code",
|
||||
"releaseDate": "2026-10-02",
|
||||
"releaseDate": "2026-10-04",
|
||||
"mode": "utility"
|
||||
}
|
||||
Reference in new issue
Block a user