pi-odd-worktree 3.3.0 → 3.5.0
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 +6 -2
- package/extensions/odd-worktree-tools.ts +39 -0
- package/lib/bash-design.js +8 -2
- package/lib/depth-launch.js +70 -0
- package/lib/depth-prompt/depth.md +53 -0
- package/lib/depth-task.js +76 -0
- package/lib/file-card-resolver.js +4 -0
- package/lib/file-card.js +8 -0
- package/lib/jobs-card-resolver.js +139 -0
- package/lib/jobs-card.js +220 -0
- package/package.json +1 -1
- package/tools/bash-design.test.js +8 -8
- package/tools/depth-command.test.js +66 -0
- package/tools/depth-launch.test.js +123 -0
- package/tools/depth-task.test.js +76 -0
- package/tools/files-bridge.test.js +2 -2
- package/tools/files-command.test.js +1 -1
- package/tools/jobs-card.test.js +292 -0
- package/tools/package-surface.test.js +2 -2
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ A Pi extension that gives an agent session worktrees, ODD documents and GitHub i
|
|
|
4
4
|
|
|
5
5
|
## What It Does
|
|
6
6
|
|
|
7
|
-
Two agent tools, four panels, one sidebar section and two tool designs, loaded from one extension entry point. Each ODD feature gets its own checkout beside the clone, and you move between checkouts and read your ODD documents, files and issues without leaving Pi.
|
|
7
|
+
Two agent tools, four panels, one background-explorer command, one sidebar section and two tool designs, loaded from one extension entry point. Each ODD feature gets its own checkout beside the clone, and you move between checkouts and read your ODD documents, files and issues without leaving Pi.
|
|
8
8
|
|
|
9
9
|
| Surface | Kind | What it does |
|
|
10
10
|
| --- | --- | --- |
|
|
@@ -14,6 +14,7 @@ Two agent tools, four panels, one sidebar section and two tool designs, loaded f
|
|
|
14
14
|
| `/odd` | panel | Reads this checkout's `odd/tasks/*.md`: list on the left, styled markdown on the right. |
|
|
15
15
|
| `/files` | panel | Browses one checkout's files with a live, language-coloured preview: `enter` pastes the chosen paths into your prompt, `ctrl+e` opens the file in `$EDITOR`. |
|
|
16
16
|
| `/issues` | panel | Reads this checkout's GitHub issues — the three scoped tabs on open, every open issue behind `g` — and, when your role allows it, edits them. |
|
|
17
|
+
| `/depth` | command | Takes a request you type and starts one background `gentle-ai-explore` on it: what a top professional would do that you did not ask for, the raw material, the methods, and what outside the model would prove the result. The handoff — your request verbatim, how it was understood, a `path:line` map, proposals kept apart from the request, how it would be verified — arrives in the session. Edit its instructions in `lib/depth-prompt/depth.md`. |
|
|
17
18
|
| `GITHUB` rail section | sidebar section | Lists the open issues of this checkout's repository assigned to you, seven at a time plus a count of the rest; a click opens that issue in `/issues` on `Assigned` and the overflow row opens `/issues`. Needs `gh` and gentle-shell-bridge with its rail; without `gh` on `PATH` it is never added to the rail at all. |
|
|
18
19
|
| `activity` tags design | design on the bridge's `Card tags` line | Optional: `/gentle:customize` → `Cards` → `Card tags`, with `default` (the host's own card) and `activity`, which is selected for you on the first run. It covers `bash`, the read-only shell tools `grep`, `find`, `ls`, and `read`, `write` and `edit`: a bash card's heading names what the command does, each family in its own theme colour (`⌕ exploring`, `✓ checking`, …; an unnamed command reads `$ bash`), those three are always `⌕ exploring`, and a `read` — which runs no shell command — is left exactly as the host drew it. `read`, `write` and `edit` are covered so that the file card can ask about them too, `write` and `edit` through a scope limited to skill and ODD paths (gentle-shell-bridge 0.9.0): the design draws nothing of its own for any of the three, so a read, a write or an edit on a skill or an ODD artifact is the file card's row and everything else stays the host's. A finished call shows its duration on the closing rule and the frame turns `warning` while the call runs and `error` when it fails. Needs gentle-shell-bridge 0.6.0 or newer for the one `Card tags` row over the six tools, and 0.9.0 for `edit` and the scope that claims a write or an edit; on 0.5.0 the row is `Card bash`, covers bash alone and keeps everything above for bash cards. Registered through gentle-shell-bridge's `registerToolDesign`; the bridge owns the choice, remembers it and repaints cards already on screen. |
|
|
19
20
|
| `color` diff design | design on the bridge's `Card diff` line | Optional: `/gentle:customize` → `Cards` → `Card diff`, with `default` (the host's own card) and `color`, which is selected for you on the first run. It covers `write` and `edit` and redraws them as an IDE pane: a write's content behind a line-number gutter, and an edit's diff, both in the active theme's own syntax roles from Pi's highlighter — the same one `/files` previews with. A write or an edit on a skill or an ODD artifact stays the file card's row, because the `Card tags` line claims exactly those calls and a specific claim wins over this generic one. Needs gentle-shell-bridge 0.9.0 or newer; on anything older nothing is registered and `Card diff` never appears. |
|
|
@@ -26,6 +27,8 @@ The diff card is a design of the same kind, on a line of its own: `Card diff`, w
|
|
|
26
27
|
|
|
27
28
|
The file cards are not a preference of this package either: they belong to that same `activity` value. While the bridge answers that `activity` draws the tool being painted, a `read`, `edit` or `write` call on a skill or an ODD artifact heads as that file — its own mark and label, the tool, the path and a read's line range, each in the theme role the reference design gives it — instead of a bare tool row, and its Markdown body is drawn by Pi's own renderer with the theme's Markdown roles. Choosing `default` on `Card tags`, or any other design on that line, gives every one of those calls back to the host. The question is asked of the bridge on every paint, so a mid-session switch repaints cards already on screen, and a bridge older than 0.7.0 — which cannot answer it — keeps the card it always had. See [the file cards](docs/reference.md#the-file-cards).
|
|
28
29
|
|
|
30
|
+
The jobs card follows the same value. Gentle Shell registers `bash_background`, `monitor`, `job_stop` and `job_list` with no renderer of their own, so Pi draws them in a plain box and neither `neon` nor `float` ever reaches them. While the bridge answers that `activity` draws the tool being painted, they are drawn on the same card substrate in the style the shell has chosen: the job's mark and name (its label, else the first line of its command), the whole command when expanded, and the job's own answer below. Under the `minimal` card content level the call is drawn alone, and a failure still says why. Any other answer on `Card tags`, no bridge, or a bridge older than 0.7.0 leaves Pi's own box exactly as it was. Unlike the file cards, the answer is read when a job card is built, because there is no host drawing to hand back on a later paint: a switch made mid-session reaches the next job card. See [the jobs card](docs/reference.md#the-jobs-card).
|
|
31
|
+
|
|
29
32
|
## Quick Start
|
|
30
33
|
|
|
31
34
|
| Requirement | Why it is needed |
|
|
@@ -47,7 +50,7 @@ gentle-shell install npm:pi-odd-worktree
|
|
|
47
50
|
|
|
48
51
|
From a local clone, `pi install .` installs the working copy, and `gentle-shell install .` does the same from inside a Gentle Shell session.
|
|
49
52
|
|
|
50
|
-
Expected result: `/warp`, `/odd`, `/files` and `/
|
|
53
|
+
Expected result: `/warp`, `/odd`, `/files`, `/issues` and `/depth` are available as commands — `/issues` only where `gh` is on `PATH` — the agent is offered `worktree_create` and `worktree_list`, a Gentle Shell whose `gentle-shell-bridge` is installed and whose rail is drawn shows a `GITHUB` section for this checkout, and its `/gentle:customize` → `Cards` page offers `activity` on its `Card tags` line — `Card bash` on a bridge older than 0.6.0.
|
|
51
54
|
|
|
52
55
|
## Core Workflow
|
|
53
56
|
|
|
@@ -71,6 +74,7 @@ The full rules of each step, including every refusal, are in [Create, list, move
|
|
|
71
74
|
- **Cards follow your shell.** Tool and warp cards use the card style Gentle Shell publishes, and a click expands that card only. See [card style](docs/reference.md#card-style-follows-your-shell).
|
|
72
75
|
- **Tool headings can name the activity.** With `activity` chosen on the `Card tags` line, a bash card whose heading shows the whole command is headed with the family its command names (mark and word) instead of `$`, and a `grep`, `find` or `ls` card is headed `⌕ exploring` instead of its own glyph and name, while a `read` — which runs no shell command — keeps the host's own card, colour and width; a bash command the classifier cannot name, or a heading that hides part of it, keeps the host's `$`. See [the cards the `activity` design paints](docs/reference.md#the-cards-the-activity-design-paints).
|
|
73
76
|
- **File calls on a skill or an ODD are cards too.** While `Card tags` answers with `activity` for the tool being painted, a `read`, `edit` or `write` call whose path names a skill (anything below a `skills` folder) or an ODD (anything below an `odd` folder) heads as that file, with the tool, the path and a read's line range; its Markdown body — the whole document when expanded, the first rows when collapsed — is drawn by Pi's own renderer in the theme's Markdown roles, and an edit always keeps its diff. Any other file call, and every call while that line answers anything else, is the host's own row. See [the file cards](docs/reference.md#the-file-cards).
|
|
77
|
+
- **Background-job tools are cards too.** While `Card tags` answers with `activity` for the tool being painted, `bash_background`, `monitor`, `job_stop` and `job_list` are drawn in the shell's own card style instead of Pi's plain box. Any other answer leaves Pi's box untouched. See [the jobs card](docs/reference.md#the-jobs-card).
|
|
74
78
|
- **`edit` and `write` cannot land in the principal checkout's default branch.** A write whose path is inside the principal checkout of the session's repository, while that checkout is on the default branch, is refused with one line pointing at `worktree_list` and `worktree_create`. Paths outside the repository, anything under the OS temp directories, other repositories and linked worktrees are never blocked. See [the guard](docs/reference.md#the-edit-and-write-guard).
|
|
75
79
|
- **`bash` cannot leave the principal checkout's default branch.** A `git worktree add` or `git worktree list` is refused in any cwd and pointed at `worktree_create` and `worktree_list`; in the principal checkout, a switch that would leave the branch it is on is refused while that branch is the repository's default, and creating a branch is not blocked. See [the guards](docs/reference.md#the-bash-guards).
|
|
76
80
|
- **Two blocks in the system prompt.** `## ODD worktrees` tells the agent how worktrees and ODDs work. `## CodeGraph` tells a session that already holds a CodeGraph tool how to use it, with one text per role. Both are appended after the host's own text, and `ODD_WORKTREE_PROMPT=0` suppresses them. See [the prompt blocks](docs/reference.md#the--odd-worktrees-block-in-the-system-prompt).
|
|
@@ -6815,6 +6815,33 @@ function registerOddCommand(pi) {
|
|
|
6815
6815
|
});
|
|
6816
6816
|
}
|
|
6817
6817
|
|
|
6818
|
+
// ---------------------------------------------------------------------------
|
|
6819
|
+
// `/depth <request>` (depth-command S1-S8): the fifth command. It starts ONE background
|
|
6820
|
+
// `gentle-ai-explore` through the host's own `subagent_run` tool, with the Depth
|
|
6821
|
+
// instructions of `lib/depth-prompt/depth.md` and the request verbatim, and answers with
|
|
6822
|
+
// one notice. Everything after the start is gentle-agents' — the progress, the cancel and
|
|
6823
|
+
// the handoff that lands in the session — so the command draws nothing, keeps no state,
|
|
6824
|
+
// registers no key and spawns no child of its own (`lib/depth-launch.js`).
|
|
6825
|
+
// ---------------------------------------------------------------------------
|
|
6826
|
+
|
|
6827
|
+
function registerDepthCommand(pi) {
|
|
6828
|
+
if (typeof pi?.registerCommand !== "function") return;
|
|
6829
|
+
pi.registerCommand("depth", {
|
|
6830
|
+
description: "Understand a request in depth and explore it in the background; the handoff arrives in this session",
|
|
6831
|
+
handler: async (args, ctx) => {
|
|
6832
|
+
let outcome;
|
|
6833
|
+
try {
|
|
6834
|
+
outcome = await libRequire("depth-launch.js").launchDepth(typeof args === "string" ? args : "", ctx);
|
|
6835
|
+
} catch (error) {
|
|
6836
|
+
outcome = { level: "error", message: `/depth failed: ${error instanceof Error ? error.message : String(error)}` };
|
|
6837
|
+
}
|
|
6838
|
+
try {
|
|
6839
|
+
if (ctx && ctx.ui && typeof ctx.ui.notify === "function") ctx.ui.notify(outcome.message, outcome.level);
|
|
6840
|
+
} catch {}
|
|
6841
|
+
},
|
|
6842
|
+
});
|
|
6843
|
+
}
|
|
6844
|
+
|
|
6818
6845
|
// ---------------------------------------------------------------------------
|
|
6819
6846
|
// `/files` (T7: S9, S14, S17): the file picker over one checkout of this clone.
|
|
6820
6847
|
//
|
|
@@ -9738,6 +9765,8 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
9738
9765
|
// picker's — bound after its command exists, and therefore never when the
|
|
9739
9766
|
// `gh`-absent gate left that command unregistered.
|
|
9740
9767
|
bindIssuesShortcut(pi);
|
|
9768
|
+
// depth-command S6: the fifth command, `/depth`.
|
|
9769
|
+
registerDepthCommand(pi);
|
|
9741
9770
|
pi.registerTool(worktreeCreateTool);
|
|
9742
9771
|
pi.registerTool(worktreeListTool);
|
|
9743
9772
|
if (typeof pi?.on !== "function") return;
|
|
@@ -9979,6 +10008,16 @@ function registerOddWorktreeSurfaceEntries(pi) {
|
|
|
9979
10008
|
} catch {
|
|
9980
10009
|
// The card is cosmetic.
|
|
9981
10010
|
}
|
|
10011
|
+
// The jobs card, through the same host hook: `bash_background`, `monitor`, `job_stop` and
|
|
10012
|
+
// `job_list` have no renderer of their own, so Pi draws a plain box and the conversation's
|
|
10013
|
+
// card style never reaches them. While the bridge's `Card tags` line answers with this
|
|
10014
|
+
// package's activity design for the tool, they are drawn on the card substrate in the
|
|
10015
|
+
// shell's own style; any other answer leaves Pi's drawing exactly as it was.
|
|
10016
|
+
try {
|
|
10017
|
+
libRequire("jobs-card-resolver.js").registerJobsCard(pi, { metrics: () => resolveWorktreeToolCardMetrics() });
|
|
10018
|
+
} catch {
|
|
10019
|
+
// The card is cosmetic.
|
|
10020
|
+
}
|
|
9982
10021
|
// The live-checkout scan is DISPATCHED and never awaited. Its only product is
|
|
9983
10022
|
// `warpDiscoveryCache`, which nothing reads — every warp lists fresh before
|
|
9984
10023
|
// acting — so the old "startup barrier" awaited three git reads for a result the
|
package/lib/bash-design.js
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// `/gentle:customize` → `Cards` (`default` | `activity`), it is read on every paint so cards
|
|
13
13
|
// already on screen repaint when it changes, and extension load order does not matter.
|
|
14
14
|
//
|
|
15
|
-
// ONE line covers
|
|
15
|
+
// ONE line covers eleven tools. `bash`'s heading names what its command does; the three read-only
|
|
16
16
|
// shell tools the line covers (`grep`, `find`, `ls`) only ever read, so their heading is always
|
|
17
17
|
// `exploring` whatever their arguments are. `read`, `write` and `edit` are declared for a different reason:
|
|
18
18
|
// the file card is painted only while the bridge's line resolves to this design for the tool being
|
|
@@ -46,6 +46,9 @@ const { SHELL_ACTIVITY_IDENTITY, inferBashActivity } = require('./bash-activity.
|
|
|
46
46
|
// S6: the file card's own identity rule, reused and never copied — a path it claims is
|
|
47
47
|
// the file card's row, so this design must leave it alone.
|
|
48
48
|
const { fileCardIdentity, FILE_CARD_TOOLS } = require('./skill-odd-card.js');
|
|
49
|
+
// The four background-job tools: the jobs card (`lib/jobs-card.js`) draws them, and it is painted
|
|
50
|
+
// only while this line answers that this design draws the tool being drawn.
|
|
51
|
+
const { JOB_TOOLS } = require('./jobs-card.js');
|
|
49
52
|
const { cardElapsed, charColumns, elapsedRow, paintFrame, rowColumns, sgrBefore, textColumns, visibleChars } = require('./bash-frame.js');
|
|
50
53
|
|
|
51
54
|
const TOOL_NAME = 'bash';
|
|
@@ -105,7 +108,10 @@ const WRITE_TOOL = 'write';
|
|
|
105
108
|
const EDIT_TOOL = 'edit';
|
|
106
109
|
// The tools of the line, in the order they have always been declared; the scoped shape appends the
|
|
107
110
|
// tool that only a scoped claim can carry.
|
|
108
|
-
|
|
111
|
+
// The background-job tools are declared for the same reason as `read` and `write`: the jobs card is the
|
|
112
|
+
// only surface that draws them, and it is painted only while this line resolves to this design for them.
|
|
113
|
+
// `computeActivity` knows no mark for them, so the design itself returns their rows exactly as drawn.
|
|
114
|
+
const LINE_TOOLS = [TOOL_NAME, ...READ_TOOL_GLYPHS.keys(), READ_TOOL, WRITE_TOOL, ...JOB_TOOLS];
|
|
109
115
|
|
|
110
116
|
// The bridge keeps ONE persisted value per tool, in its own store (`bridge-tool-designs` →
|
|
111
117
|
// `selections` → `{ "bash": <design id> }`, documented in the bridge's contract), and one per LINE
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `/depth`'s launch (S4, S5, S8): ONE background `gentle-ai-explore`, started through the host's own `subagent_run` tool
|
|
3
|
+
// with the Depth task of `lib/depth-task.js` and nothing else.
|
|
4
|
+
//
|
|
5
|
+
// Everything after the start belongs to gentle-agents, which this package never imports: it draws the progress, owns the
|
|
6
|
+
// cancel and, when the explorer finishes, sends its answer to the session as a message that starts a turn. So this module
|
|
7
|
+
// has no widget, no timer and no message of its own. It decides whether the launch can happen and answers in one sentence
|
|
8
|
+
// what did or did not.
|
|
9
|
+
//
|
|
10
|
+
// The host API is `ctx.executeTool(name, args)`, which never rejects for a tool failure — an unknown tool, a refused call
|
|
11
|
+
// and a thrown error all come back as `isError: true` — and `ctx.tools`, which lists what it can call (the same contract
|
|
12
|
+
// `lib/session-worktree-register.js` documents). `subagent_run` rejects any key outside its schema, so the arguments are
|
|
13
|
+
// exactly `agent`, `task`, `label` and `mode`.
|
|
14
|
+
//
|
|
15
|
+
// Never throws, never rejects.
|
|
16
|
+
|
|
17
|
+
const { buildDepthTask, depthLabel } = require('./depth-task.js');
|
|
18
|
+
|
|
19
|
+
const DEPTH_AGENT = 'gentle-ai-explore';
|
|
20
|
+
const DEPTH_TOOL = 'subagent_run';
|
|
21
|
+
|
|
22
|
+
function refuse(message) {
|
|
23
|
+
return { ok: false, level: 'error', message };
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function toolAvailable(ctx) {
|
|
27
|
+
try {
|
|
28
|
+
if (!ctx || typeof ctx.executeTool !== 'function') return false;
|
|
29
|
+
const tools = ctx.tools;
|
|
30
|
+
return Array.isArray(tools) && tools.some((tool) => tool && tool.name === DEPTH_TOOL);
|
|
31
|
+
} catch {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The words the host tool answered with, so a refusal reads in its own sentence.
|
|
37
|
+
function outcomeText(outcome) {
|
|
38
|
+
const parts = outcome && Array.isArray(outcome.content) ? outcome.content : [];
|
|
39
|
+
return parts
|
|
40
|
+
.map((part) => (part && part.type === 'text' && typeof part.text === 'string' ? part.text.trim() : ''))
|
|
41
|
+
.filter((text) => text.length > 0)
|
|
42
|
+
.join(' ');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function couldNotStart(detail) {
|
|
46
|
+
return refuse(`/depth couldn't start the explorer: ${detail}`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function launchDepth(request, ctx) {
|
|
50
|
+
const task = buildDepthTask(request);
|
|
51
|
+
if (task === null) {
|
|
52
|
+
return refuse('/depth needs a request: /depth <request>. The explorer does not see this chat, so put everything it needs in the request.');
|
|
53
|
+
}
|
|
54
|
+
if (!toolAvailable(ctx)) {
|
|
55
|
+
return refuse(`/depth starts a ${DEPTH_AGENT} subagent through the ${DEPTH_TOOL} tool, and this session does not offer it.`);
|
|
56
|
+
}
|
|
57
|
+
const label = depthLabel(request);
|
|
58
|
+
let outcome;
|
|
59
|
+
try {
|
|
60
|
+
outcome = await ctx.executeTool(DEPTH_TOOL, { agent: DEPTH_AGENT, task, label, mode: 'background' });
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return couldNotStart(error instanceof Error ? error.message : String(error));
|
|
63
|
+
}
|
|
64
|
+
if (!outcome || outcome.isError === true) {
|
|
65
|
+
return couldNotStart(outcomeText(outcome) || `the ${DEPTH_TOOL} tool reported an error.`);
|
|
66
|
+
}
|
|
67
|
+
return { ok: true, level: 'info', message: `Exploring in the background (${label}). The handoff arrives in this session when it finishes.` };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = { DEPTH_AGENT, DEPTH_TOOL, launchDepth };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
You are doing a Depth pass on the request in `## Request`, the last section of this task. You are read-only, you have no chat history, and you cannot ask the human anything: the request is everything they said. First find and read the code, files, docs and logs it touches, so every answer rests on them.
|
|
2
|
+
|
|
3
|
+
I want a deeper version of this request, not a bigger one. Answer these four questions from what you found, not from what a request like this usually needs:
|
|
4
|
+
|
|
5
|
+
(1) What would a top professional in this field do here that the request does not ask for?
|
|
6
|
+
(2) What is the rawest material they would start from, instead of what has already been digested?
|
|
7
|
+
(3) What specific methods and tools would they use?
|
|
8
|
+
(4) What, other than you or the human, would show the result is right?
|
|
9
|
+
|
|
10
|
+
Take the professional's method, not their voice: do what they do, do not write like them.
|
|
11
|
+
|
|
12
|
+
## How to work
|
|
13
|
+
|
|
14
|
+
1. Read the source, not summaries of it, whenever the source is reachable. Search the project and the paths the request names.
|
|
15
|
+
2. Match the effort to the request. A small, specific request gets a short handoff, a line per section. A section with nothing to say says `none`.
|
|
16
|
+
3. You cannot run commands. Where the raw material needs something to be run (a test, a reproduction, a log), give the exact command and say it was not run. Never claim a result you did not observe.
|
|
17
|
+
4. For (4), name only oracles that something outside you can execute: an existing test, a command, a type check, a file to compare. Cite `path:line` where one exists. "Review it" and "double-check it" are not oracles.
|
|
18
|
+
5. Everything the request does not ask for, which is most of (1) to (3), goes only under `## Not requested`. Tag each item `[evidencia: path:line]` when you found its basis in the project, or `[inferido]` when it is your judgement. These are proposals for the human to accept or drop: never a requirement, and never part of `## Understood`.
|
|
19
|
+
6. `## Understood` adds nothing the request does not say. If the request can reasonably be read two materially different ways, do not pick one silently: say which reading you used there, and put the questions for the human under `## Questions`. Otherwise `## Questions` says `none`.
|
|
20
|
+
|
|
21
|
+
Never carry the request out. Do not edit files or start work; you only read and report.
|
|
22
|
+
|
|
23
|
+
## Return
|
|
24
|
+
|
|
25
|
+
Reply in the language of the request, in at most ~2k tokens. Start with this line, unchanged:
|
|
26
|
+
|
|
27
|
+
**/depth handoff: read-only exploration, nothing was implemented.**
|
|
28
|
+
|
|
29
|
+
Then give exactly these headings, in this order, each alone on its line. Copy each heading character for character: the names stay in English whatever the language of the request, and translating one is an error. Do not drop a section; a section with nothing to say says `none`. The last section, `## For the parent`, is required: without it the main session may start implementing.
|
|
30
|
+
|
|
31
|
+
## Original request
|
|
32
|
+
The text under `## Request`, copied unchanged.
|
|
33
|
+
|
|
34
|
+
## Understood
|
|
35
|
+
The request as you read it, from what you found. Nothing the request does not say.
|
|
36
|
+
|
|
37
|
+
## Questions
|
|
38
|
+
Questions for the human, or `none`.
|
|
39
|
+
|
|
40
|
+
## Map
|
|
41
|
+
The relevant files, symbols and how they relate, each with `path:line`. No file contents.
|
|
42
|
+
|
|
43
|
+
## Not requested
|
|
44
|
+
What a top professional would add or do differently, from (1) to (3), each tagged as rule 5 says.
|
|
45
|
+
|
|
46
|
+
## How it would be verified
|
|
47
|
+
From (4): the external oracles, by rule 4.
|
|
48
|
+
|
|
49
|
+
## Uncertainty
|
|
50
|
+
What you could not settle, and what you did not read.
|
|
51
|
+
|
|
52
|
+
## For the parent
|
|
53
|
+
Copy this paragraph unchanged: Do not implement this request. If `## Questions` is not `none`, ask the human those questions first. Show `## Not requested` to the human and wait for them to accept or drop each item before anything is added to a spec.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The task `/depth` hands the `gentle-ai-explore` subagent (S1, S3, S4, S8).
|
|
3
|
+
//
|
|
4
|
+
// The text is the instructions in `lib/depth-prompt/depth.md` — one Markdown file, so it can be read and edited as
|
|
5
|
+
// prose — followed by the request exactly as the person typed it. The explorer starts with no chat, so the request is
|
|
6
|
+
// the only thing it will ever know of the person's words; the instructions make it the first section of the handoff.
|
|
7
|
+
//
|
|
8
|
+
// The file is read on every call, so an edit applies to the next `/depth` with no reload. A missing or empty file falls
|
|
9
|
+
// back to a short built-in task that still names every return section, the way the prompt blocks of this package fall
|
|
10
|
+
// back to their heading: the command never fails because prose could not be read. Pure apart from that one read, and
|
|
11
|
+
// it never throws.
|
|
12
|
+
|
|
13
|
+
const fs = require('node:fs');
|
|
14
|
+
const path = require('node:path');
|
|
15
|
+
|
|
16
|
+
const DEPTH_FILE = path.join(__dirname, 'depth-prompt', 'depth.md');
|
|
17
|
+
const REQUEST_HEADING = '## Request';
|
|
18
|
+
|
|
19
|
+
// The handoff's sections in order. The parent reads this contract, so the names are fixed and in English whatever the
|
|
20
|
+
// language of the request; `tools/depth-task.test.js` holds the shipped file to them.
|
|
21
|
+
const DEPTH_RETURN_HEADINGS = Object.freeze([
|
|
22
|
+
'## Original request',
|
|
23
|
+
'## Understood',
|
|
24
|
+
'## Questions',
|
|
25
|
+
'## Map',
|
|
26
|
+
'## Not requested',
|
|
27
|
+
'## How it would be verified',
|
|
28
|
+
'## Uncertainty',
|
|
29
|
+
'## For the parent',
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
// The two lines that keep the parent from implementing. The parent wakes on the handoff alone, so the opening line and the
|
|
33
|
+
// closing paragraph both ask for it; `lib/depth-prompt/depth.md` carries the same text and the suite holds the two in step.
|
|
34
|
+
const DEPTH_BANNER = '**/depth handoff: read-only exploration, nothing was implemented.**';
|
|
35
|
+
const DEPTH_FOR_PARENT = 'Do not implement this request. If `## Questions` is not `none`, ask the human those questions first. Show `## Not requested` to the human and wait for them to accept or drop each item before anything is added to a spec.';
|
|
36
|
+
|
|
37
|
+
const FALLBACK = [
|
|
38
|
+
'Do a Depth pass on the request in `## Request`: find and read what it touches, then say what a top professional would do that it does not ask for, the rawest material they would start from, their methods and tools, and what outside you would show the result is right. A deeper version, not a bigger one.',
|
|
39
|
+
'Never carry the request out. You only read and report.',
|
|
40
|
+
`Start your reply with this line, unchanged:\n\n${DEPTH_BANNER}`,
|
|
41
|
+
`Then give exactly these headings, in this order, copied character for character:\n\n${DEPTH_RETURN_HEADINGS.join('\n\n')}`,
|
|
42
|
+
`Under \`## For the parent\`, copy this paragraph unchanged: ${DEPTH_FOR_PARENT}`,
|
|
43
|
+
].join('\n\n');
|
|
44
|
+
|
|
45
|
+
function readDepthFile() {
|
|
46
|
+
return fs.readFileSync(DEPTH_FILE, 'utf8');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function instructions(read) {
|
|
50
|
+
try {
|
|
51
|
+
const text = read();
|
|
52
|
+
return typeof text === 'string' && text.trim().length > 0 ? text.trim() : FALLBACK;
|
|
53
|
+
} catch {
|
|
54
|
+
return FALLBACK;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// The task for one request, or `null` when there is no request to explore.
|
|
59
|
+
function buildDepthTask(request, { read = readDepthFile } = {}) {
|
|
60
|
+
if (typeof request !== 'string' || request.trim().length === 0) return null;
|
|
61
|
+
return `${instructions(read)}\n\n${REQUEST_HEADING}\n\n${request.trim()}`;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const LABEL_PREFIX = 'depth: ';
|
|
65
|
+
const LABEL_MAX = 60;
|
|
66
|
+
|
|
67
|
+
// The one-line name the agents card shows for the task.
|
|
68
|
+
function depthLabel(request) {
|
|
69
|
+
if (typeof request !== 'string') return 'depth';
|
|
70
|
+
const first = request.split('\n').map((line) => line.replace(/\s+/g, ' ').trim()).find((line) => line.length > 0);
|
|
71
|
+
if (first === undefined) return 'depth';
|
|
72
|
+
const room = LABEL_MAX - LABEL_PREFIX.length;
|
|
73
|
+
return `${LABEL_PREFIX}${first.length > room ? `${first.slice(0, room - 1)}…` : first}`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = { DEPTH_FILE, DEPTH_RETURN_HEADINGS, DEPTH_BANNER, DEPTH_FOR_PARENT, buildDepthTask, depthLabel };
|
|
@@ -250,6 +250,10 @@ function registerFileCard(pi, deps = {}) {
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
module.exports = {
|
|
253
|
+
// The bridge's published object and this package's design id: the jobs card asks the same
|
|
254
|
+
// switch (`lib/jobs-card-resolver.js`) and must read it through the same gate.
|
|
255
|
+
ACTIVITY_DESIGN_ID,
|
|
256
|
+
bridgeApi,
|
|
253
257
|
createFileCardResolver,
|
|
254
258
|
registerFileCard,
|
|
255
259
|
};
|
package/lib/file-card.js
CHANGED
|
@@ -654,6 +654,14 @@ function fileResultSlot(tool, inherited, seams, shell) {
|
|
|
654
654
|
module.exports = {
|
|
655
655
|
FILE_TOOLS,
|
|
656
656
|
PREVIEW_ROWS,
|
|
657
|
+
// The drawing helpers the jobs card (`lib/jobs-card.js`) shares, so the two cards can never
|
|
658
|
+
// disagree about a tone, a hint, a theme fallback or how a result's text is read.
|
|
659
|
+
cardTone,
|
|
660
|
+
component,
|
|
661
|
+
expandHint,
|
|
662
|
+
optionFlag,
|
|
663
|
+
resultText,
|
|
664
|
+
themeFor,
|
|
657
665
|
fileCallRows,
|
|
658
666
|
fileCallSlot,
|
|
659
667
|
fileCardHeading,
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The seam that makes `bash_background`, `monitor`, `job_stop` and `job_list` this package's
|
|
3
|
+
// jobs card (`lib/jobs-card.js`).
|
|
4
|
+
//
|
|
5
|
+
// Shaped like `lib/file-card-resolver.js`: the host resolves drawing through
|
|
6
|
+
// `pi.registerToolRenderer((toolName, next) => …)`, where `next()` is what the remaining
|
|
7
|
+
// resolvers and then the registered tool would draw. This module REGISTERS NOTHING, EXECUTES
|
|
8
|
+
// NOTHING and SHADOWS NOTHING: it chooses renderers for the four job tools and hands every
|
|
9
|
+
// other row back exactly as the chain resolved it.
|
|
10
|
+
//
|
|
11
|
+
// One difference from the file card, and it is deliberate. The file card forwards to the host's
|
|
12
|
+
// own renderers while its switch is off, so it can decide on every paint. These four tools have
|
|
13
|
+
// NO renderer of their own — Pi draws its plain default for them — so there is nothing to
|
|
14
|
+
// forward to. The switch is therefore read when the card is BUILT: any answer other than the
|
|
15
|
+
// activity design hands back exactly what the chain resolved, and Pi draws what it always drew.
|
|
16
|
+
// A switch flipped while a card is already on screen reaches the next job card, not that one.
|
|
17
|
+
//
|
|
18
|
+
// THE SWITCH is the bridge's `Card tags` line, read through its published reader, never a
|
|
19
|
+
// store path. It is strict: only the answer `design` carrying this package's activity design
|
|
20
|
+
// paints. No bridge, a bridge older than the reader, a reader that throws, `native`,
|
|
21
|
+
// `not-covered`, `missing`, another plugin's design and an answer nothing can read all leave
|
|
22
|
+
// Pi's drawing untouched, because here an unavailable answer must never change a row.
|
|
23
|
+
|
|
24
|
+
const { inheritedRenderers } = require('./file-card.js');
|
|
25
|
+
const { ACTIVITY_DESIGN_ID, bridgeApi } = require('./file-card-resolver.js');
|
|
26
|
+
const { CARD_CONTENT, cardContentLevel } = require('./card-content.js');
|
|
27
|
+
const { JOB_TOOLS, jobCallSlot, jobResultSlot } = require('./jobs-card.js');
|
|
28
|
+
|
|
29
|
+
const METRICS_FUNCTIONS = ['visibleWidth', 'truncateToWidth', 'wrapTextWithAnsi'];
|
|
30
|
+
|
|
31
|
+
const asObject = (value) => (value !== null && typeof value === 'object' ? value : {});
|
|
32
|
+
const hasFunction = (value, name) => value !== null && typeof value === 'object' && typeof value[name] === 'function';
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Whether the activity design draws `tool` right now. Strict: anything but this package's own
|
|
36
|
+
* design as the line's answer is a no. The reader never throws on the bridge's side and this
|
|
37
|
+
* one does not either.
|
|
38
|
+
*/
|
|
39
|
+
function jobsActivitySelected(tool) {
|
|
40
|
+
try {
|
|
41
|
+
const api = bridgeApi();
|
|
42
|
+
if (api === undefined || typeof api.resolveToolDesignSelection !== 'function') return false;
|
|
43
|
+
const answer = asObject(api.resolveToolDesignSelection(tool));
|
|
44
|
+
return answer.kind === 'design' && asObject(answer.design).id === ACTIVITY_DESIGN_ID;
|
|
45
|
+
} catch {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function assertMetrics(value) {
|
|
51
|
+
for (const name of METRICS_FUNCTIONS) {
|
|
52
|
+
if (!hasFunction(value, name)) throw new TypeError(`createJobsCardResolver requires metrics.${name} to be a function`);
|
|
53
|
+
}
|
|
54
|
+
return value;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The measurement seam, validated once: the object itself, or a function asked on every paint. */
|
|
58
|
+
function metricsSeam(value) {
|
|
59
|
+
if (typeof value === 'function') return value;
|
|
60
|
+
assertMetrics(value);
|
|
61
|
+
return () => value;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const usableMetrics = (value) => (METRICS_FUNCTIONS.every((name) => hasFunction(value, name)) ? value : undefined);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* `createJobsCardResolver({ metrics, registerToolRenderer, theme })` — every host seam is an
|
|
68
|
+
* option, exactly as for the file card. Returns `{ registered, resolver }`; `resolver` is the
|
|
69
|
+
* function the host hook receives. An absent or throwing hook is no hook: nothing of ours is
|
|
70
|
+
* drawn, which is what an older host needs.
|
|
71
|
+
*/
|
|
72
|
+
function createJobsCardResolver(options) {
|
|
73
|
+
const opts = asObject(options);
|
|
74
|
+
const metrics = metricsSeam(opts.metrics);
|
|
75
|
+
const seams = {
|
|
76
|
+
theme: opts.theme,
|
|
77
|
+
metrics() {
|
|
78
|
+
try {
|
|
79
|
+
return usableMetrics(metrics());
|
|
80
|
+
} catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
/** The conversation's content level, read now: `minimal` or the safe `default`. */
|
|
85
|
+
content() {
|
|
86
|
+
try {
|
|
87
|
+
return cardContentLevel() === CARD_CONTENT.MINIMAL ? CARD_CONTENT.MINIMAL : CARD_CONTENT.DEFAULT;
|
|
88
|
+
} catch {
|
|
89
|
+
return CARD_CONTENT.DEFAULT;
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
const resolver = (toolName, next) => {
|
|
94
|
+
const inherited = inheritedRenderers(next);
|
|
95
|
+
// Every tool this card does not own goes back untouched, byte for byte.
|
|
96
|
+
if (!JOB_TOOLS.includes(toolName)) return inherited;
|
|
97
|
+
// Pi's own drawing stays unless the line says activity, and unless a card can be measured.
|
|
98
|
+
if (!jobsActivitySelected(toolName)) return inherited;
|
|
99
|
+
if (seams.metrics() === undefined) return inherited;
|
|
100
|
+
return {
|
|
101
|
+
// This card frames itself, so the host must not box it too.
|
|
102
|
+
renderShell: 'self',
|
|
103
|
+
renderCall: jobCallSlot(toolName, seams),
|
|
104
|
+
renderResult: jobResultSlot(toolName, seams),
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const register = opts.registerToolRenderer;
|
|
108
|
+
if (typeof register !== 'function') return { registered: false, resolver };
|
|
109
|
+
try {
|
|
110
|
+
register(resolver);
|
|
111
|
+
return { registered: true, resolver };
|
|
112
|
+
} catch {
|
|
113
|
+
return { registered: false, resolver };
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* The extension's one-line wiring point: register through the host's hook when it has one and
|
|
119
|
+
* report the outcome rather than throwing. A host without `registerToolRenderer` draws its own
|
|
120
|
+
* rows and loses nothing.
|
|
121
|
+
*/
|
|
122
|
+
function registerJobsCard(pi, deps = {}) {
|
|
123
|
+
if (typeof pi?.registerToolRenderer !== 'function') return { registered: false, resolver: undefined };
|
|
124
|
+
try {
|
|
125
|
+
return createJobsCardResolver({
|
|
126
|
+
metrics: deps.metrics,
|
|
127
|
+
theme: deps.theme,
|
|
128
|
+
registerToolRenderer: (resolver) => pi.registerToolRenderer(resolver),
|
|
129
|
+
});
|
|
130
|
+
} catch {
|
|
131
|
+
return { registered: false, resolver: undefined };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
module.exports = {
|
|
136
|
+
createJobsCardResolver,
|
|
137
|
+
jobsActivitySelected,
|
|
138
|
+
registerJobsCard,
|
|
139
|
+
};
|