pi-anchorloop 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/README.zh-TW.md +1 -1
- package/hooks/validators/durable_validator.py +1 -1
- package/package.json +1 -1
- package/pi/book.ts +73 -10
- package/pi/second-thought.ts +5 -15
- package/pi/support/book.ts +16 -0
- package/pi/support/phases.ts +5 -4
- package/pi/support/validators.ts +1 -1
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ shared grilling · domain-modeling · human-feedback · agent-terse
|
|
|
28
28
|
| `pi/book.ts` | The loop book. The first `todo` create or `kind` call opens a loop; task records need the `todo` tool of [`@juicesharp/rpiv-todo`](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo#readme) (its `tool_result` details `{tasks, nextId}` and `rpiv-todo-state` entries). The agent declares only what the extension cannot observe with `anchorloop_stage`: `kind` (`quick`, `inline`, `reviewed`, `durable`, with an intent and the anchor command), `verify` (a check not run in bash), `fresh-read`, `friction` (`tried`, `found`, `led_by`), `reflect`, `skip`, `back`, `close`, and the query `read`. Everything else is read from evidence: production edits (a write or edit in any git repo, outside its `scratch/` and `docs/specs/`; a linked child's edits and a successful `git merge`, `cherry-pick`, or `pull` count too), the exit code of the bash call that ran the anchor command (failed-then-passed runs become retry pairs), reviewer `Blocking: P0=<n> P1=<m>` counts, summaries of `docs/specs/*/` artifacts as they are edited, and a returned subagent that Jev judges to have been a fresh-context read of the spec. A phase machine over that evidence gives each kind a fixed sequence (`quick` act → check; `inline` anchor → act → verify; `reviewed` adds review; `durable` adds decide → grill → spec → read → approve → design; every kind ends with reflect → close), and `read` shows `<kind> · phase <current> ✓ → <next> (missing: …) · skipped: …`. A phase that starts before an earlier one is complete warns once in one line and names the `skip` escape; phases regress when evidence changes or on `back`. The book also records each todo with its `anchor`, `ref` (`<path>#<heading>`, resolved to line ranges), and `followup` metadata. One YAML book per open loop lives under `~/.pi/agent/anchorloop/books/` (`ANCHORLOOP_BOOKS_DIR` overrides it; empty project and `agents/` directories are removed), subagent books under `agents/` (a child that closes keeps its book for the main session); `session_start` sweeps books whose session is gone or that have not changed in 7 days. `close` lists every phase as done, skipped, or auto-skipped and never refuses over phases or friction, only while a pending or in-progress todo lacks `metadata.followup` (a ticket id, `memory`, or `drop — <reason>`). |
|
|
29
29
|
| `pi/anchor-gate.ts` | Inside an open loop, shows one warning line when `write` or `edit` starts the `act` phase while an earlier phase of the loop kind is incomplete: no anchor (`anchor` on the `kind` call, a `Reality anchor:` line, or a skip), and in a `durable` loop a missing decision, spec, fresh read, approval, or design, read from the `docs/specs/<folder>/` files (found from the book, the intent, or a todo `ref`). It warns again only when a new phase goes missing; the call still goes through. Outside a loop and in `quick` loops it stays silent. `.md`, `.txt`, and `.html` files, `scratch/`, `docs/specs/`, and temp files outside the project pass silently. Edits made through `bash` are not checked. |
|
|
30
30
|
| `pi/decision-tool.ts` | The `anchorloop_decision` tool appends single-line, spreadsheet-safe rows to a decision trail TSV, or a `start` row when a run picks up another run's trail. |
|
|
31
|
-
| `pi/second-thought.ts` | Inside an open loop, asks Jev (TypeSafe's typed-decision model, through pi's classifier registry) to check the phase machine when a run settles and the loop book gained an entry since the last judgment, and at a `close` declaration. The program computes the next phase from the book; Jev sees the kind, intent, anchor, diff summary (≤1200 chars), `phase` (current, next, missing), verify state, open todos, the task list, and friction (a child's under its name), and judges only whether
|
|
31
|
+
| `pi/second-thought.ts` | Inside an open loop, asks Jev (TypeSafe's typed-decision model, through pi's classifier registry) to check the phase machine when a run settles and the loop book gained an entry since the last judgment, and at a `close` declaration. The program computes the next phase from the book; Jev sees the kind, intent, anchor, diff summary (≤1200 chars), `phase` (current, next, missing), verify state, open todos, the task list, and friction (a child's under its name), and judges only whether to `advance`, go `back`, or `ask-user`, plus `done`, the review tier still needed, and quality; phase completion comes from the program's evidence alone. The one-line advisory leads with `next → <phase>`; a retry pair with no friction entry adds a `friction` hint. The run continues once, only when Jev agrees to advance and the next phase is a verify, review, or fix; an advisory identical to the last one is not repeated, and a `full` rating after a clean review that follows the last change shows a note instead of a recheck. A run that called `MonitorCreate`, `LoopCreate`, `goal_wait`, or a `subagent` tool is waiting and is not judged. Without a TypeSafe key it does nothing, and outside a loop it never runs. In a subagent session (`PI_SUBAGENT_ID` from pi-herdr-agents, or `PI_SUBAGENT_CHILD` from pi-subagents) it registers nothing, since the agent that spawned it judges the result. |
|
|
32
32
|
| `pi/validate-tool-use.ts` | After each `write` or `edit`, validates the file in-process (`pi/support/validators.ts`, a port of `hooks/validators/`) and appends suggestions for `SKILL.md`, instruction files (`AGENTS.md`, `CLAUDE.md`, `GEMINI.md`, `rules/`), and `docs/specs/` artifacts. Needs no Python; the Python validators in `hooks/` remain for `validate_all.py` and the parity test. |
|
|
33
33
|
| `pi/ttsr.ts` | A port of oh-my-pi's Time Traveling Stream Rules. A Markdown rule in `~/.pi/agent/rules/` or `<project>/.pi/rules/` whose frontmatter has a `condition` regex is watched during the run. A match in streamed assistant text aborts the response, drops it, and retries with the rule injected; a match in tool arguments (the command for `bash`, the new text for `write` and `edit`) blocks the call with the rule as its reason. Frontmatter fields follow oh-my-pi: `condition`, `scope` (`text`, `thinking`, `tool`, `tool:bash`, `tool:edit(*.ts)`), `globs`, and `interruptMode` (`always`, `prose-only`, `tool-only`, `never`), plus `repeatMode` (`once` or `after-gap`) and `repeatGap`. A rule fires once per session by default. `astCondition`, `question`, and `agents` are not supported; a rule that uses them is skipped and reported. `/ttsr` lists the loaded rules. |
|
|
34
34
|
|
package/README.zh-TW.md
CHANGED
|
@@ -28,7 +28,7 @@ anchorloop 核心循環 · 原則 · playbook:autonomous-run、paus
|
|
|
28
28
|
| `pi/book.ts` | Loop book。第一次 `todo` create 或 `kind` 呼叫會開啟一個 loop;任務紀錄需要 [`@juicesharp/rpiv-todo`](https://github.com/juicesharp/rpiv-mono/tree/main/packages/rpiv-todo#readme) 的 `todo` 工具(它的 `tool_result` details `{tasks, nextId}` 和 `rpiv-todo-state` 條目)。agent 只用 `anchorloop_stage` 宣告 extension 看不到的事:`kind`(`quick`、`inline`、`reviewed`、`durable`,附 intent 和 anchor 指令)、`verify`(不是指令的檢查)、`fresh-read`、`friction`(`tried`、`found`、`led_by`)、`reflect`、`skip`、`back`、`close`,以及查詢用的 `read`。其餘都從證據讀出:production 的修改(任何 git repo 內、`scratch/` 與 `docs/specs/` 以外的 write 或 edit;已連結 child 的修改,以及成功的 `git merge`、`cherry-pick`、`pull` 也算)、執行過 anchor 指令的那次 bash 的 exit code(失敗後又通過的執行會成為 retry pair)、reviewer 的 `Blocking: P0=<n> P1=<m>` 數字、`docs/specs/*/` 產出物每次編輯後的摘要,以及 Jev 判定為「全新 context 讀過 spec」的 subagent 回報。階段機依這些證據給每種 loop 固定的階段順序(`quick` 為 act → check;`inline` 為 anchor → act → verify;`reviewed` 加 review;`durable` 再加 decide → grill → spec → read → approve → design;每一種都以 reflect → close 結尾),`read` 顯示 `<種類> · phase <目前> ✓ → <下一個>(缺:…)· 已跳過:…`。前一個階段還沒完成就開始下一個階段,會用一行警告一次並指出 `skip` 的出口;證據改變或用 `back` 時階段會退回。book 也記錄每個 todo 的 `anchor`、`ref`(`<path>#<heading>`,解析成行號範圍)和 `followup` metadata。每個開啟中的 loop 有一份 YAML book,放在 `~/.pi/agent/anchorloop/books/`(可用 `ANCHORLOOP_BOOKS_DIR` 覆寫),subagent 的 book 放在 `agents/`(subagent 自己 close 時 book 留給主 session);`session_start` 會清掉 session 已不存在或 7 天沒有更新的 book。`close` 不會因為階段或 friction 而拒絕,只在還有 pending 或 in-progress 的 todo 沒有 `metadata.followup`(票號、`memory` 或 `drop — <原因>`)時拒絕。 |
|
|
29
29
|
| `pi/anchor-gate.ts` | 只在開啟的 loop 內:`write` 或 `edit` 開始 `act` 階段、而這種 loop 前面的階段還沒完成時,顯示一行警告:沒有 anchor(kind 呼叫的 `anchor`、`Reality anchor:` 這一行,或已跳過),`durable` loop 則還缺決策、spec、全新 context 的閱讀、核准或設計(從 `docs/specs/<資料夾>/` 的檔案判斷,資料夾由 book、intent 或 todo 的 `ref` 找出)。只有新缺了一個階段時才會再警告;呼叫仍會放行。沒有 loop 或是 `quick` loop 時保持安靜。`.md`、`.txt`、`.html` 檔、`scratch/`、`docs/specs/` 和專案外的暫存檔不會觸發。透過 `bash` 做的修改不檢查。 |
|
|
30
30
|
| `pi/decision-tool.ts` | `anchorloop_decision` 工具把一筆決策寫進 TSV 決策軌跡,每筆只佔一行,用試算表開啟也安全;接手別人的軌跡時寫一筆 `start`。 |
|
|
31
|
-
| `pi/second-thought.ts` | 只在開啟的 loop 內:一次執行結束且 book 自上次判斷後多了條目時,以及宣告 `close` 時,透過 pi 的 classifier registry 請 Jev(TypeSafe 的型別化決策模型)複核階段機。下一個階段由程式從 book 算出;Jev 看到種類、intent、anchor、diff 摘要(≤1200 字元)、`phase`(目前、下一個、缺什麼)、verify 狀態、未完成 todo、任務清單和 friction(子 agent
|
|
31
|
+
| `pi/second-thought.ts` | 只在開啟的 loop 內:一次執行結束且 book 自上次判斷後多了條目時,以及宣告 `close` 時,透過 pi 的 classifier registry 請 Jev(TypeSafe 的型別化決策模型)複核階段機。下一個階段由程式從 book 算出;Jev 看到種類、intent、anchor、diff 摘要(≤1200 字元)、`phase`(目前、下一個、缺什麼)、verify 狀態、未完成 todo、任務清單和 friction(子 agent 的以它的名字列出),只判斷要 `advance`、退回(`back`)還是 `ask-user`,另外還問 `done`、還需要哪一級 review 與品質;階段是否完成只由程式依證據判定。一行提醒以 `next → <階段>` 開頭;有 retry pair 卻沒有 friction 條目時,附上 `friction` 提示。只有 Jev 同意前進、而下一個階段是 verify、review 或 fix 時,才讓 agent 多跑一輪;與上一則相同的提醒不重複,最後一次修改之後已有無 blocking 發現的 review 時,`full` 評等只顯示備註、不要求複查。呼叫過 `MonitorCreate`、`LoopCreate`、`goal_wait` 或 `subagent` 工具的執行在等待中,不被判斷。沒有 TypeSafe key 時什麼都不做,沒有 loop 時不會執行。subagent session(pi-herdr-agents 的 `PI_SUBAGENT_ID`,或 pi-subagents 的 `PI_SUBAGENT_CHILD`)不註冊任何東西,因為由派它的 agent 判斷結果。 |
|
|
32
32
|
| `pi/validate-tool-use.ts` | 每次 `write` 或 `edit` 後在行程內驗證該檔(`pi/support/validators.ts`,移植自 `hooks/validators/`),替 `SKILL.md`、指令檔(`AGENTS.md`、`CLAUDE.md`、`GEMINI.md`、`rules/`)和 `docs/specs/` 產出物附上建議。不需要 Python;`hooks/` 的 Python 驗證器仍供 `validate_all.py` 和對照測試使用。 |
|
|
33
33
|
| `pi/ttsr.ts` | 移植自 oh-my-pi 的 Time Traveling Stream Rules。`~/.pi/agent/rules/` 或 `<專案>/.pi/rules/` 裡 frontmatter 帶有 `condition` regex 的 Markdown 規則,會在執行過程中被監看。assistant 串流文字命中時,中斷回應、丟棄那段輸出,並注入規則後重試;工具參數命中時(`bash` 看指令,`write`/`edit` 看新寫入的文字),直接擋下呼叫,以規則內容作為理由。frontmatter 欄位沿用 oh-my-pi:`condition`、`scope`(`text`、`thinking`、`tool`、`tool:bash`、`tool:edit(*.ts)`)、`globs`、`interruptMode`(`always`、`prose-only`、`tool-only`、`never`),另加 `repeatMode`(`once` 或 `after-gap`)與 `repeatGap`。預設每條規則每個 session 只觸發一次。不支援 `astCondition`、`question`、`agents`,用到的規則會被跳過並回報。`/ttsr` 列出已載入的規則。 |
|
|
34
34
|
|
|
@@ -14,7 +14,7 @@ def check_decision_md(path: Path) -> list[str]:
|
|
|
14
14
|
|
|
15
15
|
# Check for decision table
|
|
16
16
|
if not re.search(r"\|\s*Question\s*\|\s*Answer\s*\|\s*Basis\s*\|\s*Status\s*\|", text, re.IGNORECASE):
|
|
17
|
-
warnings.append("decision.md should include a Question | Answer | Basis | Status table.")
|
|
17
|
+
warnings.append("decision.md should include a Question | Answer | Basis | Status table (Status: grounded, confirmed, or open).")
|
|
18
18
|
|
|
19
19
|
# Check for pre-flight readiness (core rules)
|
|
20
20
|
lower = text.lower()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-anchorloop",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "Agent workflow skills for pi: one entry skill per task type, each with playbooks, over a shared Align → Anchor → Act → Verify loop, plus loop extensions (loop book, anchor gate, decision trail tool, Jev second thought, skill validator, stream rules).",
|
|
5
5
|
"author": "Wei Hung",
|
|
6
6
|
"license": "MIT",
|
package/pi/book.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { readFileSync } from "node:fs";
|
|
11
|
+
import { homedir } from "node:os";
|
|
11
12
|
import { join, resolve } from "node:path";
|
|
12
13
|
import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
|
|
13
14
|
import {
|
|
@@ -44,6 +45,7 @@ import {
|
|
|
44
45
|
taskDetails,
|
|
45
46
|
sweep,
|
|
46
47
|
touchRepo,
|
|
48
|
+
touchRepoBeforeMerge,
|
|
47
49
|
validFollowup,
|
|
48
50
|
verifyAfterLastAct,
|
|
49
51
|
} from "./support/book.ts";
|
|
@@ -114,18 +116,65 @@ export function bashExit(event: { isError?: boolean; structuredContent?: unknown
|
|
|
114
116
|
return named ? Number(named[1]) : null;
|
|
115
117
|
}
|
|
116
118
|
|
|
119
|
+
/** The command with quoted strings blanked out, keeping every index, so quoted text never counts as a run or a separator. */
|
|
120
|
+
function unquoted(command: string): string {
|
|
121
|
+
// One left-to-right pass, so whichever starts first wins: a quote, or a `#` that starts a word and comments out its line.
|
|
122
|
+
// Newlines inside quotes are kept, since they still separate commands for the scan.
|
|
123
|
+
return command.replace(/'[^']*'|"(?:\\.|[^"\\])*"|(^|\s)#[^\n]*/g, (span) => span.replace(/[^\n]/g, " "));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Text before a run with `VAR=value` and simple wrappers (`uv run`, `time`, `timeout N`, `env`) peeled off its end. */
|
|
127
|
+
function beforeRun(text: string): string {
|
|
128
|
+
return text.replace(/(\b\w+=\S*\s+|\buv\s+run\s+|\btime\s+|\btimeout\s+[^\s;&|]+\s+|\benv\s+)+$/, "");
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// `cd` and `export` change what a check tests, so they are not setup.
|
|
132
|
+
const SETUP_SEGMENT = /^\s*(\.|source\b|set\b|\w+=)/;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Where `command` runs `anchor` as a command (at the start, or after `&&`, `||`, `;`, `|`, `!`, `(` or a newline, outside quotes,
|
|
136
|
+
* past any `VAR=value` prefixes), as the last such run, or undefined. The full anchor is tried first; an anchor whose earlier
|
|
137
|
+
* `&&` segments only set up the environment (`. venv/bin/activate && pytest -q`) also matches on its last segment.
|
|
138
|
+
*/
|
|
139
|
+
export function anchorRun(command: string, anchorText: string): { at: number; anchor: string } | undefined {
|
|
140
|
+
const masked = unquoted(command);
|
|
141
|
+
const segments = anchorText.split("&&").map((segment) => segment.trim());
|
|
142
|
+
const candidates = [anchorText.trim()];
|
|
143
|
+
if (segments.length > 1 && segments.slice(0, -1).every((segment) => SETUP_SEGMENT.test(segment))) candidates.push(segments.at(-1)!);
|
|
144
|
+
for (const anchor of candidates) {
|
|
145
|
+
if (!anchor) continue;
|
|
146
|
+
let found: number | undefined;
|
|
147
|
+
for (let at = masked.indexOf(anchor); at >= 0; at = masked.indexOf(anchor, at + 1)) {
|
|
148
|
+
const before = beforeRun(masked.slice(0, at));
|
|
149
|
+
const after = masked.charAt(at + anchor.length);
|
|
150
|
+
// `$(`, `<(`, `>(` substitute output; their exit is not the call's.
|
|
151
|
+
if (/(^|&&|\|\||[;|!\n]|(^|[^$<>])\()\s*$/.test(before) && (after === "" || /[\s;&|)]/.test(after))) found = at;
|
|
152
|
+
}
|
|
153
|
+
if (found !== undefined) return { at: found, anchor };
|
|
154
|
+
}
|
|
155
|
+
return undefined;
|
|
156
|
+
}
|
|
157
|
+
|
|
117
158
|
/**
|
|
118
159
|
* The exit to record for a bash call that ran `anchor`: the call's exit code, except `unknown` when something after the anchor
|
|
119
|
-
* can replace it: `||`, `;`, a newline, or a pipe straight after the anchor unless
|
|
160
|
+
* can replace it: `||`, `;`, a newline, `&`, or a pipe straight after the anchor unless `set -o pipefail` is in effect before it.
|
|
120
161
|
* A chain `anchor && other` keeps a failed anchor's code, so it stands.
|
|
121
162
|
*/
|
|
122
|
-
export function anchorExit(command: string,
|
|
163
|
+
export function anchorExit(command: string, anchorText: string, exit: number | null): number | "unknown" {
|
|
123
164
|
if (exit === null) return "unknown";
|
|
124
|
-
const
|
|
165
|
+
const run = anchorRun(command, anchorText);
|
|
166
|
+
if (!run) return "unknown";
|
|
167
|
+
const masked = unquoted(command);
|
|
168
|
+
const { at, anchor } = run;
|
|
125
169
|
// `! anchor` inverts the code and `x || anchor` may never run it.
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
const
|
|
170
|
+
if (/(!|\|\|)\s*(\(\s*|cd\s+\S+\s*&&\s*)*$/.test(beforeRun(masked.slice(0, at)))) return "unknown";
|
|
171
|
+
// Inside a subshell, a pipefail set or the exit of what follows is not this shell's.
|
|
172
|
+
const depth = [...masked.slice(0, at)].reduce((open, char) => open + (char === "(" ? 1 : char === ")" ? -1 : 0), 0);
|
|
173
|
+
const rest = masked.slice(at + anchor.length);
|
|
174
|
+
// The last `set -o pipefail` or `set +o pipefail` before the anchor decides.
|
|
175
|
+
const toggles = [...masked.slice(0, at).replace(/\([^()]*\)/g, (sub) => " ".repeat(sub.length)).matchAll(/\bset\b[^;&|\n]*?([-+])\w*o\s+pipefail\b/g)];
|
|
176
|
+
if (depth > 0 && toggles.length === 0 && /\|(?!\|)/.test(rest)) return "unknown";
|
|
177
|
+
const pipefail = toggles.at(-1)?.[1] === "-";
|
|
129
178
|
let chained = false;
|
|
130
179
|
// `&&` keeps a failed anchor's exit; `||`, `;`, and a newline can replace it, and so can a pipe
|
|
131
180
|
// straight after the anchor unless pipefail is set.
|
|
@@ -251,7 +300,15 @@ export default function (pi: ExtensionAPI) {
|
|
|
251
300
|
const tail = unreflected.length
|
|
252
301
|
? ` Unreflected friction for the Reflexive Pass: ${unreflected.map((item) => `${item.ref} (${item.found})`).join("; ")}.`
|
|
253
302
|
: "";
|
|
254
|
-
const
|
|
303
|
+
const named = (item: (typeof phaseList)[number]) => `${item.phase}${item.note ? ` (${item.note})` : ""}`;
|
|
304
|
+
const doneNames = phaseList.filter((item) => item.state === "done").map((item) => item.phase);
|
|
305
|
+
const skippedNames = phaseList.filter((item) => item.state === "skipped" || item.state === "auto-skipped").map(named);
|
|
306
|
+
const openNames = phaseList.filter((item) => item.state === "not shown complete").map((item) => item.phase);
|
|
307
|
+
const shown = [
|
|
308
|
+
`done: ${doneNames.join(", ") || "none"}`,
|
|
309
|
+
...(skippedNames.length ? [`skipped: ${skippedNames.join(", ")}`] : []),
|
|
310
|
+
...(openNames.length ? [`${verdict === "landed" ? "not complete" : "not reached"}: ${openNames.join(", ")}`] : []),
|
|
311
|
+
].join("; ");
|
|
255
312
|
const back = summary.back.length ? `; back ${summary.back.join(", ")}` : "";
|
|
256
313
|
const text = `Loop closed (${verdict}): phases ${shown}; ${summary.reviewTrend}; diff ${diff.summary.split("\n").join("; ")}${back}.${tail}`;
|
|
257
314
|
const after = notice ? `\n${notice}` : "";
|
|
@@ -408,14 +465,20 @@ export default function (pi: ExtensionAPI) {
|
|
|
408
465
|
const exit = bashExit(event);
|
|
409
466
|
const last = lastLine(output);
|
|
410
467
|
const anchor = anchorCommand(book.entries);
|
|
411
|
-
if (anchor && command
|
|
468
|
+
if (anchor && anchorRun(command, anchor)) {
|
|
412
469
|
const recorded = childId() !== undefined || currentKind(book.entries) === "quick" ? "check" : "verify";
|
|
413
470
|
book.entries.push(appendEntry(book.path, recorded, { command: anchor.slice(0, 200), exit: anchorExit(command, anchor, exit), last }));
|
|
414
471
|
}
|
|
415
472
|
for (const task of latestTasks(book.entries)) {
|
|
416
|
-
if (typeof task.anchor === "string" && command
|
|
473
|
+
if (typeof task.anchor === "string" && anchorRun(command, task.anchor)) appendEntry(book.path, "taskrun", { id: task.id, exit: anchorExit(command, task.anchor, exit), last });
|
|
417
474
|
}
|
|
418
|
-
|
|
475
|
+
const merged = /\bgit(\s+-C\s+\S+)?\s+(merge|cherry-pick|pull)(?=\s|$)(?![^|;&]*--(abort|quit)\b)/.exec(command);
|
|
476
|
+
if (exit === 0 && merged && !/Already up to date/i.test(last ?? "") && book.entries.at(-1)?.stage !== "edit") {
|
|
477
|
+
// The repo is the `-C` of the merge itself, else the nearest `cd` before it.
|
|
478
|
+
const cds = [...command.slice(0, merged.index).matchAll(/\bcd\s+(\S+)/g)];
|
|
479
|
+
const named = merged[1]?.trim().replace(/^-C\s+/, "") ?? cds.at(-1)?.[1];
|
|
480
|
+
const dir = named?.replace(/^~(?=\/|$)/, homedir());
|
|
481
|
+
touchRepoBeforeMerge(book, resolve(String(book.header.cwd ?? process.cwd()), dir ?? "."), merged[2]);
|
|
419
482
|
book.entries.push(appendEntry(book.path, "edit", { via: "merge" }));
|
|
420
483
|
}
|
|
421
484
|
if (exit === 0 && /\bgit\b[^|;&]*\bcommit\b/.test(command) && !book.entries.some((entry) => entry.stage === "edit")) {
|
package/pi/second-thought.ts
CHANGED
|
@@ -23,7 +23,7 @@ export type { Snapshot };
|
|
|
23
23
|
export const ENTRY_TYPE = "anchorloop-second-thought";
|
|
24
24
|
const WAIT_TOOLS = new Set(["MonitorCreate", "LoopCreate", "goal_wait", "subagent", "subagent_resume", "subagent_send"]);
|
|
25
25
|
|
|
26
|
-
export const THRESHOLDS = {
|
|
26
|
+
export const THRESHOLDS = { doneBelow: 0.25, qualityBelow: 1.5, reviewTier: "full" };
|
|
27
27
|
|
|
28
28
|
export const MOVES = ["advance", "back", "ask-user"] as const;
|
|
29
29
|
export type Move = (typeof MOVES)[number];
|
|
@@ -42,14 +42,6 @@ export const QUESTIONS = {
|
|
|
42
42
|
"ask-user": "a decision or judgment that belongs to the user blocks progress",
|
|
43
43
|
},
|
|
44
44
|
},
|
|
45
|
-
complete: {
|
|
46
|
-
type: "bool" as const,
|
|
47
|
-
instructions: "Does the evidence in `diff`, `verify`, and `phase` show that the completion condition of the last complete phase (`phase` current) truly holds, beyond the program's mechanical check?",
|
|
48
|
-
criteria: {
|
|
49
|
-
true: "the evidence observably meets what the phase requires",
|
|
50
|
-
false: "the phase counts as complete on a mechanical signal, but its content is empty, stale, or off the intent",
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
45
|
done: {
|
|
54
46
|
type: "bool" as const,
|
|
55
47
|
instructions: "Does the `verify` evidence show, with observed results, that `intent` is fully met?",
|
|
@@ -79,16 +71,15 @@ export const QUESTIONS = {
|
|
|
79
71
|
},
|
|
80
72
|
};
|
|
81
73
|
|
|
82
|
-
export type Verdict = { move: Move;
|
|
74
|
+
export type Verdict = { move: Move; done: number; review: string; reviewProbability: number; quality: number };
|
|
83
75
|
|
|
84
76
|
export function readVerdict(answers: Answers): Verdict | undefined {
|
|
85
|
-
const { move,
|
|
86
|
-
if (move?.type !== "choice" ||
|
|
77
|
+
const { move, done, review, quality } = answers;
|
|
78
|
+
if (move?.type !== "choice" || done?.type !== "bool" || review?.type !== "choice" || quality?.type !== "score") return undefined;
|
|
87
79
|
if (!(MOVES as readonly string[]).includes(move.choice ?? "")) return undefined;
|
|
88
80
|
const choice = review.choice ?? "";
|
|
89
81
|
return {
|
|
90
82
|
move: move.choice as Move,
|
|
91
|
-
complete: complete.probability ?? 0,
|
|
92
83
|
done: done.probability ?? 0,
|
|
93
84
|
review: choice,
|
|
94
85
|
reviewProbability: review.probabilities?.[choice] ?? 0,
|
|
@@ -99,7 +90,6 @@ export function readVerdict(answers: Answers): Verdict | undefined {
|
|
|
99
90
|
export function assess(verdict: Verdict, snap: Snapshot): { found: string[]; notes: string[] } {
|
|
100
91
|
const found: string[] = [];
|
|
101
92
|
const notes: string[] = [];
|
|
102
|
-
if (verdict.complete < THRESHOLDS.completeBelow && snap.current !== "start") found.push(`${snap.current} not shown to be complete`);
|
|
103
93
|
if (verdict.done < THRESHOLDS.doneBelow) found.push("evidence not shown to cover the intent");
|
|
104
94
|
if (verdict.review === THRESHOLDS.reviewTier) {
|
|
105
95
|
if (snap.reviewClear) notes.push("review rated full, but a review recorded after the last change found no blocking finding");
|
|
@@ -119,7 +109,7 @@ export function message(verdict: Verdict, snap: Snapshot, found: string[], notes
|
|
|
119
109
|
const extra = [...found, ...notes, ...snap.hints];
|
|
120
110
|
return (
|
|
121
111
|
`Second thought (Jev, advisory): next → ${snap.next}${snap.missing ? ` (missing: ${snap.missing})` : ""}; ` +
|
|
122
|
-
`${verdict.move};
|
|
112
|
+
`${verdict.move}; done ${verdict.done.toFixed(2)}, review ${verdict.review}, quality ${verdict.quality.toFixed(2)}/3` +
|
|
123
113
|
`${extra.length ? `; ${extra.join("; ")}` : ""}.` +
|
|
124
114
|
(!atClose && continues(verdict, snap) ? ` Do ${snap.next} now, or say why it does not apply.` : "")
|
|
125
115
|
);
|
package/pi/support/book.ts
CHANGED
|
@@ -545,6 +545,22 @@ export function touchRepo(book: Book, path: string): boolean {
|
|
|
545
545
|
return true;
|
|
546
546
|
}
|
|
547
547
|
|
|
548
|
+
/**
|
|
549
|
+
* Adds the repo at `dir` with its pre-command HEAD after a `verb` (merge, pull, or cherry-pick) first seen through bash: the
|
|
550
|
+
* reflog entry before the run of `verb` entries on top. ORIG_HEAD is not used, since cherry-pick leaves an old one in place.
|
|
551
|
+
*/
|
|
552
|
+
export function touchRepoBeforeMerge(book: Book, dir: string, verb: string): boolean {
|
|
553
|
+
const found = repoOf(join(dir, "_"));
|
|
554
|
+
if (!found || bases(book.entries).some((base) => base.repo === found.repo)) return false;
|
|
555
|
+
const reflog = git(found.repo, ["reflog", "-n", "50", "--format=%H %gs"])?.split("\n").filter(Boolean) ?? [];
|
|
556
|
+
const first = reflog.findIndex((line) => !line.slice(41).startsWith(verb));
|
|
557
|
+
const before = reflog.length > 0 && reflog[0].slice(41).startsWith(verb) && first > 0 ? reflog[first].slice(0, 40) : undefined;
|
|
558
|
+
// A rebasing pull leaves the old HEAD off HEAD's history; their merge base keeps the pulled commits in the diff.
|
|
559
|
+
const base = before === undefined ? undefined : git(found.repo, ["merge-base", before, "HEAD"]);
|
|
560
|
+
book.entries.push(appendEntry(book.path, "base", { repo: found.repo, head: base || found.head }));
|
|
561
|
+
return true;
|
|
562
|
+
}
|
|
563
|
+
|
|
548
564
|
export type Diff = { summary: string; files: string[]; paths: string[] };
|
|
549
565
|
|
|
550
566
|
/** The diff of each base's repo against its recorded HEAD, as one summary line per repo and the changed files. */
|
package/pi/support/phases.ts
CHANGED
|
@@ -123,10 +123,11 @@ function skipEntry(entries: Entry[], from: number, name: string): Entry | undefi
|
|
|
123
123
|
|
|
124
124
|
/** The latest recorded summary of an artifact since `from`; a loop that never wrote it falls back to the file on disk. */
|
|
125
125
|
function artifact(ctx: Ctx, name: string, from: number): Entry | undefined {
|
|
126
|
+
// The file on disk is the current state (a `sed` edit through bash is not observed); entries are history.
|
|
127
|
+
const disk = ctx.folder && from === 0 ? artifactOnDisk(ctx.folder, name, ctx.cwd) : undefined;
|
|
128
|
+
if (disk) return disk;
|
|
126
129
|
const index = lastWhere(ctx.entries, from, (entry) => entry.stage === name && entry.auto === true);
|
|
127
|
-
|
|
128
|
-
const wrote = ctx.entries.some((entry) => entry.stage === name && entry.auto === true);
|
|
129
|
-
return from === 0 && !wrote && ctx.folder ? artifactOnDisk(ctx.folder, name, ctx.cwd) : undefined;
|
|
130
|
+
return index >= 0 ? ctx.entries[index] : undefined;
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
const total = (counts: unknown): number => Object.values((counts ?? {}) as Record<string, number>).reduce((sum, n) => sum + Number(n), 0);
|
|
@@ -155,7 +156,7 @@ function evaluate(name: string, ctx: Ctx): Status {
|
|
|
155
156
|
switch (name) {
|
|
156
157
|
case "decide": {
|
|
157
158
|
const decision = artifact(ctx, "decision", from);
|
|
158
|
-
return total(decision?.counts) > 0 ? done(name) : missing(name, ctx.folder ? `${ctx.folder}/decision.md with decision rows` : "decision.md with decision rows (no spec folder: name it in `intent` by calling `kind` again)");
|
|
159
|
+
return total(decision?.counts) > 0 ? done(name) : missing(name, ctx.folder ? `${ctx.folder}/decision.md with decision rows (Status grounded, confirmed, or open)` : "decision.md with decision rows with Status grounded, confirmed, or open (no spec folder: name it in `intent` by calling `kind` again)");
|
|
159
160
|
}
|
|
160
161
|
case "grill": {
|
|
161
162
|
const decision = artifact(ctx, "decision", from);
|
package/pi/support/validators.ts
CHANGED
|
@@ -320,7 +320,7 @@ function checkDecisionMd(path: string): string[] {
|
|
|
320
320
|
const warnings: string[] = [];
|
|
321
321
|
const text = readText(path);
|
|
322
322
|
if (!/\|\s*Question\s*\|\s*Answer\s*\|\s*Basis\s*\|\s*Status\s*\|/i.test(text)) {
|
|
323
|
-
warnings.push("decision.md should include a Question | Answer | Basis | Status table.");
|
|
323
|
+
warnings.push("decision.md should include a Question | Answer | Basis | Status table (Status: grounded, confirmed, or open).");
|
|
324
324
|
}
|
|
325
325
|
const lower = text.toLowerCase();
|
|
326
326
|
if (!lower.includes("rule") && !lower.includes("readiness") && !lower.includes("prerequisite") && !lower.includes("core")) {
|