pi-odd-worktree 3.4.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 +3 -2
- package/extensions/odd-worktree-tools.ts +29 -0
- package/lib/depth-launch.js +70 -0
- package/lib/depth-prompt/depth.md +53 -0
- package/lib/depth-task.js +76 -0
- package/package.json +1 -1
- 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/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. |
|
|
@@ -49,7 +50,7 @@ gentle-shell install npm:pi-odd-worktree
|
|
|
49
50
|
|
|
50
51
|
From a local clone, `pi install .` installs the working copy, and `gentle-shell install .` does the same from inside a Gentle Shell session.
|
|
51
52
|
|
|
52
|
-
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.
|
|
53
54
|
|
|
54
55
|
## Core Workflow
|
|
55
56
|
|
|
@@ -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;
|
|
@@ -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 };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pi-odd-worktree",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.5.0",
|
|
4
4
|
"description": "Pi package for odd-worktree: the Git worktree tools a Pi session uses (create and list the checkouts the agent works in), the /warp worktree panel, the /odd ODD viewer, and the /issues GitHub issue reader. Needs only Pi and git: no companion app, no extra service.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"pi-package",
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `/depth` through the registered command (S4, S5, S6): the extension's one new command starts the explorer by itself,
|
|
3
|
+
// through the host's `subagent_run` tool, and answers with one notice. The launch rules are in tools/depth-launch.test.js;
|
|
4
|
+
// this suite proves the command is wired to them in the loaded extension, behind the same gate as the others.
|
|
5
|
+
const { test } = require('node:test');
|
|
6
|
+
const assert = require('node:assert/strict');
|
|
7
|
+
const { loadExtension } = require('./fixtures/load-extension.js');
|
|
8
|
+
|
|
9
|
+
function makeCtx({ tools = [{ name: 'subagent_run' }], outcome = { content: [{ type: 'text', text: 'Started gentle-ai-explore in the background as task t-1.' }] } } = {}) {
|
|
10
|
+
const calls = [];
|
|
11
|
+
const notes = [];
|
|
12
|
+
const ctx = {
|
|
13
|
+
tools,
|
|
14
|
+
executeTool: async (name, args) => {
|
|
15
|
+
calls.push({ name, args });
|
|
16
|
+
return outcome;
|
|
17
|
+
},
|
|
18
|
+
ui: { notify: (message, level) => notes.push({ message, level }) },
|
|
19
|
+
};
|
|
20
|
+
return { ctx, calls, notes };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test('/depth is a registered command that says what it does', async () => {
|
|
24
|
+
const { commands } = await loadExtension({});
|
|
25
|
+
const depth = commands.get('depth');
|
|
26
|
+
assert.ok(depth, '/depth is registered');
|
|
27
|
+
assert.equal(typeof depth.handler, 'function');
|
|
28
|
+
assert.match(depth.description, /background/);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test('/depth <request> starts one background explorer with the request verbatim and says so', async () => {
|
|
32
|
+
const { commands } = await loadExtension({});
|
|
33
|
+
const { ctx, calls, notes } = makeCtx();
|
|
34
|
+
await commands.get('depth').handler(' make the error messages clearer ', ctx);
|
|
35
|
+
|
|
36
|
+
assert.equal(calls.length, 1);
|
|
37
|
+
assert.equal(calls[0].name, 'subagent_run');
|
|
38
|
+
assert.equal(calls[0].args.agent, 'gentle-ai-explore');
|
|
39
|
+
assert.equal(calls[0].args.mode, 'background');
|
|
40
|
+
assert.ok(calls[0].args.task.endsWith('## Request\n\nmake the error messages clearer'));
|
|
41
|
+
assert.deepEqual(notes, [
|
|
42
|
+
{ message: 'Exploring in the background (depth: make the error messages clearer). The handoff arrives in this session when it finishes.', level: 'info' },
|
|
43
|
+
]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('/depth with no request starts nothing and shows the usage as an error', async () => {
|
|
47
|
+
const { commands } = await loadExtension({});
|
|
48
|
+
const { ctx, calls, notes } = makeCtx();
|
|
49
|
+
await commands.get('depth').handler('', ctx);
|
|
50
|
+
assert.equal(calls.length, 0);
|
|
51
|
+
assert.equal(notes.length, 1);
|
|
52
|
+
assert.equal(notes[0].level, 'error');
|
|
53
|
+
assert.match(notes[0].message, /^\/depth needs a request: \/depth <request>\./);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('/depth without the host tool says so, and a context with no ui does not throw', async () => {
|
|
57
|
+
const { commands } = await loadExtension({});
|
|
58
|
+
const { ctx, calls, notes } = makeCtx({ tools: [] });
|
|
59
|
+
await commands.get('depth').handler('fix the login', ctx);
|
|
60
|
+
assert.equal(calls.length, 0);
|
|
61
|
+
assert.match(notes[0].message, /subagent_run/);
|
|
62
|
+
assert.equal(notes[0].level, 'error');
|
|
63
|
+
|
|
64
|
+
await assert.doesNotReject(commands.get('depth').handler('fix the login', { tools: [], executeTool: async () => ({}) }));
|
|
65
|
+
await assert.doesNotReject(commands.get('depth').handler(undefined, undefined));
|
|
66
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// `/depth`'s launch (S4, S5, S8): the command starts ONE background `gentle-ai-explore` through the host's own
|
|
3
|
+
// `subagent_run` tool, with the Depth task and nothing else. Progress, cancellation and the delivery of the handoff are
|
|
4
|
+
// gentle-agents', so this module has no widget, no timer and no message of its own; it only decides whether the launch can
|
|
5
|
+
// happen and says in one sentence what did or did not.
|
|
6
|
+
const { test } = require('node:test');
|
|
7
|
+
const assert = require('node:assert/strict');
|
|
8
|
+
const { launchDepth, DEPTH_AGENT, DEPTH_TOOL } = require('../lib/depth-launch.js');
|
|
9
|
+
const { DEPTH_RETURN_HEADINGS } = require('../lib/depth-task.js');
|
|
10
|
+
|
|
11
|
+
const STARTED = {
|
|
12
|
+
content: [{ type: 'text', text: 'Started gentle-ai-explore in the background as task abc-1.' }],
|
|
13
|
+
details: {},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
function host({ outcome = STARTED, tools = [{ name: 'subagent_run' }, { name: 'job_list' }], throws } = {}) {
|
|
17
|
+
const calls = [];
|
|
18
|
+
const ctx = {
|
|
19
|
+
tools,
|
|
20
|
+
executeTool: async (name, args) => {
|
|
21
|
+
calls.push({ name, args });
|
|
22
|
+
if (throws) throw throws;
|
|
23
|
+
return outcome;
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
return { ctx, calls };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
test('the names the launch depends on are the host agent and tool', () => {
|
|
30
|
+
assert.equal(DEPTH_AGENT, 'gentle-ai-explore');
|
|
31
|
+
assert.equal(DEPTH_TOOL, 'subagent_run');
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test('it starts one background explorer, with exactly the arguments the host tool accepts', async () => {
|
|
35
|
+
const { ctx, calls } = host();
|
|
36
|
+
const request = 'make the error messages clearer\n\n- keep «exactly» this';
|
|
37
|
+
const result = await launchDepth(request, ctx);
|
|
38
|
+
|
|
39
|
+
assert.equal(calls.length, 1);
|
|
40
|
+
assert.equal(calls[0].name, 'subagent_run');
|
|
41
|
+
// `subagent_run` rejects any other key (additionalProperties: false), so the set is closed.
|
|
42
|
+
assert.deepEqual(Object.keys(calls[0].args).sort(), ['agent', 'label', 'mode', 'task']);
|
|
43
|
+
assert.equal(calls[0].args.agent, 'gentle-ai-explore');
|
|
44
|
+
assert.equal(calls[0].args.mode, 'background');
|
|
45
|
+
assert.equal(calls[0].args.label, 'depth: make the error messages clearer');
|
|
46
|
+
assert.ok(calls[0].args.task.endsWith(`## Request\n\n${request}`), 'the request goes in verbatim, last');
|
|
47
|
+
for (const heading of DEPTH_RETURN_HEADINGS) assert.ok(calls[0].args.task.includes(heading), heading);
|
|
48
|
+
|
|
49
|
+
assert.deepEqual(result, {
|
|
50
|
+
ok: true,
|
|
51
|
+
level: 'info',
|
|
52
|
+
message: 'Exploring in the background (depth: make the error messages clearer). The handoff arrives in this session when it finishes.',
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('a blank request starts nothing and says how to use the command', async () => {
|
|
57
|
+
for (const blank of ['', ' \n', undefined, null]) {
|
|
58
|
+
const { ctx, calls } = host();
|
|
59
|
+
const result = await launchDepth(blank, ctx);
|
|
60
|
+
assert.equal(calls.length, 0);
|
|
61
|
+
assert.equal(result.ok, false);
|
|
62
|
+
assert.equal(result.level, 'error');
|
|
63
|
+
assert.match(result.message, /^\/depth needs a request: \/depth <request>\./);
|
|
64
|
+
assert.match(result.message, /does not see this chat/);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('without the host tool nothing starts, and the sentence names the tool', async () => {
|
|
69
|
+
const noTool = { executeTool: async () => assert.fail('must not be called') };
|
|
70
|
+
const cases = [
|
|
71
|
+
{ ...noTool },
|
|
72
|
+
{ ...noTool, tools: [] },
|
|
73
|
+
{ ...noTool, tools: [{ name: 'job_list' }] },
|
|
74
|
+
{ ...noTool, tools: 'subagent_run' },
|
|
75
|
+
{ tools: [{ name: 'subagent_run' }] },
|
|
76
|
+
undefined,
|
|
77
|
+
null,
|
|
78
|
+
];
|
|
79
|
+
for (const ctx of cases) {
|
|
80
|
+
const result = await launchDepth('fix the login', ctx);
|
|
81
|
+
assert.equal(result.ok, false);
|
|
82
|
+
assert.equal(result.level, 'error');
|
|
83
|
+
assert.match(result.message, /subagent_run/);
|
|
84
|
+
assert.match(result.message, /does not offer it/);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
test('a refusal from the host tool is shown with its own words', async () => {
|
|
89
|
+
const { ctx, calls } = host({ outcome: { isError: true, content: [{ type: 'text', text: 'Background subagents need an interactive session.' }] } });
|
|
90
|
+
const result = await launchDepth('fix the login', ctx);
|
|
91
|
+
assert.equal(calls.length, 1);
|
|
92
|
+
assert.deepEqual(result, {
|
|
93
|
+
ok: false,
|
|
94
|
+
level: 'error',
|
|
95
|
+
message: "/depth couldn't start the explorer: Background subagents need an interactive session.",
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('a refusal with no text, a thrown error and an empty answer each become one sentence', async () => {
|
|
100
|
+
const silent = await launchDepth('x', host({ outcome: { isError: true, content: [] } }).ctx);
|
|
101
|
+
assert.equal(silent.message, "/depth couldn't start the explorer: the subagent_run tool reported an error.");
|
|
102
|
+
|
|
103
|
+
const thrown = await launchDepth('x', host({ throws: new Error('boom') }).ctx);
|
|
104
|
+
assert.equal(thrown.ok, false);
|
|
105
|
+
assert.equal(thrown.message, "/depth couldn't start the explorer: boom");
|
|
106
|
+
|
|
107
|
+
// `null`, not `undefined`: the double's default parameter would turn `undefined` into a successful start.
|
|
108
|
+
const empty = await launchDepth('x', host({ outcome: null }).ctx);
|
|
109
|
+
assert.equal(empty.ok, false);
|
|
110
|
+
assert.match(empty.message, /^\/depth couldn't start the explorer:/);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test('a hostile context never makes it throw', async () => {
|
|
114
|
+
const hostile = {
|
|
115
|
+
get tools() {
|
|
116
|
+
throw new Error('no tools for you');
|
|
117
|
+
},
|
|
118
|
+
executeTool: async () => STARTED,
|
|
119
|
+
};
|
|
120
|
+
const result = await launchDepth('fix the login', hostile);
|
|
121
|
+
assert.equal(result.ok, false);
|
|
122
|
+
assert.match(result.message, /subagent_run/);
|
|
123
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// The task `/depth` hands the explorer: the instructions of `lib/depth-prompt/depth.md`, then the request exactly as the
|
|
3
|
+
// person typed it (S1, S3, S8). The explorer has no chat, so the request is the only thing it will ever know of the
|
|
4
|
+
// person's words, and it comes back first in the handoff (S8, L8).
|
|
5
|
+
const { test } = require('node:test');
|
|
6
|
+
const assert = require('node:assert/strict');
|
|
7
|
+
const { buildDepthTask, depthLabel, DEPTH_RETURN_HEADINGS, DEPTH_BANNER, DEPTH_FOR_PARENT } = require('../lib/depth-task.js');
|
|
8
|
+
|
|
9
|
+
const REQUEST = 'make the error messages clearer\n\n- keep «exactly» this: `/x failed:`\n- no retries';
|
|
10
|
+
|
|
11
|
+
test('the task is the instructions, then the request exactly as typed', () => {
|
|
12
|
+
const task = buildDepthTask(REQUEST, { read: () => 'INSTRUCTIONS' });
|
|
13
|
+
assert.ok(task.startsWith('INSTRUCTIONS'), 'the instructions lead');
|
|
14
|
+
assert.ok(task.endsWith(`## Request\n\n${REQUEST}`), 'the request closes the task, byte for byte');
|
|
15
|
+
assert.equal(task.split('## Request').length - 1, 1, 'one request section');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('only the ends of the request are trimmed, never its inside', () => {
|
|
19
|
+
const task = buildDepthTask('\n a\n\n b \n\n', { read: () => 'I' });
|
|
20
|
+
assert.ok(task.endsWith('## Request\n\na\n\n b'));
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('a blank or non-string request builds no task', () => {
|
|
24
|
+
for (const blank of ['', ' ', '\n\t\n', undefined, null, 5, {}]) {
|
|
25
|
+
assert.equal(buildDepthTask(blank, { read: () => 'I' }), null);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('a missing or empty instructions file still gives a task that names every section', () => {
|
|
30
|
+
const unreadable = () => {
|
|
31
|
+
throw new Error('ENOENT');
|
|
32
|
+
};
|
|
33
|
+
for (const read of [unreadable, () => '', () => ' \n', () => undefined]) {
|
|
34
|
+
const task = buildDepthTask(REQUEST, { read });
|
|
35
|
+
assert.ok(task.endsWith(`## Request\n\n${REQUEST}`));
|
|
36
|
+
for (const heading of DEPTH_RETURN_HEADINGS) assert.ok(task.includes(heading), `fallback names ${heading}`);
|
|
37
|
+
assert.match(task, /Never carry the request out/);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test('the shipped instructions name the return sections in order, and the parent closes them', () => {
|
|
42
|
+
const task = buildDepthTask('x');
|
|
43
|
+
let at = -1;
|
|
44
|
+
for (const heading of DEPTH_RETURN_HEADINGS) {
|
|
45
|
+
const next = task.indexOf(`\n${heading}\n`, at + 1);
|
|
46
|
+
assert.ok(next > at, `${heading} appears after the previous section`);
|
|
47
|
+
at = next;
|
|
48
|
+
}
|
|
49
|
+
assert.equal(DEPTH_RETURN_HEADINGS[0], '## Original request', 'the verbatim request leads the handoff');
|
|
50
|
+
assert.equal(DEPTH_RETURN_HEADINGS.at(-1), '## For the parent', 'the line for the parent closes it');
|
|
51
|
+
assert.match(task, /Do not implement/);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test('the label is one short line that starts with the command', () => {
|
|
55
|
+
assert.equal(depthLabel('fix the login'), 'depth: fix the login');
|
|
56
|
+
const long = depthLabel(`${'x'.repeat(200)}\nsecond line`);
|
|
57
|
+
assert.ok(long.startsWith('depth: xxx') && long.endsWith('…') && !long.includes('\n'));
|
|
58
|
+
assert.ok(long.length <= 60, `short enough, got ${long.length}`);
|
|
59
|
+
assert.equal(depthLabel('first\nsecond'), 'depth: first');
|
|
60
|
+
for (const blank of ['', ' ', undefined, 5]) assert.equal(depthLabel(blank), 'depth');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
test('the parent is guarded at both ends: an opening line and the closing paragraph, in the shipped file and in the fallback', () => {
|
|
64
|
+
// The parent wakes on the handoff alone and may start implementing, so the instruction not to must not depend on one
|
|
65
|
+
// section a cheap model can drop (a real run dropped `## For the parent` and translated the headings).
|
|
66
|
+
assert.equal(typeof DEPTH_BANNER, 'string');
|
|
67
|
+
assert.equal(typeof DEPTH_FOR_PARENT, 'string');
|
|
68
|
+
assert.match(DEPTH_BANNER, /nothing was implemented/);
|
|
69
|
+
assert.match(DEPTH_FOR_PARENT, /^Do not implement this request\./);
|
|
70
|
+
for (const read of [undefined, () => '']) {
|
|
71
|
+
const task = buildDepthTask('x', read === undefined ? {} : { read });
|
|
72
|
+
assert.ok(task.includes(DEPTH_BANNER), 'the opening line is asked for');
|
|
73
|
+
assert.ok(task.includes(DEPTH_FOR_PARENT), 'the closing paragraph is given');
|
|
74
|
+
assert.match(task, /character for character/);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
@@ -433,8 +433,8 @@ test('S18/S19 (T14): the ready announcement registers the whole surface, exactly
|
|
|
433
433
|
const bridge = installBridge();
|
|
434
434
|
for (const entry of ready) entry.handler();
|
|
435
435
|
|
|
436
|
-
assert.deepEqual([...loaded.commands.keys()].sort(), ['files', 'issues', 'odd', 'warp'],
|
|
437
|
-
'the
|
|
436
|
+
assert.deepEqual([...loaded.commands.keys()].sort(), ['depth', 'files', 'issues', 'odd', 'warp'],
|
|
437
|
+
'the five commands arrive with the bridge');
|
|
438
438
|
assert.deepEqual([...loaded.tools.keys()].sort(), ['worktree_create', 'worktree_list'], 'the two tools');
|
|
439
439
|
assert.deepEqual([...loaded.messageRenderers.keys()], ['worktree-warp'], 'the message renderer');
|
|
440
440
|
assert.deepEqual([...loaded.entryRenderers.keys()].sort(), ['odd-worktree-issues-refusal', 'odd-worktree-warp-queue'],
|
|
@@ -244,7 +244,7 @@ const agentStub = {
|
|
|
244
244
|
describe('/files registration (S17)', () => {
|
|
245
245
|
test('the file picker is registered beside the other three panels', async () => {
|
|
246
246
|
const { commands } = await loadExtension({});
|
|
247
|
-
assert.deepEqual([...commands.keys()].sort(), ['files', 'issues', 'odd', 'warp']);
|
|
247
|
+
assert.deepEqual([...commands.keys()].sort(), ['depth', 'files', 'issues', 'odd', 'warp']);
|
|
248
248
|
const files = commands.get('files');
|
|
249
249
|
assert.equal(typeof files.handler, 'function', 'the command carries its handler');
|
|
250
250
|
assert.ok(files.description.includes('files'), 'the description says what it browses');
|
|
@@ -83,11 +83,11 @@ describe('manifest', () => {
|
|
|
83
83
|
});
|
|
84
84
|
|
|
85
85
|
describe('registration', () => {
|
|
86
|
-
test('registers /warp, /odd, /files, /issues and the two worktree tools', async () => {
|
|
86
|
+
test('registers /warp, /odd, /files, /issues, /depth and the two worktree tools', async () => {
|
|
87
87
|
delete process.env.GENTLE_WORKTREE_THREAD;
|
|
88
88
|
const { commands, tools, messageRenderers } = await loadExtension({});
|
|
89
89
|
const registered = [...commands.keys()].sort();
|
|
90
|
-
assert.deepEqual(registered, ['files', 'issues', 'odd', 'warp'], 'the command list is exactly the four panels');
|
|
90
|
+
assert.deepEqual(registered, ['depth', 'files', 'issues', 'odd', 'warp'], 'the command list is exactly the four panels and /depth');
|
|
91
91
|
assert.deepEqual([...tools.keys()].sort(), ['worktree_create', 'worktree_list'], 'exactly two agent tools');
|
|
92
92
|
assert.deepEqual([...messageRenderers.keys()], ['worktree-warp']);
|
|
93
93
|
});
|