pi-odd-worktree 2.1.0 → 3.0.1
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 +54 -319
- package/extensions/odd-worktree-tools.ts +4182 -2539
- package/lib/bash-activity.js +1166 -0
- package/lib/bash-design.js +684 -0
- package/lib/bash-destructive.js +559 -0
- package/lib/bash-frame.js +205 -0
- package/lib/card-content.js +23 -0
- package/lib/card-style.js +175 -0
- package/lib/checkout-facts.js +30 -70
- package/lib/codegraph-card-preview.js +628 -0
- package/lib/codegraph-card.js +515 -0
- package/lib/codegraph-compaction.js +76 -0
- package/lib/codegraph-daemon.js +246 -0
- package/lib/codegraph-edit-sync.js +182 -0
- package/lib/codegraph-guard-target.js +337 -0
- package/lib/codegraph-guard.js +211 -0
- package/lib/codegraph-index.js +1020 -0
- package/lib/codegraph-lock.js +607 -0
- package/lib/codegraph-mcp-config.js +134 -0
- package/lib/codegraph-mcp.js +123 -0
- package/lib/codegraph-paths.js +69 -0
- package/lib/codegraph-prompt/explore.md +11 -0
- package/lib/codegraph-prompt/fix.md +6 -0
- package/lib/codegraph-prompt/generic.md +8 -0
- package/lib/codegraph-prompt/judge.md +9 -0
- package/lib/codegraph-prompt/orchestrator.md +17 -0
- package/lib/codegraph-prompt/verify.md +10 -0
- package/lib/codegraph-prompt/worker.md +7 -0
- package/lib/codegraph-role.js +55 -0
- package/lib/codegraph-rules.js +146 -0
- package/lib/codegraph-session.js +303 -383
- package/lib/codegraph-warmup.js +139 -0
- package/lib/file-card-markdown.js +141 -0
- package/lib/file-card-resolver.js +245 -0
- package/lib/file-card.js +659 -0
- package/lib/files-index.js +387 -0
- package/lib/files-insert.js +81 -0
- package/lib/files-orders.js +326 -0
- package/lib/files-picker-view.js +1421 -0
- package/lib/files-preview.js +338 -0
- package/lib/files-scope-detail.js +171 -0
- package/lib/files-scope-view.js +507 -0
- package/lib/gh-issues.js +323 -15
- package/lib/issue-preview.js +26 -7
- package/lib/issues-bash-mutation.js +206 -0
- package/lib/issues-cache-store.js +261 -0
- package/lib/issues-section.js +710 -0
- package/lib/issues-view.js +649 -52
- package/lib/odd-prompt/odd-worktrees.md +21 -0
- package/lib/odd-worktrees-prompt.js +10 -28
- package/lib/related-issues-cache.js +210 -0
- package/lib/shell-card.js +825 -0
- package/lib/skill-odd-card.js +183 -0
- package/lib/tui-paint.js +4 -5
- package/lib/warp-create-panel.js +538 -250
- package/lib/warp-create-picker.js +56 -9
- package/lib/warp-delete-confirm.js +19 -28
- package/lib/warp-selector-view.js +160 -82
- package/lib/which-command.js +90 -0
- package/lib/worktree-card.js +267 -897
- package/lib/worktree-cards.js +383 -0
- package/lib/worktree-create.js +287 -0
- package/lib/worktree-git.js +3 -3
- package/lib/worktree-guard.js +548 -0
- package/lib/worktree-hooks.js +421 -712
- package/lib/worktree-list.js +120 -0
- package/lib/worktree-registry.js +162 -879
- package/lib/{worktree-close-herdr.js → worktree-remove.js} +9 -11
- package/lib/worktree-setup-runner.js +376 -0
- package/lib/worktree-setup.js +140 -0
- package/lib/worktree-warp-busy.js +462 -85
- package/lib/worktree-warp-sessions.js +1 -2
- package/package.json +2 -2
- package/tools/bash-activity.test.js +1420 -0
- package/tools/bash-design.test.js +1093 -0
- package/tools/bash-destructive.test.js +139 -0
- package/tools/card-content.test.js +44 -0
- package/tools/card-style.test.js +298 -0
- package/tools/codegraph-card-preview.test.js +254 -0
- package/tools/codegraph-card.test.js +1080 -0
- package/tools/codegraph-compaction.test.js +378 -0
- package/tools/codegraph-daemon.test.js +248 -0
- package/tools/codegraph-edit-sync.test.js +295 -0
- package/tools/codegraph-guard-target.test.js +174 -0
- package/tools/codegraph-guard.test.js +238 -0
- package/tools/codegraph-index.test.js +1948 -0
- package/tools/codegraph-lock.test.js +932 -0
- package/tools/codegraph-mcp-config.test.js +181 -0
- package/tools/codegraph-mcp.test.js +194 -0
- package/tools/codegraph-paths.test.js +44 -0
- package/tools/codegraph-role.test.js +30 -0
- package/tools/codegraph-rules.test.js +250 -0
- package/tools/codegraph-session.test.js +660 -391
- package/tools/codegraph-warmup.test.js +316 -0
- package/tools/commands.test.js +510 -31
- package/tools/file-card-markdown.test.js +188 -0
- package/tools/file-card.test.js +1289 -0
- package/tools/files-bridge.test.js +575 -0
- package/tools/files-command.test.js +613 -0
- package/tools/files-index.test.js +473 -0
- package/tools/files-insert.test.js +139 -0
- package/tools/files-orders.test.js +597 -0
- package/tools/files-picker-view.test.js +1889 -0
- package/tools/files-preview.test.js +452 -0
- package/tools/files-scope-detail.test.js +264 -0
- package/tools/files-scope-view.test.js +614 -0
- package/tools/fixtures/card-codegraph-outputs.js +110 -0
- package/tools/fixtures/codegraph-cli-stub.js +16 -0
- package/tools/fixtures/codegraph-init-process.js +28 -0
- package/tools/fixtures/codegraph-lock-worker.js +117 -0
- package/tools/fixtures/daemon-fake.js +98 -0
- package/tools/fixtures/daemon-mcp-server.js +39 -0
- package/tools/fixtures/daemon-warmup-worker.js +12 -0
- package/tools/fixtures/load-extension.js +136 -3
- package/tools/gh-issues-feedback.test.js +31 -7
- package/tools/gh-issues.test.js +417 -1
- package/tools/issue-preview.test.js +44 -7
- package/tools/issues-bash-mutation.test.js +101 -0
- package/tools/issues-cache-store.test.js +222 -0
- package/tools/issues-command.test.js +1517 -67
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4235 -0
- package/tools/issues-seed-query-regression.test.js +67 -0
- package/tools/issues-view.test.js +1489 -60
- package/tools/odd-worktrees-prompt.test.js +98 -65
- package/tools/package-surface.test.js +431 -36
- package/tools/related-issues-cache.test.js +324 -0
- package/tools/shell-card.test.js +834 -0
- package/tools/skill-odd-card.test.js +200 -0
- package/tools/t5-session-identity.test.js +44 -22
- package/tools/warp-busy-guard.test.js +2565 -309
- package/tools/warp-create-panel.test.js +499 -74
- package/tools/warp-create-picker.test.js +101 -5
- package/tools/warp-delete-confirm.test.js +49 -15
- package/tools/warp-empty-session.test.js +0 -1
- package/tools/warp-fallback-regression.test.js +533 -0
- package/tools/warp-selector-view.test.js +460 -196
- package/tools/which-command.test.js +126 -0
- package/tools/worktree-card.test.js +551 -0
- package/tools/worktree-cards.test.js +845 -0
- package/tools/worktree-changes.test.js +4 -5
- package/tools/worktree-create.test.js +489 -0
- package/tools/worktree-guard.test.js +823 -0
- package/tools/worktree-hooks.test.js +905 -0
- package/tools/worktree-list.test.js +170 -0
- package/tools/worktree-registry.test.js +89 -230
- package/tools/worktree-remove-async.test.js +318 -0
- package/tools/worktree-setup-runner.test.js +276 -0
- package/tools/worktree-setup.test.js +140 -0
- package/tools/worktree-tools.test.js +419 -199
- package/lib/codegraph-commands.js +0 -165
- package/lib/odd-prompt/odd-worktrees.with-codegraph.md +0 -19
- package/lib/odd-prompt/odd-worktrees.without-codegraph.md +0 -15
- package/lib/worktree-model-result.js +0 -291
- package/tools/codegraph-commands.test.js +0 -371
- package/tools/herdr-free-create.test.js +0 -161
- package/tools/worktree-close-herdr-async.test.js +0 -204
- package/tools/worktree-odd-migration.test.js +0 -224
- package/tools/worktree-registry-cache.test.js +0 -163
- package/tools/worktree-registry-odd.test.js +0 -231
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
// The three CodeGraph session commands' bodies (S9): `/codegraph-hook`,
|
|
3
|
-
// `/codegraph-init` and `/codegraph-sync`.
|
|
4
|
-
//
|
|
5
|
-
// They are plain functions returning a render-ready result — `{ok, level,
|
|
6
|
-
// text}` — so the extension only has to hand the line to `ctx.ui.notify`. The
|
|
7
|
-
// registration itself is the extension's job and is gated on the session gate,
|
|
8
|
-
// so a session without the CLI never lists these commands.
|
|
9
|
-
//
|
|
10
|
-
// `/codegraph-hook` flips the in-memory, process-wide switch owned by
|
|
11
|
-
// `codegraph-session.js`: nothing is written to user configuration, and the
|
|
12
|
-
// environment (`CODEGRAPH_HOOK=0`) is only the starting state.
|
|
13
|
-
//
|
|
14
|
-
// `init` and `sync` run the real CLI once, at the session's current directory,
|
|
15
|
-
// through the injected `run` seam. The reported line is the child's real
|
|
16
|
-
// outcome: a non-zero (or unstartable) child is a failure, and no path throws
|
|
17
|
-
// into the command handler.
|
|
18
|
-
|
|
19
|
-
const { isHookEnabled, setHookEnabled } = require('./codegraph-session.js');
|
|
20
|
-
|
|
21
|
-
const CODEGRAPH_BIN = 'codegraph';
|
|
22
|
-
const COMMANDS = { init: 'codegraph init', sync: 'codegraph sync' };
|
|
23
|
-
|
|
24
|
-
function pick(deps, name, fallback) {
|
|
25
|
-
return deps && typeof deps[name] === 'function' ? deps[name] : fallback;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// The convention every other lib helper uses for its runner;
|
|
29
|
-
// `runArgvAsync` resolves (never rejects) with `{status, stdout, stderr, error}`.
|
|
30
|
-
function defaultRun(bin, args, cwd) {
|
|
31
|
-
return require('./worktree-git.js').runArgvAsync(bin, args, { cwd });
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function sessionCwd(ctx) {
|
|
35
|
-
const cwd = ctx && ctx.cwd;
|
|
36
|
-
return typeof cwd === 'string' && cwd.length > 0 ? cwd : process.cwd();
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// One line of child output, so a multi-line stack never becomes the message.
|
|
40
|
-
function firstLine(text) {
|
|
41
|
-
const raw = String(text === undefined || text === null ? '' : text);
|
|
42
|
-
for (const line of raw.split(/\r?\n/)) {
|
|
43
|
-
const trimmed = line.trim();
|
|
44
|
-
if (trimmed.length > 0) return trimmed.length > 200 ? `${trimmed.slice(0, 200)}…` : trimmed;
|
|
45
|
-
}
|
|
46
|
-
return '';
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function hookState() {
|
|
50
|
-
return isHookEnabled() ? 'enabled' : 'disabled';
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// `/codegraph-hook` — no argument toggles; `on` and `off` set the state
|
|
54
|
-
// explicitly; `status` only reports it.
|
|
55
|
-
function codegraphHook(rawArgs) {
|
|
56
|
-
const raw = String(rawArgs === undefined || rawArgs === null ? '' : rawArgs).trim().toLowerCase();
|
|
57
|
-
if (raw === '' || raw === 'on' || raw === 'off') setHookEnabled(raw === '' ? !isHookEnabled() : raw === 'on');
|
|
58
|
-
else if (raw !== 'status') {
|
|
59
|
-
return { ok: false, level: 'error', text: `codegraph hook: unknown option "${raw}". Use on, off or status.` };
|
|
60
|
-
}
|
|
61
|
-
return { ok: true, level: 'info', text: `codegraph hook: ${hookState()}` };
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// The CLI is chatty and decorative (a box around every line, ANSI colours, and
|
|
65
|
-
// glyphs that change between releases), so the report is built from the plain
|
|
66
|
-
// text it puts on stdout and stderr rather than from the exit status alone. The
|
|
67
|
-
// captured shapes this reads:
|
|
68
|
-
//
|
|
69
|
-
// init, fresh "Initialized in <path>" / "Indexed N files" / "N nodes, M edges in Tms"
|
|
70
|
-
// init, indexed "Already initialized in <path>" / "Use \"codegraph index\" to re-index ..."
|
|
71
|
-
// sync, clean "Already up to date"
|
|
72
|
-
// sync, changed "Synced N changed files" / "Modified: N — M nodes in Tms"
|
|
73
|
-
// sync, no index "CodeGraph not initialized in <path>" (stderr, exit 1)
|
|
74
|
-
const ANSI = /\u001b\[[0-9;]*[a-zA-Z]/g;
|
|
75
|
-
|
|
76
|
-
function plain(text) {
|
|
77
|
-
return String(text === undefined || text === null ? '' : text).replace(ANSI, '');
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
function count(value, noun) {
|
|
81
|
-
const n = Number(value);
|
|
82
|
-
if (!Number.isFinite(n)) return '';
|
|
83
|
-
return `${n} ${noun}${n === 1 ? '' : 's'}`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function summarize(label, out) {
|
|
87
|
-
const text = `${plain(out.stdout)}\n${plain(out.stderr)}`;
|
|
88
|
-
const path = (match) => (match && match[1] ? match[1].trim() : '');
|
|
89
|
-
|
|
90
|
-
const notIndexed = text.match(/not initialized in\s+(\S+)/i);
|
|
91
|
-
if (notIndexed) {
|
|
92
|
-
return { ok: false, level: 'error', text: `${label}: no index in this checkout — run /codegraph-init first` };
|
|
93
|
-
}
|
|
94
|
-
const already = text.match(/already initialized in\s+(\S+)/i);
|
|
95
|
-
if (already) {
|
|
96
|
-
return { ok: true, level: 'info', text: `${label}: already initialized at ${path(already)} — nothing to do, use /codegraph-sync to update` };
|
|
97
|
-
}
|
|
98
|
-
const upToDate = /already up to date/i.test(text);
|
|
99
|
-
if (upToDate) {
|
|
100
|
-
return { ok: true, level: 'info', text: `${label}: already up to date — nothing to sync` };
|
|
101
|
-
}
|
|
102
|
-
const synced = text.match(/synced\s+(\d+)\s+changed\s+files?/i);
|
|
103
|
-
if (synced) {
|
|
104
|
-
const nodes = text.match(/(\d+)\s+nodes?/i);
|
|
105
|
-
const counts = [count(synced[1], 'changed file'), nodes ? count(nodes[1], 'node') : ''].filter(Boolean).join(' — ');
|
|
106
|
-
return { ok: true, level: 'info', text: `${label}: synced ${counts}` };
|
|
107
|
-
}
|
|
108
|
-
const initialized = text.match(/initialized in\s+(\S+)/i);
|
|
109
|
-
if (initialized) {
|
|
110
|
-
const files = text.match(/indexed\s+(\d+)\s+files?/i);
|
|
111
|
-
const nodes = text.match(/(\d+)\s+nodes?/i);
|
|
112
|
-
const edges = text.match(/(\d+)\s+edges?/i);
|
|
113
|
-
const sorted = [
|
|
114
|
-
files ? count(files[1], 'file') : '',
|
|
115
|
-
nodes ? count(nodes[1], 'node') : '',
|
|
116
|
-
edges ? count(edges[1], 'edge') : '',
|
|
117
|
-
].filter(Boolean).join(', ');
|
|
118
|
-
return { ok: true, level: 'info', text: `${label}: initialized ${path(initialized)}${sorted ? ` — ${sorted}` : ''}` };
|
|
119
|
-
}
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
async function runStep(verb, rawArgs, ctx, deps) {
|
|
124
|
-
const label = COMMANDS[verb];
|
|
125
|
-
const raw = String(rawArgs === undefined || rawArgs === null ? '' : rawArgs).trim();
|
|
126
|
-
if (raw !== '') return { ok: false, level: 'error', text: `${label}: takes no argument.` };
|
|
127
|
-
|
|
128
|
-
const cwd = sessionCwd(ctx);
|
|
129
|
-
let outcome;
|
|
130
|
-
try {
|
|
131
|
-
outcome = await pick(deps, 'run', defaultRun)(CODEGRAPH_BIN, [verb, '.'], cwd);
|
|
132
|
-
} catch (err) {
|
|
133
|
-
return { ok: false, level: 'error', text: `${label}: failed — ${firstLine((err && err.message) || String(err))}` };
|
|
134
|
-
}
|
|
135
|
-
const out = outcome && typeof outcome === 'object' ? outcome : {};
|
|
136
|
-
const summary = summarize(label, out);
|
|
137
|
-
// The CLI answers `sync` in a checkout with no index on stderr with exit 1,
|
|
138
|
-
// so the recognised message decides before the exit status does.
|
|
139
|
-
if (summary && (summary.ok || /no index/.test(summary.text))) return summary;
|
|
140
|
-
if (out.error) {
|
|
141
|
-
return { ok: false, level: 'error', text: `${label}: failed — ${firstLine(out.error) || 'unknown error'}` };
|
|
142
|
-
}
|
|
143
|
-
if (out.status !== 0) {
|
|
144
|
-
const exit = Number.isInteger(out.status) ? out.status : 'unknown';
|
|
145
|
-
const detail = firstLine(plain(out.stderr)) || firstLine(plain(out.stdout)) || 'no output';
|
|
146
|
-
return { ok: false, level: 'error', text: `${label}: exit ${exit} — ${detail}` };
|
|
147
|
-
}
|
|
148
|
-
return summary || { ok: true, level: 'info', text: `${label}: done` };
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// `/codegraph-init` and `/codegraph-sync` — one awaited CLI run at the session's
|
|
152
|
-
// current directory, reported by its real exit status.
|
|
153
|
-
function codegraphInit(rawArgs, ctx, deps) {
|
|
154
|
-
return runStep('init', rawArgs, ctx, deps);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function codegraphSync(rawArgs, ctx, deps) {
|
|
158
|
-
return runStep('sync', rawArgs, ctx, deps);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
module.exports = {
|
|
162
|
-
codegraphHook,
|
|
163
|
-
codegraphInit,
|
|
164
|
-
codegraphSync,
|
|
165
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
## ODD worktrees
|
|
2
|
-
|
|
3
|
-
Each ODD feature has its own worktree.
|
|
4
|
-
|
|
5
|
-
Starting a new ODD: create its worktree (`worktree_create`) before writing
|
|
6
|
-
anything.
|
|
7
|
-
|
|
8
|
-
Resuming an ODD: check whether it already has an associated worktree. If it does,
|
|
9
|
-
resume it there; if it does not, create it. ODD work never starts in the principal
|
|
10
|
-
checkout.
|
|
11
|
-
|
|
12
|
-
`worktree_create` places the checkout at `<repo-parent>/<repo-name>-worktrees/<name>`
|
|
13
|
-
and runs `codegraph init` there, so the new checkout has its own index from the
|
|
14
|
-
start. Edits and writes trigger a background `codegraph sync` for that checkout.
|
|
15
|
-
Every worktree keeps its own `.codegraph/`; never copy, symlink or reuse another
|
|
16
|
-
checkout's index.
|
|
17
|
-
|
|
18
|
-
When the work is merged into the trunk, remove the checkout (`worktree_delete`) —
|
|
19
|
-
the branch is kept, so the merge comes first.
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
## ODD worktrees
|
|
2
|
-
|
|
3
|
-
Each ODD feature has its own worktree.
|
|
4
|
-
|
|
5
|
-
Starting a new ODD: create its worktree (`worktree_create`) before writing
|
|
6
|
-
anything.
|
|
7
|
-
|
|
8
|
-
Resuming an ODD: check whether it already has an associated worktree. If it does,
|
|
9
|
-
resume it there; if it does not, create it. ODD work never starts in the principal
|
|
10
|
-
checkout.
|
|
11
|
-
|
|
12
|
-
`worktree_create` places the checkout at `<repo-parent>/<repo-name>-worktrees/<name>`.
|
|
13
|
-
|
|
14
|
-
When the work is merged into the trunk, remove the checkout (`worktree_delete`) —
|
|
15
|
-
the branch is kept, so the merge comes first.
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
// T8/S12 model-facing half: compact, agent-useful result text for the four
|
|
3
|
-
// own worktree tools this adapter formats.
|
|
4
|
-
//
|
|
5
|
-
// The extension's raw text prints one line per fact (for a listing:
|
|
6
|
-
// `worktree list: <name> <branch> thread=<id> issues=<csv> odd=<csv>` per
|
|
7
|
-
// checkout). That shape spends the agent's context on thread ids and on the
|
|
8
|
-
// ODD documents a checkout HAPPENS TO HOLD. This module builds the
|
|
9
|
-
// model-facing text from the SAME `details` object execute() already
|
|
10
|
-
// returns, so:
|
|
11
|
-
//
|
|
12
|
-
// * `details` (and every other result field) is preserved byte for byte —
|
|
13
|
-
// the UI card and runtime callers keep their contract;
|
|
14
|
-
// * only the text content is replaced, and non-text content (images and
|
|
15
|
-
// anything else) survives in place;
|
|
16
|
-
// * an error, partial, malformed or unrecognized result is returned
|
|
17
|
-
// UNCHANGED — a failure's prose is its diagnostics, and this module
|
|
18
|
-
// never turns "not enough structured evidence" into an invented
|
|
19
|
-
// success.
|
|
20
|
-
//
|
|
21
|
-
// Text style (chosen once, used everywhere): short `label: value` rows with
|
|
22
|
-
// a stable order, plus one `·`-separated row per checkout for listings, whose
|
|
23
|
-
// invariant cells are declared in the header line. No key=value dumps, no
|
|
24
|
-
// quoted path prose, no repeated title, no truncation: values are emitted
|
|
25
|
-
// whole. A listing row is `name · branch · path`, followed by ONE state cell
|
|
26
|
-
// only when the row is not the ordinary "registered and live" case — `missing`
|
|
27
|
-
// (the path exists but git no longer lists the checkout) or `unregistered` (a
|
|
28
|
-
// live checkout the registry does not own) — so a reader still tells those
|
|
29
|
-
// apart while nothing repeats what the row already says (S6).
|
|
30
|
-
//
|
|
31
|
-
// Free of side effects: no filesystem, network, registry, process or timing
|
|
32
|
-
// access, so it can run inside any execute() wrapper.
|
|
33
|
-
//
|
|
34
|
-
// NO ISSUES, NO ODD (S1): a worktree carries neither an issue list nor an ODD
|
|
35
|
-
// document any more, so no worktree display mentions them. The registry still
|
|
36
|
-
// stores those legacy records (preserved bytes), but `worktree_list` no longer
|
|
37
|
-
// publishes them in its text or its details, and this module would ignore
|
|
38
|
-
// `details.worktrees[].issues`, `.assignedOdd` and `.odd` if a producer ever
|
|
39
|
-
// supplied them again.
|
|
40
|
-
//
|
|
41
|
-
// The create tool is deliberately NOT in this list: it writes its own short
|
|
42
|
-
// ordered text (`created:`/`path:`/`codegraph:` plus one `warning:` row each),
|
|
43
|
-
// and the retired create-or-update builder that predated it is gone with the
|
|
44
|
-
// old contract.
|
|
45
|
-
|
|
46
|
-
const WORKTREE_MODEL_TOOLS = [
|
|
47
|
-
'worktree_list',
|
|
48
|
-
'worktree_delete',
|
|
49
|
-
'worktree_session_open',
|
|
50
|
-
'worktree_warp',
|
|
51
|
-
];
|
|
52
|
-
|
|
53
|
-
// ANSI SGR/OSC-8 sequences and C0/C1 controls (multi-line structure is
|
|
54
|
-
// irrelevant here: every value is folded onto one line).
|
|
55
|
-
const ANSI_PATTERN = /\x1b\[[0-9;]*m|\x1b\]8;;.*?\x07/g;
|
|
56
|
-
// eslint-disable-next-line no-control-regex
|
|
57
|
-
const CONTROL_PATTERN = /[\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g;
|
|
58
|
-
|
|
59
|
-
const LIST_LEGEND = 'name · branch · path';
|
|
60
|
-
|
|
61
|
-
// S6: the trailing state cell is optional and self-describing, so the legend
|
|
62
|
-
// declares only the three cells every row carries. Existence is implied by the
|
|
63
|
-
// listing itself — a checkout whose path is gone is pruned before it can be
|
|
64
|
-
// listed — so a normal state is never worth a cell, and `agent` (the ordinary
|
|
65
|
-
// registered worktree) is never worth one either. `principal` repeats the row's
|
|
66
|
-
// own name, `unregistered` repeats its state, and an existence spelling in
|
|
67
|
-
// `kind` repeats what the listing already proves, so all three collapse away
|
|
68
|
-
// while a kind the row does NOT already state still prints.
|
|
69
|
-
const ORDINARY_STATUS = new Set(['', 'live', 'exists']);
|
|
70
|
-
const ORDINARY_KIND = new Set(['', 'agent']);
|
|
71
|
-
|
|
72
|
-
// One-line, escape-free, whitespace-folded value. Branch names and paths are
|
|
73
|
-
// untrusted input: a raw escape or newline must never reshape a row.
|
|
74
|
-
function clean(value) {
|
|
75
|
-
if (typeof value !== 'string') return '';
|
|
76
|
-
return value.replace(ANSI_PATTERN, '').replace(CONTROL_PATTERN, '').replace(/\s+/g, ' ').trim();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function asRecord(value) {
|
|
80
|
-
if (value !== null && typeof value === 'object' && !Array.isArray(value)) return value;
|
|
81
|
-
return {};
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Mirrors lib/worktree-git.js slugifyBranch and the extension's slugPart, so
|
|
85
|
-
// the model text names the same identifier `warp`/`close` accept.
|
|
86
|
-
function slugify(value) {
|
|
87
|
-
const slug = clean(value).toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/^-+|-+$/g, '');
|
|
88
|
-
return slug === '' ? 'worktree' : slug;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function baseName(value) {
|
|
92
|
-
const text = clean(value).replace(/\/+$/, '');
|
|
93
|
-
if (text.length === 0) return '';
|
|
94
|
-
const parts = text.split('/');
|
|
95
|
-
return parts[parts.length - 1];
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Warnings are already the summarized, agent-useful form the extension
|
|
99
|
-
// produced (failed hook steps, pruned stale records, dropped legacy
|
|
100
|
-
// associations). They are kept verbatim, deduplicated, and never replaced by
|
|
101
|
-
// raw hook/command output. `pruneError` is a bare reason string, so it is
|
|
102
|
-
// added only when no warning already carries it; a FAILED creation-hook step
|
|
103
|
-
// is added the same way from its own detail line, so a hook failure stays
|
|
104
|
-
// visible even if the warning list ever stops summarizing it. Skipped steps
|
|
105
|
-
// and stdout are never copied: they cost context and the warnings already say
|
|
106
|
-
// what matters.
|
|
107
|
-
function warningRows(details) {
|
|
108
|
-
const rows = [];
|
|
109
|
-
const seen = [];
|
|
110
|
-
// A warning the extension already summarized is kept once, verbatim.
|
|
111
|
-
const pushNew = (text) => {
|
|
112
|
-
if (text.length === 0 || seen.includes(text)) return;
|
|
113
|
-
seen.push(text);
|
|
114
|
-
rows.push(`warning: ${text}`);
|
|
115
|
-
};
|
|
116
|
-
// A bare reason field is dropped when a warning already carries it.
|
|
117
|
-
const pushDerived = (text) => {
|
|
118
|
-
if (text.length === 0 || seen.some((known) => known.includes(text))) return;
|
|
119
|
-
pushNew(text);
|
|
120
|
-
};
|
|
121
|
-
const warnings = Array.isArray(details.warnings) ? details.warnings : [];
|
|
122
|
-
for (const warning of warnings) pushNew(clean(warning));
|
|
123
|
-
pushDerived(clean(details.pruneError));
|
|
124
|
-
const hooks = asRecord(details.hooks);
|
|
125
|
-
const steps = Array.isArray(hooks.steps) ? hooks.steps : [];
|
|
126
|
-
for (const step of steps) {
|
|
127
|
-
const record = asRecord(step);
|
|
128
|
-
if (record.status !== 'failed') continue;
|
|
129
|
-
pushDerived(clean(record.detail));
|
|
130
|
-
}
|
|
131
|
-
return rows;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
function listRows(details) {
|
|
135
|
-
if (!Array.isArray(details.worktrees)) return null;
|
|
136
|
-
const entries = details.worktrees;
|
|
137
|
-
const count = typeof details.count === 'number' && Number.isFinite(details.count)
|
|
138
|
-
? details.count
|
|
139
|
-
: entries.length;
|
|
140
|
-
const rows = [entries.length > 0 ? `worktrees: ${count} (${LIST_LEGEND})` : `worktrees: ${count}`];
|
|
141
|
-
for (const entry of entries) {
|
|
142
|
-
const row = asRecord(entry);
|
|
143
|
-
const name = clean(row.name) || baseName(row.path);
|
|
144
|
-
const branch = clean(row.branch);
|
|
145
|
-
const target = clean(row.path);
|
|
146
|
-
const status = clean(row.status);
|
|
147
|
-
// S6: what changes how the row must be read stays; the ordinary case does
|
|
148
|
-
// not spend a cell saying so.
|
|
149
|
-
const state = ORDINARY_STATUS.has(status) ? '' : status;
|
|
150
|
-
const kind = clean(row.kind);
|
|
151
|
-
const kindCell = ORDINARY_KIND.has(kind) || ORDINARY_STATUS.has(kind) || kind === name || kind === state
|
|
152
|
-
? ''
|
|
153
|
-
: kind;
|
|
154
|
-
const cells = [name, branch, target, kindCell, state].filter((cell) => cell.length > 0);
|
|
155
|
-
if (cells.length === 0) continue;
|
|
156
|
-
// S1: the row IS the checkout's identity. Issues and ODD documents are not
|
|
157
|
-
// part of a worktree any more, so they never reach a listing row even when
|
|
158
|
-
// the details still carry the preserved legacy fields.
|
|
159
|
-
rows.push(cells.join(' · '));
|
|
160
|
-
}
|
|
161
|
-
rows.push(...warningRows(details));
|
|
162
|
-
return rows;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function closeRows(details) {
|
|
166
|
-
const branch = clean(details.branch);
|
|
167
|
-
const target = clean(details.path);
|
|
168
|
-
if (branch.length === 0 && target.length === 0) return null;
|
|
169
|
-
const name = branch.length > 0 ? slugify(branch) : baseName(target);
|
|
170
|
-
const rows = ['outcome: removed'];
|
|
171
|
-
if (name.length > 0) rows.push(`name: ${name}`);
|
|
172
|
-
if (branch.length > 0) rows.push(`branch: ${branch}`);
|
|
173
|
-
if (target.length > 0) rows.push(`path: ${target}`);
|
|
174
|
-
rows.push(`branch state: ${details.branchKept === false ? 'deleted' : 'kept'}`);
|
|
175
|
-
// A pre-removal warp is part of the outcome: the caller's session is no
|
|
176
|
-
// longer where it was, so the destination must stay visible.
|
|
177
|
-
const warp = asRecord(details.warp);
|
|
178
|
-
const warpTarget = [clean(warp.name), clean(warp.path)].filter((part) => part.length > 0).join(' · ');
|
|
179
|
-
if (warpTarget.length > 0) rows.push(`session: warped to ${warpTarget}`);
|
|
180
|
-
// A skipped or partially reconciled Herdr workspace never fails the close,
|
|
181
|
-
// so its status (and the notice explaining it) has to reach the agent.
|
|
182
|
-
const workspace = asRecord(details.herdrWorkspace);
|
|
183
|
-
const workspaceStatus = clean(workspace.status);
|
|
184
|
-
if (workspaceStatus.length > 0) {
|
|
185
|
-
const notice = clean(workspace.notice);
|
|
186
|
-
rows.push(notice.length > 0 ? `herdr workspace: ${workspaceStatus} · ${notice}` : `herdr workspace: ${workspaceStatus}`);
|
|
187
|
-
}
|
|
188
|
-
rows.push(...warningRows(details));
|
|
189
|
-
return rows;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function sessionOpenRows(details) {
|
|
193
|
-
const worktree = clean(details.worktree);
|
|
194
|
-
const session = clean(details.sessionId);
|
|
195
|
-
const target = clean(details.path);
|
|
196
|
-
if (worktree.length === 0 && session.length === 0 && target.length === 0) return null;
|
|
197
|
-
const rows = [`outcome: ${details.resumed === true ? 'resumed' : 'opened'}`];
|
|
198
|
-
if (worktree.length > 0) rows.push(`worktree: ${worktree}`);
|
|
199
|
-
const branch = clean(details.branch);
|
|
200
|
-
if (branch.length > 0) rows.push(`branch: ${branch}`);
|
|
201
|
-
if (target.length > 0) rows.push(`path: ${target}`);
|
|
202
|
-
// The session id, workspace and pane are the routing ids a caller needs to
|
|
203
|
-
// reach the session it just started; the agent name names the agent.
|
|
204
|
-
if (session.length > 0) rows.push(`session: ${session}`);
|
|
205
|
-
const workspace = clean(details.workspaceId);
|
|
206
|
-
if (workspace.length > 0) rows.push(`workspace: ${workspace}`);
|
|
207
|
-
const pane = clean(details.paneId);
|
|
208
|
-
if (pane.length > 0) rows.push(`pane: ${pane}`);
|
|
209
|
-
const agent = clean(details.agentName);
|
|
210
|
-
if (agent.length > 0) rows.push(`agent: ${agent}`);
|
|
211
|
-
rows.push(...warningRows(details));
|
|
212
|
-
return rows;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function warpRows(details) {
|
|
216
|
-
const name = clean(details.name);
|
|
217
|
-
const target = clean(details.path);
|
|
218
|
-
if (name.length === 0 && target.length === 0) return null;
|
|
219
|
-
const rows = [`outcome: ${details.alreadyThere === true ? 'already there' : 'moved'}`];
|
|
220
|
-
const source = [clean(details.fromName), clean(details.from)].filter((part) => part.length > 0).join(' · ');
|
|
221
|
-
if (source.length > 0) rows.push(`from: ${source}`);
|
|
222
|
-
// `to` carries the continuation target: the name the next call accepts and
|
|
223
|
-
// the absolute path the session now works in.
|
|
224
|
-
const destination = [name, target].filter((part) => part.length > 0).join(' · ');
|
|
225
|
-
if (destination.length > 0) rows.push(`to: ${destination}`);
|
|
226
|
-
const branch = clean(details.branch);
|
|
227
|
-
if (branch.length > 0) rows.push(`branch: ${branch}`);
|
|
228
|
-
rows.push(...warningRows(details));
|
|
229
|
-
return rows;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
const ROW_BUILDERS = {
|
|
233
|
-
worktree_list: listRows,
|
|
234
|
-
worktree_delete: closeRows,
|
|
235
|
-
worktree_session_open: sessionOpenRows,
|
|
236
|
-
worktree_warp: warpRows,
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
// Replace every text entry with ONE formatted entry at the position of the
|
|
240
|
-
// first one, keeping non-text entries (images, …) untouched and in order. The
|
|
241
|
-
// caller guarantees at least one text entry (hasTextContent below).
|
|
242
|
-
function rebuildContent(content, text) {
|
|
243
|
-
const entries = [];
|
|
244
|
-
let placed = false;
|
|
245
|
-
for (const entry of content) {
|
|
246
|
-
if (entry && entry.type === 'text' && typeof entry.text === 'string') {
|
|
247
|
-
if (!placed) {
|
|
248
|
-
entries.push({ ...entry, text });
|
|
249
|
-
placed = true;
|
|
250
|
-
}
|
|
251
|
-
continue;
|
|
252
|
-
}
|
|
253
|
-
entries.push(entry);
|
|
254
|
-
}
|
|
255
|
-
return entries;
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function hasTextContent(content) {
|
|
259
|
-
return content.some((entry) => entry && entry.type === 'text' && typeof entry.text === 'string');
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Format one own worktree tool result for the model.
|
|
264
|
-
*
|
|
265
|
-
* @param {string} toolName One of WORKTREE_MODEL_TOOLS.
|
|
266
|
-
* @param {object} result The tool result ({content, details, isError?}).
|
|
267
|
-
* @returns {object} The same result with the text content replaced when the
|
|
268
|
-
* tool is known, the result is a successful structured one, and the details
|
|
269
|
-
* carry enough evidence; otherwise the INPUT UNCHANGED (same reference).
|
|
270
|
-
*/
|
|
271
|
-
function formatWorktreeModelResult(toolName, result) {
|
|
272
|
-
if (typeof toolName !== 'string' || !Object.prototype.hasOwnProperty.call(ROW_BUILDERS, toolName)) {
|
|
273
|
-
return result;
|
|
274
|
-
}
|
|
275
|
-
if (result === null || typeof result !== 'object' || Array.isArray(result)) return result;
|
|
276
|
-
// A failure's prose IS its diagnostics, and a partial result is not
|
|
277
|
-
// settled: both are returned untouched rather than reformatted.
|
|
278
|
-
if (result.isError === true || result.isPartial === true) return result;
|
|
279
|
-
const content = result.content;
|
|
280
|
-
if (!Array.isArray(content) || !hasTextContent(content)) return result;
|
|
281
|
-
const details = result.details;
|
|
282
|
-
if (details === null || typeof details !== 'object' || Array.isArray(details)) return result;
|
|
283
|
-
const rows = ROW_BUILDERS[toolName](details);
|
|
284
|
-
if (rows === null || rows.length === 0) return result;
|
|
285
|
-
return { ...result, content: rebuildContent(content, rows.join('\n')) };
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
module.exports = {
|
|
289
|
-
formatWorktreeModelResult,
|
|
290
|
-
WORKTREE_MODEL_TOOLS,
|
|
291
|
-
};
|