@andares/pi-toolkits 1.2.4 → 1.2.5
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/CHANGELOG.md +6 -0
- package/README.md +10 -6
- package/README.zh-CN.md +10 -6
- package/package.json +5 -5
- package/src/features/autostart/autostart.ts +1 -1
- package/src/features/autostart/index.ts +2 -2
- package/src/features/compact/index.ts +1 -1
- package/src/features/favorites/constants.ts +2 -2
- package/src/features/favorites/patch-cycle.ts +4 -3
- package/src/features/favorites/patch-selector.ts +1 -1
- package/src/features/spec/index.test.ts +184 -8
- package/src/features/spec/index.ts +136 -24
- package/src/features/spec/prompt.test.ts +20 -0
- package/src/features/spec/prompt.ts +46 -0
- package/src/features/stash/stash.ts +2 -2
- package/src/lib/gates.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,11 @@ renames that heading to the version being published and refuses an empty section
|
|
|
11
11
|
|
|
12
12
|
<!-- Notes for the next release go here; `pnpm release` renames this heading. -->
|
|
13
13
|
|
|
14
|
+
## 1.2.5 — 2026-11-30
|
|
15
|
+
|
|
16
|
+
- **ask-spec** — `/ask-spec` without arguments now arms the phase instead of starting it from an empty topic: the next message you send (multi-line, pasted, whole paragraphs) becomes the spec brief, and its first line names the draft file. Running the bare command again, or `/ask-spec off`, cancels before anything starts.
|
|
17
|
+
- **host compatibility** — the supported pi range moves to `pi >= 1.0.0`, verified 1.0.0 through 1.7.0 (window 1.4–1.7 plus the 1.3/1.2/1.1/1.0 probes, every published version, full gate). Nothing in this plugin needed a code change for 1.7.0; the keys and the mirrored compaction files are unchanged.
|
|
18
|
+
|
|
14
19
|
## 1.2.4 — 2026-11-28
|
|
15
20
|
|
|
16
21
|
- **ask-review / ask-spec** — the retired command spellings `/third-review` and `/ask-plan` are no longer registered; use `/ask-review` and `/ask-spec`. An autostart entry still spelled the old way is skipped with a warning instead of being sent to the model as chat.
|
|
@@ -100,3 +105,4 @@ renames that heading to the version being published and refuses an empty section
|
|
|
100
105
|
- permission — a capped rolling JSONL approval log records each ask, its parsed units and your answer; `pnpm approval-report` turns it into rule candidates.
|
|
101
106
|
|
|
102
107
|
|
|
108
|
+
|
package/README.md
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
[](https://pi.dev/packages/@andares/pi-toolkits)
|
|
11
11
|
[](LICENSE)
|
|
12
12
|
[](https://pnpm.io)
|
|
13
|
-
[](https://github.com/earendil-works/pi)
|
|
14
14
|
[](https://github.com/andares/pi-toolkits)
|
|
15
15
|
|
|
16
16
|
In a nutshell: thirteen ready-to-use capabilities — **read-only consult mode** `ask`, **session-scoped boundary permission** `ask-perm`, **model favorites** `favorites`, **prompt stash** `stash`, **third-party code review** `ask-review`, **dedicated compaction model** `compact-model`, **session startup automation** `autostart`, an **agent memory framework** `ask-init`, a **spec review in the browser** `ask-spec`, **reply notes in the browser** `ask-talk`, an **acceptance ledger with a browser page** `ask-uat`, a **session backlog for parallel work** `keep`, and **release notes on the first start after an upgrade** `whats-new` — with more to come.
|
|
17
17
|
|
|
18
|
-
**Requirements**: pi `>=0.
|
|
18
|
+
**Requirements**: pi `>=1.0.0`. Every published pi release from 1.0.0 through 1.7.0 has been verified with the full gate (install → `tsc --noEmit` → full test suite → keybinding audit → hash compare of the host files this package patches), each in a sandbox with the whole `@earendil-works/*` family pinned to the version under test. There is no upper bound: newer releases are verified as they ship and the floor moves only when the measurement says so; `pnpm check:compat` reproduces the result. Note: pi ≥ 0.99 hosts require host-provided packages to be declared in `peerDependencies` with a `"*"` range — `@earendil-works/pi-tui` and `typebox` (the `scratchpad` tool builds a TypeBox schema) are declared that way; an installed copy in `dependencies` would make pi warn.
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
@@ -293,6 +293,8 @@ After a development task is done, type the `/ask-review` command to summon **a d
|
|
|
293
293
|
|
|
294
294
|
`/ask-spec [topic]` opens a spec-review phase: the agent explores the code, asks what it cannot infer, and writes a spec — no code changes while the spec is under review. Then it calls `spec_submit`, the review opens in **your browser**, and you annotate it **paragraph by paragraph**: every blank-line-separated block can carry notes, and every note comes back to the agent as its next message. The pre-rename `/ask-plan` alias was removed.
|
|
295
295
|
|
|
296
|
+
- **A brief that does not fit on a command line.** Run `/ask-spec` with no arguments and the phase is only *armed*: nothing starts, nothing changes, and the next message you send — multi-line, pasted, whole paragraphs with lists and code — becomes the brief the review starts from. Its first line also names the default file (`specs/<slug>.md`). Typing the bare command again, or `/ask-spec off`, cancels before anything starts.
|
|
297
|
+
|
|
296
298
|
- **Blocks are the unit of review.** Each paragraph is one block, with a badge telling you what changed since the previous round: `new`, `modified`, `moved`, `removed`. Unchanged blocks collapse, so a three-line edit does not look like a rewrite. Fenced code blocks stay whole.
|
|
297
299
|
- **Two levels of notes.** On a block, or global. Nothing finer — no text ranges to re-anchor after an edit.
|
|
298
300
|
- **The page keeps the review in view.** A two-column layout: the spec on the left; the revision stats and a clickable annotation index on the right. Global notes stay visible above the blocks even when the editor is closed.
|
|
@@ -307,13 +309,15 @@ After a development task is done, type the `/ask-review` command to summon **a d
|
|
|
307
309
|
**Browser on WSL**: the review server binds `0.0.0.0` and the URL is printed with the WSL address, because Windows cannot reach a loopback-only server inside WSL. The opener prefers a Windows-side launcher (`wslview`, `cmd.exe /c start`, `powershell Start-Process`) and only falls back to `xdg-open` elsewhere — that is the difference between "opens your browser" and "opens a browser inside WSL that you cannot see".
|
|
308
310
|
|
|
309
311
|
```text
|
|
310
|
-
/ask-spec build the export feature # start the review
|
|
311
|
-
/ask-spec
|
|
312
|
-
/ask-spec #
|
|
312
|
+
/ask-spec build the export feature # start the review from a one-line topic
|
|
313
|
+
/ask-spec # idle: arm it — your next message becomes the brief
|
|
314
|
+
/ask-spec # reviewing: leave the phase
|
|
313
315
|
/ask-spec off # leave the phase (the draft stays where it is)
|
|
316
|
+
/ask-spec open # re-open the review page
|
|
314
317
|
```
|
|
315
318
|
|
|
316
|
-
The spec lands in `specs/<slug>.md` — the same place `/ask-init` keeps specs
|
|
319
|
+
The spec lands in `specs/<slug>.md` — the same place `/ask-init` keeps specs, with the slug
|
|
320
|
+
coming from the topic or from the first line of an armed brief. Without an
|
|
317
321
|
agent framework the review still works, but `record_change` and `/ask-uat` stay unavailable
|
|
318
322
|
until `/ask-init`; the command says so when the review starts. Leave an open UAT page first:
|
|
319
323
|
the two phases do not run on top of each other.
|
package/README.zh-CN.md
CHANGED
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
[](https://pi.dev/packages/@andares/pi-toolkits)
|
|
11
11
|
[](LICENSE)
|
|
12
12
|
[](https://pnpm.io)
|
|
13
|
-
[](https://github.com/earendil-works/pi)
|
|
14
14
|
[](https://github.com/andares/pi-toolkits)
|
|
15
15
|
|
|
16
16
|
一句话介绍:目前包含十三个开箱即用的功能——**只读咨询模式** `ask`、**会话级边界权限** `ask-perm`、**模型收藏** `favorites`、**提示词暂存** `stash`、**第三方代码评审** `ask-review`、**独立压缩模型** `compact-model`、**会话启动自动化** `autostart`、**agent 记忆框架** `ask-init`、**浏览器内规格评审** `ask-spec`、**回复批注** `ask-talk`、**验收台账与浏览器页面** `ask-uat`、**并行任务的会话暂存** `keep`、**升级后首次启动的版本变更提示** `whats-new`,后续持续追加。
|
|
17
17
|
|
|
18
|
-
**版本要求**:pi `>=0.
|
|
18
|
+
**版本要求**:pi `>=1.0.0`。1.0.0 到 1.7.0 的每一个已发布版本都用完整门禁实测过(install → `tsc --noEmit` → 全量测试 → 键位审计 → 对 patch 目标宿主文件做哈希比对),每个版本都在沙箱中把整个 `@earendil-works/*` 家族钉在同一版本。没有上界:更新的版本随发布逐个验证,下限只在实测结果允许时移动;`pnpm check:compat` 可复现该结论。注:pi ≥ 0.99 的宿主要求「宿主提供的包」一律声明为 peerDependencies `"*"` —— `@earendil-works/pi-tui` 与 `typebox`(ask 的 `scratchpad` 用它构造参数 schema)都按此声明;若放进 `dependencies`,pi 会告警。
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
@@ -293,6 +293,8 @@ run = ["/ask-perm allow allow allow ask"]
|
|
|
293
293
|
|
|
294
294
|
`/ask-spec [主题]` 进入规格评审期:模型先调研、把代码里看不出来的问题问清楚,然后写一份 spec——评审期间不改代码。写完调用 `spec_submit`,评审页在**你的浏览器**里打开,你**逐段**批注:每个空行分隔的块都可以挂批注,批注会作为下一条消息回到模型。改名前的 `/ask-plan` 别名已移除。
|
|
295
295
|
|
|
296
|
+
- **一整段需求塞不进命令行。** 不带参数执行 `/ask-spec` 只是**武装**:什么都不启动、什么都不改,你发下的**下一条消息**——多行、粘贴、带列表和代码的整篇需求——才是这次评审的依据,默认文件名 `specs/<slug>.md` 也取自它的第一行。再执行一次裸命令或用 `/ask-spec off`,在任何东西开始前取消。
|
|
297
|
+
|
|
296
298
|
- **块是评审单位。** 每个空行分隔的段落是一块,徽标告诉你相对上一版改了什么:`new`、`modified`、`moved`、`removed`。未变的块会折叠,三行小改不会看起来像整篇重写;围栏代码块保持完整。
|
|
297
299
|
- **两级批注。** 段落级,或全局;没有更细的文本范围批注,改完不需要重新锚定。
|
|
298
300
|
- **评审页一直看得见。** 双栏布局:左边是 spec,右边是本版统计和可点击的批注索引;全局批注即使编辑框关着也常显在正文上方。
|
|
@@ -307,13 +309,15 @@ run = ["/ask-perm allow allow allow ask"]
|
|
|
307
309
|
**WSL 下的浏览器**:评审服务器绑 `0.0.0.0`,URL 用 WSL 的地址打印,因为 Windows 连不到 WSL 里只绑 loopback 的服务器。打开器优先用 Windows 侧启动器(`wslview`、`cmd.exe /c start`、`powershell Start-Process`),其它平台才回落到 `xdg-open`——这决定了是「打开你的浏览器」还是「在 WSL 里打开一个你看不见的浏览器」。
|
|
308
310
|
|
|
309
311
|
```text
|
|
310
|
-
/ask-spec 做导出功能 #
|
|
311
|
-
/ask-spec
|
|
312
|
-
/ask-spec #
|
|
312
|
+
/ask-spec 做导出功能 # 用一行主题进入规格评审
|
|
313
|
+
/ask-spec # 空闲时:武装——下一条消息作为需求
|
|
314
|
+
/ask-spec # 评审中:退出评审期
|
|
313
315
|
/ask-spec off # 退出评审期(草稿留在原处)
|
|
316
|
+
/ask-spec open # 重新打开评审页
|
|
314
317
|
```
|
|
315
318
|
|
|
316
|
-
spec 落在 `specs/<slug>.md`——与 `/ask-init` 放 spec
|
|
319
|
+
spec 落在 `specs/<slug>.md`——与 `/ask-init` 放 spec 的地方相同,slug 取自主题或武装时那条
|
|
320
|
+
需求的第一行。没有 agent 框架时评审仍可用,
|
|
317
321
|
但 `record_change` 与 `/ask-uat` 不可用,直到 `/ask-init`;命令在评审开始时会说明。
|
|
318
322
|
UAT 页面开着时先退出:两个相位不叠在一起跑。
|
|
319
323
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andares/pi-toolkits",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "Integrated toolkit extension for pi — ask mode (read-only Q&A), browser-reviewed planning, reply notes in the browser (/ask-talk), an acceptance ledger with a browser page, session-scoped permission checks, model favorites, prompt stash, third-party code review, session autostart, a dedicated compaction model, an agent memory framework (/ask-init), a session backlog (/keep-quit, /keep-load, /keep-drop), and release notes on the first start after an upgrade",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"session-backlog"
|
|
54
54
|
],
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@earendil-works/pi-coding-agent": ">=0.
|
|
56
|
+
"@earendil-works/pi-coding-agent": ">=1.0.0",
|
|
57
57
|
"@earendil-works/pi-tui": "*",
|
|
58
58
|
"typebox": "*"
|
|
59
59
|
},
|
|
@@ -63,9 +63,9 @@
|
|
|
63
63
|
"smol-toml": "^1.9.0"
|
|
64
64
|
},
|
|
65
65
|
"devDependencies": {
|
|
66
|
-
"@earendil-works/pi-ai": "^1.
|
|
67
|
-
"@earendil-works/pi-coding-agent": "^1.
|
|
68
|
-
"@earendil-works/pi-tui": "^1.
|
|
66
|
+
"@earendil-works/pi-ai": "^1.7.0",
|
|
67
|
+
"@earendil-works/pi-coding-agent": "^1.7.0",
|
|
68
|
+
"@earendil-works/pi-tui": "^1.7.0",
|
|
69
69
|
"@types/node": "^26.6.2",
|
|
70
70
|
"typebox": "^1.3.27",
|
|
71
71
|
"typescript": "^5.6.0",
|
|
@@ -48,7 +48,7 @@ export const RUNNABLE_REASONS: ReadonlySet<string> = new Set([
|
|
|
48
48
|
* `-r` (`--resume`), `--session <path>` and `--fork <path>` all open an
|
|
49
49
|
* existing session *before* the first runtime exists, and that runtime is
|
|
50
50
|
* created without an explicit session_start event, so extensions see pi's
|
|
51
|
-
* default reason — `startup` — not `resume` (verified on pi 1.2.0–1.
|
|
51
|
+
* default reason — `startup` — not `resume` (verified on pi 1.2.0–1.7.0:
|
|
52
52
|
* `main.js` builds the initial session manager from those flags and calls
|
|
53
53
|
* `createAgentSessionRuntime` with no `sessionStartEvent`;
|
|
54
54
|
* `agent-session.js` defaults it to `{ reason: "startup" }`). `resume` is only
|
|
@@ -27,11 +27,11 @@
|
|
|
27
27
|
* that flag is what routes "/cmd args" through _tryExecuteExtensionCommand
|
|
28
28
|
* instead of the model prompt path. The wrapper defaults it to false in this
|
|
29
29
|
* package. `_tryExecuteExtensionCommand` is byte-identical across every
|
|
30
|
-
* published version of the supported window (1.
|
|
30
|
+
* published version of the supported window (1.4.0 → 1.7.0); `sendUserMessage`
|
|
31
31
|
* itself was refactored in 1.5.1 (the rest of the body moved into
|
|
32
32
|
* `_preparePrompt`, #9154), but the extension-command branch is still the
|
|
33
33
|
* first early exit of the wrapper, so `/cmd args` never reaches the model
|
|
34
|
-
* prompt path (1.6.0 left `sendUserMessage` and `_preparePrompt`
|
|
34
|
+
* prompt path (1.6.0 → 1.7.0 left `sendUserMessage` and `_preparePrompt`
|
|
35
35
|
* byte-identical). See AGENTS.md host-compat discipline for the version matrix.
|
|
36
36
|
*
|
|
37
37
|
* Only extension commands can run this way. Built-in commands (/compact,
|
|
@@ -135,7 +135,7 @@ async function completeSummary(
|
|
|
135
135
|
* over).
|
|
136
136
|
*
|
|
137
137
|
* 1.4.0 changed two things this mirror covers, and we follow 1.4.0 for every
|
|
138
|
-
* host in the supported window (1.
|
|
138
|
+
* host in the supported window (1.4.0 → 1.7.0) because both are bug fixes
|
|
139
139
|
* rather than behavior we could sensibly keep per version:
|
|
140
140
|
* - summaries no longer cap maxTokens at 0.8/0.5 × reserveTokens; the
|
|
141
141
|
* request omits maxTokens so the provider uses the model's output limit
|
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* bindings — only the cycle semantics change (patch-cycle.ts), so no
|
|
9
9
|
* keybinding conflicts arise.
|
|
10
10
|
*
|
|
11
|
-
*
|
|
12
|
-
* (0.
|
|
11
|
+
* Keybinding tables audited against every published version in the supported
|
|
12
|
+
* range (1.0.0 → 1.7.0), with pi-tui input dispatch checked on WSL2 +
|
|
13
13
|
* Windows Terminal; re-run `pnpm check:keybindings` after every host upgrade
|
|
14
14
|
* before trusting this.
|
|
15
15
|
*/
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
* model available" feedback); otherwise jump to it
|
|
16
16
|
* - the apply logic mirrors pi's _cycleScopedModel/_cycleAvailableModel
|
|
17
17
|
* (byte-identical across every published version in the supported window
|
|
18
|
-
* 1.
|
|
19
|
-
* tool-restore rewrites, by 1.5.0's auth-routing/loadout-ordering changes
|
|
20
|
-
* and by 1.5.1's extraction of
|
|
18
|
+
* 1.4.0 → 1.7.0 — `cycleModel` itself is untouched by 1.4.0's recovery and
|
|
19
|
+
* tool-restore rewrites, by 1.5.0's auth-routing/loadout-ordering changes,
|
|
20
|
+
* by the later 1.6.x changes and by 1.7.0, and by 1.5.1's extraction of
|
|
21
|
+
* the index math into `getNextCycleIndex`
|
|
21
22
|
* (that refactor lives in `_cycleScopedModel`/`_cycleAvailableModel`, which
|
|
22
23
|
* this patch replaces rather than calls; the semantics it encodes —
|
|
23
24
|
* wrap-around, and "current model not in the list → forward first /
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
* keeps loading and ctrl+p falls back to stock behavior. The prototype
|
|
23
23
|
* shape touched here (handleInput/updateList/filterModels and the instance
|
|
24
24
|
* fields below) is unchanged across the mandatory window
|
|
25
|
-
* pi 1.
|
|
25
|
+
* pi 1.4.0 → 1.7.0 (and exercised by the 1.0.0 → 1.3.0 backward probes).
|
|
26
26
|
* updateList gained one layout change in 1.5.0 — the disambiguating model
|
|
27
27
|
* name after the id — mirrored here; see distinctModelName below.
|
|
28
28
|
* filterModels gained a second `preferredModel` argument in 1.5.1 (keep the
|
|
@@ -11,11 +11,11 @@ import { request } from "node:http";
|
|
|
11
11
|
import { tmpdir } from "node:os";
|
|
12
12
|
import { dirname, join } from "node:path";
|
|
13
13
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
14
|
-
import type { ExtensionAPI, ExtensionContext, ToolCallEvent } from "@earendil-works/pi-coding-agent";
|
|
14
|
+
import type { ExtensionAPI, ExtensionContext, InputEvent, InputEventResult, ToolCallEvent } from "@earendil-works/pi-coding-agent";
|
|
15
15
|
import type { GateHub, GateVerdict } from "../../lib/gates.js";
|
|
16
16
|
import { setPermissionControl, type PermissionControl } from "../../lib/permission-control.js";
|
|
17
17
|
import { setAskControl } from "../../lib/ask-control.js";
|
|
18
|
-
import { LEGACY_SPEC_PHASE_TOOL } from "../../lib/phases.js";
|
|
18
|
+
import { LEGACY_SPEC_PHASE_TOOL, UAT_PHASE_TOOL } from "../../lib/phases.js";
|
|
19
19
|
import { registerSpec, SPEC_COMMAND, SPEC_SUBMIT_TOOL } from "./index.js";
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -55,11 +55,17 @@ function writeSpec(relativePath: string, text: string): void {
|
|
|
55
55
|
writeFileSync(path, text);
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** An input event, the way the host hands a typed message to extensions. */
|
|
59
|
+
function briefEvent(text: string, source: "interactive" | "rpc" | "extension" = "interactive"): InputEvent {
|
|
60
|
+
return { type: "input", text, source };
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
interface Harness {
|
|
59
64
|
pi: ExtensionAPI;
|
|
60
65
|
commands: Map<string, { description: string; handler: (args: string, ctx: ExtensionContext) => Promise<void> }>;
|
|
61
66
|
tools: Map<string, { name: string; execute: (id: string, params: { path?: string }) => Promise<{ content: Array<{ text: string }>; details: unknown }> }>;
|
|
62
67
|
handlers: Record<string, Array<(event: { systemPrompt: string }, ctx?: ExtensionContext) => { systemPrompt?: string } | undefined>>;
|
|
68
|
+
inputs: Array<(event: InputEvent, ctx: ExtensionContext) => InputEventResult | undefined>;
|
|
63
69
|
gates: Array<{ name: string; order?: number; evaluate: (event: ToolCallEvent) => GateVerdict | undefined }>;
|
|
64
70
|
sendUserMessage: ReturnType<typeof vi.fn>;
|
|
65
71
|
activeTools: () => string[];
|
|
@@ -74,6 +80,7 @@ function harness(): Harness {
|
|
|
74
80
|
const tools = new Map<string, { name: string; execute: (id: string, params: { path?: string }) => Promise<{ content: Array<{ text: string }>; details: unknown }> }>();
|
|
75
81
|
const gates: Harness["gates"] = [];
|
|
76
82
|
const handlers: Harness["handlers"] = {};
|
|
83
|
+
const inputs: Harness["inputs"] = [];
|
|
77
84
|
let activeTools = ["read", "grep", "bash", "write", "edit"];
|
|
78
85
|
const sendUserMessage = vi.fn();
|
|
79
86
|
const pi = {
|
|
@@ -82,9 +89,17 @@ function harness(): Harness {
|
|
|
82
89
|
tools.set(def.name, def as never);
|
|
83
90
|
},
|
|
84
91
|
on: (type: string, handler: (event: { systemPrompt: string }, ctx?: ExtensionContext) => { systemPrompt?: string } | undefined) => {
|
|
92
|
+
if (type === "input") {
|
|
93
|
+
inputs.push(handler as unknown as Harness["inputs"][number]);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
85
96
|
handlers[type] = [...(handlers[type] ?? []), handler];
|
|
86
97
|
},
|
|
87
98
|
getActiveTools: () => activeTools,
|
|
99
|
+
getCommands: () => [
|
|
100
|
+
{ name: "ask-spec", source: "extension" },
|
|
101
|
+
{ name: "ask-perm", source: "extension" },
|
|
102
|
+
],
|
|
88
103
|
getAllTools: () => [
|
|
89
104
|
{ name: "read" },
|
|
90
105
|
{ name: "bash" },
|
|
@@ -121,7 +136,7 @@ function harness(): Harness {
|
|
|
121
136
|
portStart: takePort(),
|
|
122
137
|
closeDelayMs: 25,
|
|
123
138
|
});
|
|
124
|
-
return { pi, commands, tools, gates, handlers, sendUserMessage, activeTools: () => activeTools, openBrowser, notify, ctx, control };
|
|
139
|
+
return { pi, commands, tools, gates, handlers, inputs, sendUserMessage, activeTools: () => activeTools, openBrowser, notify, ctx, control };
|
|
125
140
|
}
|
|
126
141
|
|
|
127
142
|
/** Talk to the review server the way the page does. */
|
|
@@ -218,10 +233,12 @@ describe("ask-spec command", () => {
|
|
|
218
233
|
expect(h.commands.has("ask-plan")).toBe(false);
|
|
219
234
|
});
|
|
220
235
|
|
|
221
|
-
it("
|
|
236
|
+
it("arms the phase instead of starting it without a topic", async () => {
|
|
222
237
|
const h = harness();
|
|
223
238
|
await h.commands.get(SPEC_COMMAND)!.handler("", h.ctx);
|
|
224
|
-
expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("
|
|
239
|
+
expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("armed"), "info");
|
|
240
|
+
expect(h.sendUserMessage).not.toHaveBeenCalled();
|
|
241
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
225
242
|
});
|
|
226
243
|
|
|
227
244
|
it("leaves spec mode when the bare command is run again", async () => {
|
|
@@ -236,11 +253,14 @@ describe("ask-spec command", () => {
|
|
|
236
253
|
expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("spec mode off"), "info");
|
|
237
254
|
expect(h.sendUserMessage).toHaveBeenCalledTimes(1);
|
|
238
255
|
|
|
239
|
-
// The next bare invocation
|
|
256
|
+
// The next bare invocation arms a new review; its brief arrives as a message.
|
|
240
257
|
await handler("", h.ctx);
|
|
258
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
259
|
+
const submitted = h.inputs[0]!(briefEvent("write the spec"), h.ctx);
|
|
260
|
+
expect(submitted).toMatchObject({ action: "transform" });
|
|
241
261
|
expect(h.activeTools()).toContain(SPEC_SUBMIT_TOOL);
|
|
242
|
-
expect(h.notify).toHaveBeenLastCalledWith(expect.stringContaining("specs/spec.md"), "info");
|
|
243
|
-
expect(h.sendUserMessage).toHaveBeenCalledTimes(
|
|
262
|
+
expect(h.notify).toHaveBeenLastCalledWith(expect.stringContaining("specs/write-the-spec.md"), "info");
|
|
263
|
+
expect(h.sendUserMessage).toHaveBeenCalledTimes(1);
|
|
244
264
|
});
|
|
245
265
|
|
|
246
266
|
it("opens a new window and server for the revision after feedback, keeping history", async () => {
|
|
@@ -451,6 +471,162 @@ describe("phase integration", () => {
|
|
|
451
471
|
});
|
|
452
472
|
});
|
|
453
473
|
|
|
474
|
+
describe("armed bare command", () => {
|
|
475
|
+
const arm = (h: Harness) => h.commands.get(SPEC_COMMAND)!.handler("", h.ctx);
|
|
476
|
+
const send = (h: Harness, event: InputEvent) => h.inputs[0]!(event, h.ctx);
|
|
477
|
+
|
|
478
|
+
it("nothing happens until the brief arrives", async () => {
|
|
479
|
+
const h = harness();
|
|
480
|
+
await arm(h);
|
|
481
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
482
|
+
expect(h.control.enableDefaults).not.toHaveBeenCalled();
|
|
483
|
+
expect(h.sendUserMessage).not.toHaveBeenCalled();
|
|
484
|
+
expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("armed"), "info");
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
it("turns the next message into the kickoff, verbatim, and starts the phase", async () => {
|
|
488
|
+
const h = harness();
|
|
489
|
+
await arm(h);
|
|
490
|
+
h.notify.mockClear();
|
|
491
|
+
const brief = [
|
|
492
|
+
"Add an armed entry for ask-spec",
|
|
493
|
+
"",
|
|
494
|
+
"Second paragraph, kept word for word, with `code` and a list:",
|
|
495
|
+
"- one",
|
|
496
|
+
"- two",
|
|
497
|
+
].join("\n");
|
|
498
|
+
|
|
499
|
+
const result = send(h, briefEvent(brief));
|
|
500
|
+
expect(result).toMatchObject({ action: "transform" });
|
|
501
|
+
const transformed = result?.action === "transform" ? result.text : "";
|
|
502
|
+
expect(transformed).toContain(brief);
|
|
503
|
+
expect(transformed).toContain("Target file: `specs/add-an-armed-entry-for-ask-spec.md`");
|
|
504
|
+
expect(transformed).toContain("Start spec review.");
|
|
505
|
+
|
|
506
|
+
expect(h.activeTools()).toContain(SPEC_SUBMIT_TOOL);
|
|
507
|
+
expect(h.control.enableDefaults).toHaveBeenCalledWith(h.ctx);
|
|
508
|
+
expect(h.notify).toHaveBeenCalledWith(
|
|
509
|
+
expect.stringContaining("specs/add-an-armed-entry-for-ask-spec.md"),
|
|
510
|
+
"info",
|
|
511
|
+
);
|
|
512
|
+
// The transformed input is the message; nothing is sent a second time.
|
|
513
|
+
expect(h.sendUserMessage).not.toHaveBeenCalled();
|
|
514
|
+
});
|
|
515
|
+
|
|
516
|
+
it("has the banner and the submit tool already on for that turn", async () => {
|
|
517
|
+
const h = harness();
|
|
518
|
+
await arm(h);
|
|
519
|
+
send(h, briefEvent("armed banner"));
|
|
520
|
+
const injected = h.handlers.before_agent_start![0]!({ systemPrompt: "base" });
|
|
521
|
+
expect(injected?.systemPrompt).toContain("[ASK-SPEC — SPEC REVIEW]");
|
|
522
|
+
expect(h.activeTools()).toContain(SPEC_SUBMIT_TOOL);
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it("stops arming once the brief is used", async () => {
|
|
526
|
+
const h = harness();
|
|
527
|
+
await arm(h);
|
|
528
|
+
send(h, briefEvent("first brief"));
|
|
529
|
+
expect(send(h, briefEvent("a second, unrelated message"))).toBeUndefined();
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
it("keeps arming past commands and extension-sent messages", async () => {
|
|
533
|
+
const h = harness();
|
|
534
|
+
await arm(h);
|
|
535
|
+
expect(send(h, briefEvent("/ask-perm allow"))).toBeUndefined();
|
|
536
|
+
expect(send(h, briefEvent("dispatched by autostart", "extension"))).toBeUndefined();
|
|
537
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
538
|
+
// Still armed: the operator's own message is the brief.
|
|
539
|
+
expect(send(h, briefEvent("the real brief"))).toMatchObject({ action: "transform" });
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
it("cancels with the bare command again, and with `off`", async () => {
|
|
543
|
+
const h = harness();
|
|
544
|
+
const handler = h.commands.get(SPEC_COMMAND)!.handler;
|
|
545
|
+
|
|
546
|
+
await arm(h);
|
|
547
|
+
await handler("", h.ctx);
|
|
548
|
+
expect(h.notify).toHaveBeenLastCalledWith(
|
|
549
|
+
expect.stringContaining("pending requirement cancelled"),
|
|
550
|
+
"info",
|
|
551
|
+
);
|
|
552
|
+
expect(send(h, briefEvent("too late"))).toBeUndefined();
|
|
553
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
554
|
+
|
|
555
|
+
await arm(h);
|
|
556
|
+
await handler("off", h.ctx);
|
|
557
|
+
expect(h.notify).toHaveBeenLastCalledWith(
|
|
558
|
+
expect.stringContaining("pending requirement cancelled"),
|
|
559
|
+
"info",
|
|
560
|
+
);
|
|
561
|
+
expect(send(h, briefEvent("also too late"))).toBeUndefined();
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
it("accepts a brief that starts with a path rather than a real command", async () => {
|
|
565
|
+
const h = harness();
|
|
566
|
+
await arm(h);
|
|
567
|
+
const result = send(h, briefEvent("/tmp contains the fixtures\n\nKeep the exporter unchanged."));
|
|
568
|
+
expect(result).toMatchObject({ action: "transform" });
|
|
569
|
+
expect(result?.action === "transform" ? result.text : "").toContain("/tmp contains the fixtures");
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
it("replaces the armed brief when a topic is given instead", async () => {
|
|
573
|
+
const h = harness();
|
|
574
|
+
const handler = h.commands.get(SPEC_COMMAND)!.handler;
|
|
575
|
+
await arm(h);
|
|
576
|
+
await handler("topic", h.ctx);
|
|
577
|
+
|
|
578
|
+
// `off` must leave the active phase, not merely cancel the old wait.
|
|
579
|
+
await handler("off", h.ctx);
|
|
580
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
581
|
+
expect(h.notify).toHaveBeenLastCalledWith(expect.stringContaining("spec mode off"), "info");
|
|
582
|
+
expect(send(h, briefEvent("an unrelated later message"))).toBeUndefined();
|
|
583
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
it("does not enter over UAT if it opened while the brief was pending", async () => {
|
|
587
|
+
const h = harness();
|
|
588
|
+
await arm(h);
|
|
589
|
+
h.pi.setActiveTools([...h.activeTools(), UAT_PHASE_TOOL]);
|
|
590
|
+
h.notify.mockClear();
|
|
591
|
+
|
|
592
|
+
expect(send(h, briefEvent("must not start spec over UAT"))).toBeUndefined();
|
|
593
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
594
|
+
expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("ask-uat is open"), "warning");
|
|
595
|
+
|
|
596
|
+
// The blocked attempt cancels the wait instead of arming a later surprise.
|
|
597
|
+
h.pi.setActiveTools(h.activeTools().filter((name) => name !== UAT_PHASE_TOOL));
|
|
598
|
+
expect(send(h, briefEvent("a later ordinary message"))).toBeUndefined();
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
it("does not enter during streaming if the agent started while armed", async () => {
|
|
602
|
+
const h = harness();
|
|
603
|
+
await arm(h);
|
|
604
|
+
h.notify.mockClear();
|
|
605
|
+
|
|
606
|
+
const queued = { ...briefEvent("queued while streaming"), streamingBehavior: "followUp" } as const;
|
|
607
|
+
expect(send(h, queued)).toBeUndefined();
|
|
608
|
+
expect(h.activeTools()).not.toContain(SPEC_SUBMIT_TOOL);
|
|
609
|
+
expect(h.notify).toHaveBeenCalledWith(expect.stringContaining("still running"), "warning");
|
|
610
|
+
expect(send(h, briefEvent("after the run"))).toBeUndefined();
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it("drops the armed state when the session changes", async () => {
|
|
614
|
+
const h = harness();
|
|
615
|
+
await arm(h);
|
|
616
|
+
const nextCtx = {
|
|
617
|
+
...h.ctx,
|
|
618
|
+
sessionManager: { getSessionId: () => "next-session" },
|
|
619
|
+
} as unknown as ExtensionContext;
|
|
620
|
+
h.handlers.session_start![0]!({ systemPrompt: "" }, nextCtx);
|
|
621
|
+
expect(h.inputs[0]!(briefEvent("from the old session"), h.ctx)).toBeUndefined();
|
|
622
|
+
});
|
|
623
|
+
|
|
624
|
+
it("does nothing at all when not armed", async () => {
|
|
625
|
+
const h = harness();
|
|
626
|
+
expect(h.inputs[0]!(briefEvent("just a normal message"), h.ctx)).toBeUndefined();
|
|
627
|
+
});
|
|
628
|
+
});
|
|
629
|
+
|
|
454
630
|
describe("spec gate", () => {
|
|
455
631
|
const gate = (h: Harness) => h.gates.find((entry) => entry.name === "spec");
|
|
456
632
|
|
|
@@ -22,7 +22,13 @@ import { readFileSync } from "node:fs";
|
|
|
22
22
|
import { isAbsolute, relative, resolve } from "node:path";
|
|
23
23
|
import { getAgentDir } from "@earendil-works/pi-coding-agent";
|
|
24
24
|
import { Type } from "typebox";
|
|
25
|
-
import type {
|
|
25
|
+
import type {
|
|
26
|
+
ExtensionAPI,
|
|
27
|
+
ExtensionContext,
|
|
28
|
+
InputEvent,
|
|
29
|
+
InputEventResult,
|
|
30
|
+
ToolCallEvent,
|
|
31
|
+
} from "@earendil-works/pi-coding-agent";
|
|
26
32
|
import type { GateHub } from "../../lib/gates.js";
|
|
27
33
|
import { getPermissionControl, type PermissionSnapshot } from "../../lib/permission-control.js";
|
|
28
34
|
import { getAskControl } from "../../lib/ask-control.js";
|
|
@@ -33,7 +39,12 @@ import { canonicalize, isWithin } from "../permission/paths.js";
|
|
|
33
39
|
import { parseCommandUnits } from "../permission/units.js";
|
|
34
40
|
import { buildFeedbackMarkdown } from "./feedback.js";
|
|
35
41
|
import { openInBrowser } from "../../lib/opener.js";
|
|
36
|
-
import {
|
|
42
|
+
import {
|
|
43
|
+
buildSpecKickoff,
|
|
44
|
+
buildSpecKickoffFromBrief,
|
|
45
|
+
buildSpecSystemPrompt,
|
|
46
|
+
specTitleFromBrief,
|
|
47
|
+
} from "./prompt.js";
|
|
37
48
|
import { renderBlockHtml } from "../review-page/render.js";
|
|
38
49
|
import { buildSpecState, startSpecServer, type SpecServerHandle } from "./server.js";
|
|
39
50
|
import {
|
|
@@ -114,6 +125,12 @@ export function registerSpec(pi: ExtensionAPI, gates: GateHub, options: SpecOpti
|
|
|
114
125
|
let cwd = process.cwd();
|
|
115
126
|
let ctxRef: ExtensionContext | undefined;
|
|
116
127
|
let specSessionId: string | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* The bare command arms the phase instead of starting it: the requirement is
|
|
130
|
+
* a message the operator has not typed yet. Until it arrives the phase is off
|
|
131
|
+
* (no gates, no tools, no permission change) — only this flag is set.
|
|
132
|
+
*/
|
|
133
|
+
let armedForBrief = false;
|
|
117
134
|
|
|
118
135
|
function closeServer(): void {
|
|
119
136
|
if (!server) return;
|
|
@@ -160,6 +177,54 @@ export function registerSpec(pi: ExtensionAPI, gates: GateHub, options: SpecOpti
|
|
|
160
177
|
return { handle, started: true };
|
|
161
178
|
}
|
|
162
179
|
|
|
180
|
+
/** Target file and kickoff for a brief that arrives as a message. */
|
|
181
|
+
function briefPlan(brief: string): { path: string; kickoff: string } {
|
|
182
|
+
const path = `specs/${specSlug(specTitleFromBrief(brief))}.md`;
|
|
183
|
+
return { path, kickoff: buildSpecKickoffFromBrief(brief, path) };
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Turn spec review on. Shared by both entries: `/ask-spec <topic>` and the
|
|
188
|
+
* armed bare command whose brief arrives as the next message. Sending the
|
|
189
|
+
* kickoff stays with the caller — the two paths deliver it differently (a new
|
|
190
|
+
* message vs. the transformed input that is already on its way).
|
|
191
|
+
*/
|
|
192
|
+
function enterPhase(target: ExtensionContext, plan: { path: string; kickoff: string }): void {
|
|
193
|
+
// Entering through a topic replaces a pending bare-command brief. Leaving
|
|
194
|
+
// the flag set would make `off` cancel the wait instead of the active
|
|
195
|
+
// phase, and would consume a later, unrelated message as another brief.
|
|
196
|
+
armedForBrief = false;
|
|
197
|
+
const readiness = frameworkReadiness(resolveProjectRoot(cwd));
|
|
198
|
+
if (!readiness.ready) {
|
|
199
|
+
target.ui.notify(
|
|
200
|
+
`ask-spec: no complete agent framework (missing: ${readiness.missing.join(", ")}). The spec still works, but record_change and /ask-uat stay unavailable until /ask-init.`,
|
|
201
|
+
"info",
|
|
202
|
+
);
|
|
203
|
+
}
|
|
204
|
+
specPath = plan.path;
|
|
205
|
+
session = undefined;
|
|
206
|
+
specSessionId = sessionIdOf(target);
|
|
207
|
+
const permission = getPermissionControl();
|
|
208
|
+
permissionBefore = permission?.snapshot();
|
|
209
|
+
permission?.enableDefaults(target);
|
|
210
|
+
permissionDuring = permission?.snapshot();
|
|
211
|
+
// Spec mode is intentionally less restrictive than ask mode. Let ask
|
|
212
|
+
// restore its own tool snapshot before we add spec_submit.
|
|
213
|
+
if (getAskControl()?.isActive()) getAskControl()?.exit(target);
|
|
214
|
+
active = true;
|
|
215
|
+
pi.setActiveTools(toolSetWithSubmit());
|
|
216
|
+
target.ui.notify(
|
|
217
|
+
`ask-spec: reviewing. Write the spec to ${plan.path}, then call ${SPEC_SUBMIT_TOOL}.`,
|
|
218
|
+
"info",
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/** True only for a command the host actually knows, not any `/path`-like text. */
|
|
223
|
+
function isRegisteredCommand(text: string): boolean {
|
|
224
|
+
const name = /^\/([^\s]+)/.exec(text)?.[1];
|
|
225
|
+
return name !== undefined && pi.getCommands().some((command) => command.name === name);
|
|
226
|
+
}
|
|
227
|
+
|
|
163
228
|
function toolSetWithSubmit(): string[] {
|
|
164
229
|
const tools = pi
|
|
165
230
|
.getActiveTools()
|
|
@@ -258,13 +323,18 @@ export function registerSpec(pi: ExtensionAPI, gates: GateHub, options: SpecOpti
|
|
|
258
323
|
|
|
259
324
|
const specCommand = {
|
|
260
325
|
description:
|
|
261
|
-
"Spec first: research, write a spec, review it in the browser with block annotations, then implement after approval.
|
|
326
|
+
"Spec first: research, write a spec, review it in the browser with block annotations, then implement after approval. Without arguments it arms the phase and your next message (multi-line paste included) becomes the brief; run the bare command again or use `off` to leave or cancel, and `open` re-opens the review.",
|
|
262
327
|
handler: async (args: string, ctx: ExtensionContext) => {
|
|
263
328
|
const arg = args.trim();
|
|
264
329
|
ctxRef = ctx;
|
|
265
330
|
cwd = canonicalize(ctx.cwd || process.cwd());
|
|
266
331
|
|
|
267
332
|
if (arg === "off") {
|
|
333
|
+
if (armedForBrief) {
|
|
334
|
+
armedForBrief = false;
|
|
335
|
+
ctx.ui.notify("ask-spec: pending requirement cancelled.", "info");
|
|
336
|
+
return;
|
|
337
|
+
}
|
|
268
338
|
if (!active) {
|
|
269
339
|
ctx.ui.notify("ask-spec: not in spec mode.", "info");
|
|
270
340
|
return;
|
|
@@ -312,35 +382,75 @@ export function registerSpec(pi: ExtensionAPI, gates: GateHub, options: SpecOpti
|
|
|
312
382
|
return;
|
|
313
383
|
}
|
|
314
384
|
|
|
315
|
-
|
|
316
|
-
|
|
385
|
+
// Bare command: arm and wait for the brief instead of starting from a
|
|
386
|
+
// topic that has to be squeezed onto the command line. A pasted
|
|
387
|
+
// multi-paragraph requirement is the whole point of this entry.
|
|
388
|
+
if (arg === "") {
|
|
389
|
+
if (armedForBrief) {
|
|
390
|
+
armedForBrief = false;
|
|
391
|
+
ctx.ui.notify("ask-spec: pending requirement cancelled.", "info");
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
armedForBrief = true;
|
|
317
395
|
ctx.ui.notify(
|
|
318
|
-
|
|
396
|
+
"ask-spec: armed — send the requirement as your next message (multi-line and pasted text are fine); spec review starts from it. /ask-spec again cancels.",
|
|
319
397
|
"info",
|
|
320
398
|
);
|
|
399
|
+
return;
|
|
321
400
|
}
|
|
322
401
|
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
specSessionId = sessionIdOf(ctx);
|
|
327
|
-
const permission = getPermissionControl();
|
|
328
|
-
permissionBefore = permission?.snapshot();
|
|
329
|
-
permission?.enableDefaults(ctx);
|
|
330
|
-
permissionDuring = permission?.snapshot();
|
|
331
|
-
// Spec mode is intentionally less restrictive than ask mode. Let ask
|
|
332
|
-
// restore its own tool snapshot before we add spec_submit.
|
|
333
|
-
if (getAskControl()?.isActive()) getAskControl()?.exit(ctx);
|
|
334
|
-
active = true;
|
|
335
|
-
pi.setActiveTools(toolSetWithSubmit());
|
|
336
|
-
ctx.ui.notify(
|
|
337
|
-
`ask-spec: reviewing. Write the spec to ${specPath}, then call ${SPEC_SUBMIT_TOOL}.`,
|
|
338
|
-
"info",
|
|
339
|
-
);
|
|
340
|
-
pi.sendUserMessage(buildSpecKickoff(arg || undefined));
|
|
402
|
+
const plan = { path: `specs/${specSlug(arg)}.md`, kickoff: buildSpecKickoff(arg) };
|
|
403
|
+
enterPhase(ctx, plan);
|
|
404
|
+
pi.sendUserMessage(plan.kickoff);
|
|
341
405
|
},
|
|
342
406
|
};
|
|
343
407
|
|
|
408
|
+
/**
|
|
409
|
+
* The armed bare command: the next message is the brief.
|
|
410
|
+
*
|
|
411
|
+
* The input runs before the model sees anything, so the phase is turned on
|
|
412
|
+
* here — `before_agent_start` then injects the spec banner and re-asserts the
|
|
413
|
+
* tool set for this very turn — and the message is transformed into the
|
|
414
|
+
* kickoff with the requirement embedded verbatim. Nothing is dropped or sent
|
|
415
|
+
* twice: it is still the operator's one message.
|
|
416
|
+
*
|
|
417
|
+
* Commands and extension-dispatched messages are not the brief: built-in
|
|
418
|
+
* slash commands never reach here, but a registered `/cmd` can, and
|
|
419
|
+
* autostart sends its whole list through `sendUserMessage` with source
|
|
420
|
+
* `extension` — neither should be eaten as a requirement.
|
|
421
|
+
*/
|
|
422
|
+
pi.on("input", (event: InputEvent, ctx: ExtensionContext): InputEventResult | undefined => {
|
|
423
|
+
if (!armedForBrief || active) return undefined;
|
|
424
|
+
if (event.source === "extension") return undefined;
|
|
425
|
+
const brief = event.text.trim();
|
|
426
|
+
if (brief === "" || isRegisteredCommand(brief)) return undefined;
|
|
427
|
+
// The command enforces these before arming, but either state can change
|
|
428
|
+
// while the operator is composing the brief. Re-check at the moment the
|
|
429
|
+
// phase would really start: entering during a stream would mutate the
|
|
430
|
+
// current run's tools, and entering over UAT would stack the two phases.
|
|
431
|
+
if (event.streamingBehavior !== undefined || !ctx.isIdle()) {
|
|
432
|
+
armedForBrief = false;
|
|
433
|
+
ctx.ui.notify(
|
|
434
|
+
"ask-spec: the agent is still running — pending requirement cancelled; finish or abort first.",
|
|
435
|
+
"warning",
|
|
436
|
+
);
|
|
437
|
+
return undefined;
|
|
438
|
+
}
|
|
439
|
+
if (pi.getActiveTools().includes(UAT_PHASE_TOOL)) {
|
|
440
|
+
armedForBrief = false;
|
|
441
|
+
ctx.ui.notify(
|
|
442
|
+
"ask-spec: ask-uat is open — pending requirement cancelled; /ask-uat off first.",
|
|
443
|
+
"warning",
|
|
444
|
+
);
|
|
445
|
+
return undefined;
|
|
446
|
+
}
|
|
447
|
+
ctxRef = ctx;
|
|
448
|
+
cwd = canonicalize(ctx.cwd || process.cwd());
|
|
449
|
+
const plan = briefPlan(brief);
|
|
450
|
+
enterPhase(ctx, plan);
|
|
451
|
+
return { action: "transform", text: plan.kickoff };
|
|
452
|
+
});
|
|
453
|
+
|
|
344
454
|
// One name only. The pre-rename `/ask-plan` alias was removed 2026-11-27
|
|
345
455
|
// (it had been undocumented since the rename; autostart entries still
|
|
346
456
|
// spelled that way are skipped by the pre-flight and reported, so they are
|
|
@@ -500,6 +610,7 @@ export function registerSpec(pi: ExtensionAPI, gates: GateHub, options: SpecOpti
|
|
|
500
610
|
});
|
|
501
611
|
|
|
502
612
|
pi.on("session_shutdown", () => {
|
|
613
|
+
armedForBrief = false;
|
|
503
614
|
closeServer();
|
|
504
615
|
});
|
|
505
616
|
|
|
@@ -510,6 +621,7 @@ export function registerSpec(pi: ExtensionAPI, gates: GateHub, options: SpecOpti
|
|
|
510
621
|
// or permission snapshot. Permission's own session_start has already reset
|
|
511
622
|
// its state, so do not restore the old snapshot here.
|
|
512
623
|
active = false;
|
|
624
|
+
armedForBrief = false;
|
|
513
625
|
session = undefined;
|
|
514
626
|
permissionBefore = undefined;
|
|
515
627
|
permissionDuring = undefined;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { describe, expect, it } from "vitest";
|
|
2
2
|
import {
|
|
3
3
|
buildSpecKickoff,
|
|
4
|
+
buildSpecKickoffFromBrief,
|
|
4
5
|
buildSpecSystemPrompt,
|
|
5
6
|
INTERVIEW_GUIDE,
|
|
6
7
|
SPEC_MODE_BANNER,
|
|
7
8
|
SPEC_FRAMEWORK_GUIDE,
|
|
9
|
+
specTitleFromBrief,
|
|
8
10
|
} from "./prompt.js";
|
|
9
11
|
|
|
10
12
|
describe("spec review prompt", () => {
|
|
@@ -89,3 +91,21 @@ describe("buildSpecKickoff", () => {
|
|
|
89
91
|
expect(buildSpecKickoff(" ")).toContain("the work we have been discussing in this session");
|
|
90
92
|
});
|
|
91
93
|
});
|
|
94
|
+
|
|
95
|
+
describe("brief-shaped kickoff", () => {
|
|
96
|
+
it("keeps the requirement byte for byte, blank lines and lists included", () => {
|
|
97
|
+
const brief = "Renew the watcher\n\nWhy: the current one drops events.\n\n- keep the API\n- add a test";
|
|
98
|
+
const kickoff = buildSpecKickoffFromBrief(brief, "specs/renew-the-watcher.md");
|
|
99
|
+
expect(kickoff).toContain(brief);
|
|
100
|
+
expect(kickoff).toContain("Target file: `specs/renew-the-watcher.md`");
|
|
101
|
+
expect(kickoff).toContain("Do not implement anything yet.");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("takes the file title from the first real line", () => {
|
|
105
|
+
expect(specTitleFromBrief("## Add a queue\n\ndetail")).toBe("Add a queue");
|
|
106
|
+
expect(specTitleFromBrief("\n\n 1. Fix the export\nmore")).toBe("Fix the export");
|
|
107
|
+
expect(specTitleFromBrief("```ts\nconst a = 1;\n```\nTop level ask")).toBe("Top level ask");
|
|
108
|
+
expect(specTitleFromBrief("### ")).toBe("spec");
|
|
109
|
+
expect(specTitleFromBrief(" ")).toBe("spec");
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -108,3 +108,49 @@ export function buildSpecKickoff(topic: string | undefined): string {
|
|
|
108
108
|
"submit it with spec_submit. Do not implement anything yet.",
|
|
109
109
|
].join("\n");
|
|
110
110
|
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* First line of a message-shaped brief, stripped of markdown markers, for the
|
|
114
|
+
* default file name. A requirement usually opens with the line that names the
|
|
115
|
+
* work; the rest is detail that makes a poor file name and would be truncated
|
|
116
|
+
* anyway.
|
|
117
|
+
*/
|
|
118
|
+
export function specTitleFromBrief(brief: string): string {
|
|
119
|
+
let inFence = false;
|
|
120
|
+
for (const raw of brief.split(/\r?\n/)) {
|
|
121
|
+
const line = raw.trim();
|
|
122
|
+
if (line.startsWith("```") || line.startsWith("~~~")) {
|
|
123
|
+
inFence = !inFence;
|
|
124
|
+
continue;
|
|
125
|
+
}
|
|
126
|
+
if (inFence || line === "") continue;
|
|
127
|
+
const stripped = line
|
|
128
|
+
.replace(/^#{1,6}\s*/, "")
|
|
129
|
+
.replace(/^([-*+>]|\d+[.)])\s+/, "")
|
|
130
|
+
.trim();
|
|
131
|
+
// A line that is nothing but list/quote markers names nothing.
|
|
132
|
+
if (stripped === "" || /^[-*+>#]+$/.test(stripped)) continue;
|
|
133
|
+
return stripped;
|
|
134
|
+
}
|
|
135
|
+
return "spec";
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Kickoff for the armed bare command. Here the requirement is the operator's
|
|
140
|
+
* whole message, so it is embedded verbatim instead of being compressed into a
|
|
141
|
+
* one-line topic: the point of that entry is that a long, pasted, multi-paragraph
|
|
142
|
+
* brief arrives intact.
|
|
143
|
+
*/
|
|
144
|
+
export function buildSpecKickoffFromBrief(brief: string, specPath: string): string {
|
|
145
|
+
return [
|
|
146
|
+
"Start spec review.",
|
|
147
|
+
`Target file: \`${specPath}\`.`,
|
|
148
|
+
"",
|
|
149
|
+
"## Operator's requirement",
|
|
150
|
+
"",
|
|
151
|
+
brief.trim(),
|
|
152
|
+
"",
|
|
153
|
+
"Explore the code before writing, ask me what you cannot infer, then write the spec file and",
|
|
154
|
+
"submit it with spec_submit. Do not implement anything yet.",
|
|
155
|
+
].join("\n");
|
|
156
|
+
}
|
|
@@ -21,8 +21,8 @@ import type { KeyId } from "@earendil-works/pi-tui";
|
|
|
21
21
|
/**
|
|
22
22
|
* Stash hotkey.
|
|
23
23
|
*
|
|
24
|
-
* Compatibility rationale (
|
|
25
|
-
* matchesKey probes and terminal/OS behavior):
|
|
24
|
+
* Compatibility rationale (keybinding tables audited across pi 1.0.0–1.7.0;
|
|
25
|
+
* matchesKey probes and terminal/OS behavior verified separately):
|
|
26
26
|
* - pi: no default binding for ctrl+alt+<letter> (only ctrl+alt+] is taken);
|
|
27
27
|
* extension shortcuts dispatch first while the editor is focused
|
|
28
28
|
* - terminals: alt encodes as ESC-prefix, so ctrl+alt+y arrives as "\x1b\x19"
|
package/src/lib/gates.ts
CHANGED
|
@@ -18,9 +18,9 @@
|
|
|
18
18
|
* promise. The queue serializes our own presentations; the host slot is
|
|
19
19
|
* still shared with other extensions (pi does not arbitrate globally).
|
|
20
20
|
* pi 1.4.0 stacks extension dialogs so a second one no longer strands the
|
|
21
|
-
* first (#11166), but the 1.2–1.3 hosts
|
|
22
|
-
* replace it — the queue stays, and it also keeps one confirmation
|
|
23
|
-
* at a time instead of a pile of stacked dialogs on later hosts.
|
|
21
|
+
* first (#11166), but the 1.2–1.3 hosts covered by the declared floor
|
|
22
|
+
* still replace it — the queue stays, and it also keeps one confirmation
|
|
23
|
+
* visible at a time instead of a pile of stacked dialogs on later hosts.
|
|
24
24
|
* - A gate that throws blocks the call (fail closed), matching pi's own
|
|
25
25
|
* `tool_call` handler contract.
|
|
26
26
|
*
|