pi-odd-worktree 2.0.0 → 3.0.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 +54 -311
- package/extensions/odd-worktree-tools.ts +4149 -2447
- package/lib/bash-activity.js +1164 -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 +1416 -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 +308 -14
- 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 -711
- 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 +1419 -0
- package/tools/bash-design.test.js +1091 -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 +610 -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 +1871 -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 +391 -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 +1512 -66
- package/tools/issues-open-guard.test.js +1096 -0
- package/tools/issues-section.test.js +4195 -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 +2569 -308
- 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 +477 -93
- 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
|
@@ -0,0 +1,1020 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
// Index preparation (S2) and its coordination (S3): one create-or-sync policy per root, a linked worktree seeded
|
|
3
|
+
// from the main checkout's index, and every write of the package under one init lock and one per-project sync lease.
|
|
4
|
+
//
|
|
5
|
+
// The decision is `planIndexAction`: an existing `.codegraph` is synced, a fresh git project with a marker file is
|
|
6
|
+
// initialised, anything else is left alone. A linked worktree extends it: it indexes its own tree and never shares
|
|
7
|
+
// the main checkout's index, so an unindexed worktree whose main checkout has an index is SEEDED from it (a copy
|
|
8
|
+
// while nobody writes it, then one sync in the worktree) instead of paying a full init.
|
|
9
|
+
//
|
|
10
|
+
// Nothing here runs in the foreground of a caller that can await: every command is a fixed argv with a bounded
|
|
11
|
+
// timeout through an injected runner, spawned from the temp directory with the project as an argument, and a
|
|
12
|
+
// timeout only reports the failure once the terminated process is gone. No shell string, no `spawnSync`, no network.
|
|
13
|
+
//
|
|
14
|
+
// Every seam is injected with a real default: `run`, `hasBinary`, `exists`, `fs`, `lock`, `sync`, `copySeed`,
|
|
15
|
+
// `sourceBusy`, `clock` (`now`). The CLI's presence is probed ONCE PER PROCESS (the probe is cached per probe
|
|
16
|
+
// function, so the real PATH probe runs once and a test's own seam runs once for that seam), and without it nothing
|
|
17
|
+
// here runs at all. Role gating is the caller's: it passes `role` or `mayWrite`, and a read-only role starts no
|
|
18
|
+
// index write here, in the post-init path or in a compaction.
|
|
19
|
+
|
|
20
|
+
const nodeFs = require('node:fs');
|
|
21
|
+
const nodePath = require('node:path');
|
|
22
|
+
const { spawn } = require('node:child_process');
|
|
23
|
+
|
|
24
|
+
const { codegraphSpawn } = require('./codegraph-paths.js');
|
|
25
|
+
const { mayInitiateIndexWrite, sessionIndexRole } = require('./codegraph-role.js');
|
|
26
|
+
const {
|
|
27
|
+
INIT_TIMEOUT_MS,
|
|
28
|
+
SYNC_TIMEOUT_MS,
|
|
29
|
+
codegraphWritingIndex,
|
|
30
|
+
realInitLock,
|
|
31
|
+
realSyncLease,
|
|
32
|
+
} = require('./codegraph-lock.js');
|
|
33
|
+
const { listWorktreesAsync } = require('./worktree-git.js');
|
|
34
|
+
|
|
35
|
+
/** One of these next to a `.git` is what makes a directory a project worth indexing automatically. */
|
|
36
|
+
const INIT_PROJECT_MARKERS = [
|
|
37
|
+
'composer.json',
|
|
38
|
+
'package.json',
|
|
39
|
+
'pyproject.toml',
|
|
40
|
+
'go.mod',
|
|
41
|
+
'Cargo.toml',
|
|
42
|
+
'Gemfile',
|
|
43
|
+
'pom.xml',
|
|
44
|
+
'build.gradle',
|
|
45
|
+
'build.gradle.kts',
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
/** The environment variable a subagent child carries; a child shares its parent's project. */
|
|
49
|
+
const CHILD_ENV = 'GENTLE_PI_AGENTS_CHILD';
|
|
50
|
+
|
|
51
|
+
/** The native CodeGraph extension tool: the one that can `init` itself, and the one the hook observes. */
|
|
52
|
+
const NATIVE_CODEGRAPH_TOOL = 'codegraph';
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* How long the tool result of a native `codegraph init` waits for the sync requested after it before reporting it as
|
|
56
|
+
* pending. The request is not cancelled: it stays recorded and runs when the index is free.
|
|
57
|
+
*/
|
|
58
|
+
const POST_INIT_SYNC_WAIT_MS = 10_000;
|
|
59
|
+
|
|
60
|
+
/** How long a killed command may take to be gone before the timeout is reported anyway. */
|
|
61
|
+
const KILL_WAIT_MS = 10_000;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* How long after the soft kill a child that is still alive is escalated to a hard one. It sits inside the reporting
|
|
65
|
+
* grace (`killWaitMs`, `KILL_WAIT_MS` by default): the escalation happens while the run still reports its timeout,
|
|
66
|
+
* never instead of that report. A caller's `escalationMs` is clamped to at most half that grace and never negative,
|
|
67
|
+
* so a configured escape hatch cannot silently disable the hard kill.
|
|
68
|
+
*/
|
|
69
|
+
const KILL_ESCALATION_MS = 2_000;
|
|
70
|
+
|
|
71
|
+
/** The `node:fs` surface used here, so a test can stand in for it. */
|
|
72
|
+
const FS_NAMES = ['copyFileSync', 'existsSync', 'mkdirSync', 'readFileSync', 'renameSync', 'rmSync', 'statSync', 'writeFileSync'];
|
|
73
|
+
|
|
74
|
+
function fsOf(options) {
|
|
75
|
+
const fs = options && options.fs;
|
|
76
|
+
if (!fs) return nodeFs;
|
|
77
|
+
const merged = {};
|
|
78
|
+
for (const name of FS_NAMES) merged[name] = typeof fs[name] === 'function' ? fs[name] : nodeFs[name];
|
|
79
|
+
return merged;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The rename the atomic seed publish uses, or `undefined` when the seam this caller supplied has none: a fake without
|
|
84
|
+
* a rename keeps the two-write publish it always had instead of gaining an operation it never provided.
|
|
85
|
+
*/
|
|
86
|
+
function renamerOf(options) {
|
|
87
|
+
const fs = options && options.fs;
|
|
88
|
+
if (!fs) return nodeFs.renameSync;
|
|
89
|
+
return typeof fs.renameSync === 'function' ? fs.renameSync : undefined;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function lockOf(value) {
|
|
93
|
+
if (value === undefined) return realInitLock;
|
|
94
|
+
return value || undefined;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function syncOf(value) {
|
|
98
|
+
if (value === undefined) return realSyncLease;
|
|
99
|
+
return value || undefined;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Whether this session may start an index write at all. The caller decides (it passes `mayWrite`, or the `role` it
|
|
104
|
+
* read from the session's tools); without either, the role is read from the child environment the same way the
|
|
105
|
+
* prompt section reads it. A read-only role never writes the index it reads.
|
|
106
|
+
*/
|
|
107
|
+
function mayWriteHere(input) {
|
|
108
|
+
if (input && typeof input.mayWrite === 'boolean') return input.mayWrite;
|
|
109
|
+
if (input && input.role !== undefined) return mayInitiateIndexWrite(input.role);
|
|
110
|
+
return mayInitiateIndexWrite(sessionIndexRole((input && input.env) || process.env));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// ---- The CLI seam (S2) ----
|
|
114
|
+
|
|
115
|
+
/** A PATH presence probe that never runs the binary. */
|
|
116
|
+
function binaryOnPath(command) {
|
|
117
|
+
const directories = (process.env.PATH || '').split(nodePath.delimiter).filter((directory) => directory.length > 0);
|
|
118
|
+
if (process.platform !== 'win32') return directories.some((directory) => nodeFs.existsSync(nodePath.join(directory, command)));
|
|
119
|
+
const extensions = ['', ...(process.env.PATHEXT || '.EXE;.CMD;.BAT;.COM').split(';')];
|
|
120
|
+
return directories.some((directory) => extensions.some((extension) => nodeFs.existsSync(nodePath.join(directory, `${command}${extension}`))
|
|
121
|
+
|| nodeFs.existsSync(nodePath.join(directory, `${command}${extension.toLowerCase()}`))));
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The probe result of each probe function this process used: the CLI's presence is checked once per process, so a
|
|
126
|
+
* session start and a compaction never probe twice. An injected seam is cached by its own identity, which is what
|
|
127
|
+
* keeps a test's answer its own.
|
|
128
|
+
*/
|
|
129
|
+
const probeCache = new Map();
|
|
130
|
+
|
|
131
|
+
/** Whether the `codegraph` CLI is present, probed at most once per process (or once per injected seam). */
|
|
132
|
+
function cliAvailable(options = {}) {
|
|
133
|
+
const hasBinary = typeof options.hasBinary === 'function' ? options.hasBinary : binaryOnPath;
|
|
134
|
+
if (!probeCache.has(hasBinary)) {
|
|
135
|
+
let present = false;
|
|
136
|
+
try {
|
|
137
|
+
present = Boolean(hasBinary('codegraph'));
|
|
138
|
+
} catch {
|
|
139
|
+
present = false;
|
|
140
|
+
}
|
|
141
|
+
probeCache.set(hasBinary, present);
|
|
142
|
+
}
|
|
143
|
+
return probeCache.get(hasBinary);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ---- Running the CLI (S1, S2, S3) ----
|
|
147
|
+
|
|
148
|
+
/** Kills a child and its tree, without ever throwing: the caller is already finishing a run. */
|
|
149
|
+
function killTree(pid, child, options = {}) {
|
|
150
|
+
const spawnChild = typeof options.spawn === 'function' ? options.spawn : spawn;
|
|
151
|
+
const platform = options.platform || process.platform;
|
|
152
|
+
const signal = options.signal || 'SIGTERM';
|
|
153
|
+
if (platform === 'win32' && pid !== undefined) {
|
|
154
|
+
try {
|
|
155
|
+
// `taskkill /T /F` is already the hard kill: the escalation re-runs it only while the pid is still alive.
|
|
156
|
+
spawnChild('taskkill', ['/pid', String(pid), '/T', '/F'], { windowsHide: true, stdio: 'ignore' }).on('error', () => {});
|
|
157
|
+
return;
|
|
158
|
+
} catch {
|
|
159
|
+
// Fall through to the plain kill.
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
child.kill(signal);
|
|
164
|
+
} catch {
|
|
165
|
+
// Already gone.
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** Whether a spawned child has already left, so a second kill would only signal a pid that may be reused. */
|
|
170
|
+
function childExited(child) {
|
|
171
|
+
const code = child && child.exitCode;
|
|
172
|
+
const signal = child && child.signalCode;
|
|
173
|
+
return (code !== undefined && code !== null) || (signal !== undefined && signal !== null);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Runs the codegraph CLI with fixed arguments for the project in `cwd`. It runs from the temp directory with the
|
|
178
|
+
* project as the last argument (`sync -q <path>`, `init -y <path>`), because cmd.exe does not accept a UNC working
|
|
179
|
+
* directory and another spelling of one root starts another daemon. `onSpawn` gets the pid of the process, which the
|
|
180
|
+
* init lock records, and whether that pid is only the shell spawned around the real command (Windows runs the npm
|
|
181
|
+
* shim through a shell). A timeout kills the process tree, escalates a child that survived the soft kill to a hard
|
|
182
|
+
* kill, and only reports the failure once that process is gone; a run that timed out is never a success.
|
|
183
|
+
*/
|
|
184
|
+
function runCodegraph(args, cwd, timeoutMs, onSpawn, options = {}) {
|
|
185
|
+
const platform = options.platform || process.platform;
|
|
186
|
+
const spawnChild = typeof options.spawn === 'function' ? options.spawn : spawn;
|
|
187
|
+
const projectFor = typeof options.projectFor === 'function' ? options.projectFor : (project) => project;
|
|
188
|
+
const bound = Number.isFinite(timeoutMs) && timeoutMs > 0 ? timeoutMs : SYNC_TIMEOUT_MS;
|
|
189
|
+
const killWaitMs = Number.isFinite(options.killWaitMs) && options.killWaitMs > 0 ? options.killWaitMs : KILL_WAIT_MS;
|
|
190
|
+
// A delay at or beyond the reporting grace would be cleared by that report and never fire, so the effective delay is
|
|
191
|
+
// capped at half the grace: the hard kill always has room to land before the run reports its timeout.
|
|
192
|
+
const requestedEscalationMs = Number.isFinite(options.escalationMs) && options.escalationMs >= 0
|
|
193
|
+
? options.escalationMs
|
|
194
|
+
: KILL_ESCALATION_MS;
|
|
195
|
+
const escalationMs = Math.min(requestedEscalationMs, killWaitMs / 2);
|
|
196
|
+
return new Promise((resolve) => {
|
|
197
|
+
let settled = false;
|
|
198
|
+
let timedOut = false;
|
|
199
|
+
let timer;
|
|
200
|
+
let escalation;
|
|
201
|
+
let grace;
|
|
202
|
+
const finish = (ok) => {
|
|
203
|
+
if (settled) return;
|
|
204
|
+
settled = true;
|
|
205
|
+
clearTimeout(timer);
|
|
206
|
+
clearTimeout(escalation);
|
|
207
|
+
clearTimeout(grace);
|
|
208
|
+
resolve(ok);
|
|
209
|
+
};
|
|
210
|
+
let project = cwd;
|
|
211
|
+
try {
|
|
212
|
+
project = projectFor(cwd);
|
|
213
|
+
} catch {
|
|
214
|
+
project = cwd;
|
|
215
|
+
}
|
|
216
|
+
// Windows needs a shell to run the .cmd shim that npm installs for codegraph: the pid that comes back is that
|
|
217
|
+
// shell, not the process that ends up writing the index.
|
|
218
|
+
const shelled = platform === 'win32';
|
|
219
|
+
let child;
|
|
220
|
+
try {
|
|
221
|
+
const run = codegraphSpawn(args, project, platform);
|
|
222
|
+
const env = { ...process.env, ...run.env };
|
|
223
|
+
child = run.shell
|
|
224
|
+
? spawnChild(run.command, { cwd: run.cwd, env, shell: true, windowsHide: true, stdio: 'ignore' })
|
|
225
|
+
: spawnChild(run.command, run.args, { cwd: run.cwd, env, windowsHide: true, stdio: 'ignore' });
|
|
226
|
+
} catch {
|
|
227
|
+
resolve(false);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (child.pid !== undefined && typeof onSpawn === 'function') {
|
|
231
|
+
try {
|
|
232
|
+
onSpawn(child.pid, { proxy: shelled });
|
|
233
|
+
} catch {
|
|
234
|
+
// Recording the pid is never worth failing the run.
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
timer = setTimeout(() => {
|
|
238
|
+
// From here the run is a timeout: whatever exit code the child ends with, it is reported as a failure.
|
|
239
|
+
timedOut = true;
|
|
240
|
+
killTree(child.pid, child, { spawn: spawnChild, platform });
|
|
241
|
+
// A child that trapped the soft kill is escalated while the same grace still runs: the hard kill fires only if
|
|
242
|
+
// the child is still alive, and it never turns the timeout into a success.
|
|
243
|
+
escalation = setTimeout(() => {
|
|
244
|
+
if (settled || childExited(child)) return;
|
|
245
|
+
killTree(child.pid, child, { spawn: spawnChild, platform, signal: 'SIGKILL' });
|
|
246
|
+
}, escalationMs);
|
|
247
|
+
if (escalation && typeof escalation.unref === 'function') escalation.unref();
|
|
248
|
+
// A killed command may still be closing; the run reports the failure once that one is gone.
|
|
249
|
+
grace = setTimeout(() => finish(false), killWaitMs);
|
|
250
|
+
}, bound);
|
|
251
|
+
child.on('error', () => finish(false));
|
|
252
|
+
child.on('close', (code) => finish(!timedOut && code === 0));
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// ---- The create-or-sync decision (S2) ----
|
|
257
|
+
|
|
258
|
+
/** An existing index is synced; a fresh git project with a marker file is initialised; anything else is left alone. */
|
|
259
|
+
function planIndexAction(cwd, exists = (p) => nodeFs.existsSync(p)) {
|
|
260
|
+
if (exists(nodePath.join(cwd, '.codegraph'))) return 'sync';
|
|
261
|
+
if (exists(nodePath.join(cwd, '.git')) && INIT_PROJECT_MARKERS.some((marker) => exists(nodePath.join(cwd, marker)))) return 'init';
|
|
262
|
+
return 'none';
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* How a directory relates to a git repository. A linked worktree carries its own `.codegraph` decision: it indexes
|
|
267
|
+
* its own tree, never the main checkout's. There, `.git` is a file with `gitdir: <path>` pointing into the main
|
|
268
|
+
* repository's `.git/worktrees/<name>`; the common root is found by walking up to the directory whose `.git` is a
|
|
269
|
+
* directory. A plain repo, a pointer to a directory that is not there, or anything unreadable is not a worktree:
|
|
270
|
+
* the caller falls back to the normal per-directory decision.
|
|
271
|
+
*/
|
|
272
|
+
function worktreeOf(cwd, options = {}) {
|
|
273
|
+
const fs = fsOf(options);
|
|
274
|
+
try {
|
|
275
|
+
const dotGit = nodePath.join(cwd, '.git');
|
|
276
|
+
if (!fs.existsSync(dotGit) || !fs.statSync(dotGit).isFile()) return { worktree: false };
|
|
277
|
+
const first = fs.readFileSync(dotGit, 'utf8').split(/\r?\n/, 1)[0] || '';
|
|
278
|
+
const match = /^gitdir:\s*(.+)$/i.exec(first.trim());
|
|
279
|
+
if (!match) return { worktree: false };
|
|
280
|
+
const gitdir = nodePath.resolve(cwd, match[1].trim());
|
|
281
|
+
if (!fs.existsSync(gitdir)) return { worktree: false };
|
|
282
|
+
// The worktree gitdir is <commonRoot>/.git/worktrees/<name>; walk up to the .git directory itself.
|
|
283
|
+
let dir = nodePath.dirname(gitdir);
|
|
284
|
+
for (;;) {
|
|
285
|
+
const candidate = nodePath.join(dir, '.git');
|
|
286
|
+
if (fs.existsSync(candidate) && fs.statSync(candidate).isDirectory()) return { worktree: true, commonRoot: dir };
|
|
287
|
+
const parent = nodePath.dirname(dir);
|
|
288
|
+
if (parent === dir) return { worktree: false };
|
|
289
|
+
dir = parent;
|
|
290
|
+
}
|
|
291
|
+
} catch {
|
|
292
|
+
return { worktree: false };
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* The index decision for one directory, extending the per-directory decision with worktrees: a worktree that already
|
|
298
|
+
* has its own index is synced, one whose main checkout has an index is seeded from it, and everything else falls back
|
|
299
|
+
* to `planIndexAction`.
|
|
300
|
+
*/
|
|
301
|
+
function worktreeIndexAction(cwd, exists = (p) => nodeFs.existsSync(p), options = {}) {
|
|
302
|
+
const found = worktreeOf(cwd, options);
|
|
303
|
+
if (found.worktree && exists(nodePath.join(cwd, '.codegraph'))) return { action: 'sync' };
|
|
304
|
+
if (found.worktree && exists(nodePath.join(found.commonRoot, '.codegraph'))) return { action: 'seed', commonRoot: found.commonRoot };
|
|
305
|
+
return { action: planIndexAction(cwd, exists) };
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// ---- Seeding a linked worktree (S2, S3) ----
|
|
309
|
+
|
|
310
|
+
/** Every SQLite database file, and so every real CodeGraph index, starts with these 16 bytes. */
|
|
311
|
+
const SQLITE_MAGIC = 'SQLite format 3\u0000';
|
|
312
|
+
|
|
313
|
+
/** The seed copy for real runs: a plain file copy of the db, staged so a failure leaves nothing behind. */
|
|
314
|
+
function defaultCopySeed(from, to) {
|
|
315
|
+
try {
|
|
316
|
+
nodeFs.copyFileSync(from, to);
|
|
317
|
+
return true;
|
|
318
|
+
} catch {
|
|
319
|
+
return false;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Whether the staged copy is a plausible index: non-empty and starting with the SQLite magic, read through the
|
|
325
|
+
* injected fs seam so it is never inferred from a stat. A read that fails, throws or answers something else is not an
|
|
326
|
+
* index, and the caller treats that exactly like a failed copy. Never throws.
|
|
327
|
+
*/
|
|
328
|
+
function isPlausibleIndex(fs, staged) {
|
|
329
|
+
try {
|
|
330
|
+
const head = fs.readFileSync(staged);
|
|
331
|
+
if (typeof head === 'string') return head.length >= SQLITE_MAGIC.length && head.startsWith(SQLITE_MAGIC);
|
|
332
|
+
if (head instanceof Uint8Array) {
|
|
333
|
+
if (head.length < SQLITE_MAGIC.length) return false;
|
|
334
|
+
return Buffer.from(head.subarray(0, SQLITE_MAGIC.length)).toString('latin1') === SQLITE_MAGIC;
|
|
335
|
+
}
|
|
336
|
+
return false;
|
|
337
|
+
} catch {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
/** An entry stat answered ENOENT for: it is positively gone, which is a fact a caller may act on. */
|
|
343
|
+
const ENTRY_ABSENT = Object.freeze({ state: 'absent' });
|
|
344
|
+
/** An entry whose identity could not be read: unknown, which is never "gone" and never "the same one". */
|
|
345
|
+
const ENTRY_UNKNOWN = Object.freeze({ state: 'unknown' });
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* The identity of one filesystem entry, read through the injected fs seam — and, when it cannot be read, WHICH kind of
|
|
349
|
+
* nothing that is:
|
|
350
|
+
* - `{ state: 'present', dev, ino }`: the entry is there and its identity is known;
|
|
351
|
+
* - `ENTRY_ABSENT`: stat said ENOENT, so the entry is positively gone;
|
|
352
|
+
* - `ENTRY_UNKNOWN`: any other failed read (EACCES, EPERM, a throwing seam, an answer without a device and inode).
|
|
353
|
+
* The rule that must not be reintroduced anywhere below: UNKNOWN is never read as "absent" and never as "the same
|
|
354
|
+
* entry". A caller removes something only on a positive reading — the identity it captured, or a positively gone db.
|
|
355
|
+
*/
|
|
356
|
+
function identityOf(fs, entry) {
|
|
357
|
+
try {
|
|
358
|
+
const stats = fs.statSync(entry);
|
|
359
|
+
if (!stats || !Number.isFinite(stats.dev) || !Number.isFinite(stats.ino)) return ENTRY_UNKNOWN;
|
|
360
|
+
return { state: 'present', dev: stats.dev, ino: stats.ino };
|
|
361
|
+
} catch (error) {
|
|
362
|
+
return error && error.code === 'ENOENT' ? ENTRY_ABSENT : ENTRY_UNKNOWN;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
/** Whether the entry on disk is provably the very one whose identity was captured: two present readings, same inode. */
|
|
367
|
+
function sameIdentity(observed, captured) {
|
|
368
|
+
return observed.state === 'present' && captured !== undefined && captured.state === 'present' && observed.dev === captured.dev && observed.ino === captured.ino;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Whether the entry is positively gone. Only ENOENT says that; every other failed read is unknown and says nothing. */
|
|
372
|
+
function isPositivelyAbsent(observed) {
|
|
373
|
+
return observed.state === 'absent';
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
/**
|
|
377
|
+
* Publishes the staged copy as the worktree's index: one rename where the seam has one, so a crash cannot leave a
|
|
378
|
+
* half-published db, and the older two-write copy when the seam provides no rename.
|
|
379
|
+
*/
|
|
380
|
+
function publishStagedCopy(fs, staged, target, rename) {
|
|
381
|
+
if (typeof rename === 'function') {
|
|
382
|
+
rename(staged, target);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
385
|
+
fs.copyFileSync(staged, target);
|
|
386
|
+
fs.rmSync(staged, { force: true });
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Seeds the worktree's own index by copying the main repo's `codegraph.db`, never while the main index is being
|
|
391
|
+
* written and never leaving a half-built `.codegraph` behind: the copy is staged, validated as a plausible index, and
|
|
392
|
+
* only then published in one move. A copy that fails, and a copy that is not a real index, are the same failure: the
|
|
393
|
+
* staging file and the directory this call created are removed, and the caller runs no sync over it. The `-wal`/`-shm`
|
|
394
|
+
* siblings are deliberately not copied: the source db must be at rest, and the first sync in the worktree rebuilds
|
|
395
|
+
* whatever the WAL held.
|
|
396
|
+
*
|
|
397
|
+
* Ownership is captured, never inferred: the directory's identity is recorded the instant this call's `mkdir` creates
|
|
398
|
+
* it, and the published db's identity right after the rename. `onPublished` receives both, so the caller's rollback can
|
|
399
|
+
* prove what it removes instead of assuming it from a successful publish. A directory this call did not create is
|
|
400
|
+
* never published into: an `EEXIST` at the creation step means another actor owns it, so nothing is written there at
|
|
401
|
+
* all — `onJoined` is called when that directory already holds an index (the caller's "someone else's index is there"
|
|
402
|
+
* outcome), and a directory without one is simply a failed seed. Both fail closed.
|
|
403
|
+
*/
|
|
404
|
+
function seedWorktreeIndex(input = {}) {
|
|
405
|
+
const fs = fsOf(input);
|
|
406
|
+
const source = nodePath.join(input.commonRoot, '.codegraph', 'codegraph.db');
|
|
407
|
+
if (!fs.existsSync(source) || input.sourceBusy()) return false;
|
|
408
|
+
const targetDir = nodePath.join(input.worktree, '.codegraph');
|
|
409
|
+
const target = nodePath.join(targetDir, 'codegraph.db');
|
|
410
|
+
const staged = nodePath.join(targetDir, 'codegraph.db.seeding');
|
|
411
|
+
const copy = typeof input.copy === 'function' ? input.copy : defaultCopySeed;
|
|
412
|
+
const rename = 'rename' in input ? input.rename : renamerOf(input);
|
|
413
|
+
// A non-recursive mkdir is the proof of ownership: it succeeds only when THIS call created the directory, and the
|
|
414
|
+
// identity is captured at once. A directory that was already there belongs to someone else.
|
|
415
|
+
try {
|
|
416
|
+
// The worktree root is not what this call owns: creating it keeps the recursive mkdir this replaced.
|
|
417
|
+
fs.mkdirSync(nodePath.dirname(targetDir), { recursive: true });
|
|
418
|
+
} catch {
|
|
419
|
+
// A root this call cannot create makes the copy below fail, exactly as it did before.
|
|
420
|
+
}
|
|
421
|
+
let dirIdentity;
|
|
422
|
+
try {
|
|
423
|
+
fs.mkdirSync(targetDir);
|
|
424
|
+
dirIdentity = identityOf(fs, targetDir);
|
|
425
|
+
} catch (error) {
|
|
426
|
+
// This call did not create the directory, so it must not publish into it, whatever the reason it failed:
|
|
427
|
+
// - EEXIST: another actor owns it. With an index already readable in it that is the module's "someone else's
|
|
428
|
+
// index is there" outcome; a bare or unreadable directory is simply a failed seed.
|
|
429
|
+
// - any other failure: there is no directory of this call's to publish into.
|
|
430
|
+
// Both fail closed: nothing is written, synced or removed.
|
|
431
|
+
if (error && error.code === 'EEXIST' && identityOf(fs, target).state === 'present' && typeof input.onJoined === 'function') {
|
|
432
|
+
try {
|
|
433
|
+
input.onJoined();
|
|
434
|
+
} catch {
|
|
435
|
+
// Reporting the join is never worth failing a seed that published nothing.
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
const abandon = () => {
|
|
441
|
+
try {
|
|
442
|
+
// Nothing is removed from a directory this call cannot prove is still the one it created: a foreign one belongs
|
|
443
|
+
// to another actor, and an UNKNOWN reading (a failed stat) proves neither way, so it fails closed and removes
|
|
444
|
+
// nothing — not the staging file, not the directory.
|
|
445
|
+
if (!sameIdentity(identityOf(fs, targetDir), dirIdentity)) return;
|
|
446
|
+
fs.rmSync(staged, { force: true });
|
|
447
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
448
|
+
} catch {
|
|
449
|
+
// Nothing left to remove.
|
|
450
|
+
}
|
|
451
|
+
};
|
|
452
|
+
try {
|
|
453
|
+
if (!copy(source, staged)) {
|
|
454
|
+
abandon();
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
if (!isPlausibleIndex(fs, staged)) {
|
|
458
|
+
abandon();
|
|
459
|
+
return false;
|
|
460
|
+
}
|
|
461
|
+
publishStagedCopy(fs, staged, target, rename);
|
|
462
|
+
if (typeof input.onPublished === 'function') {
|
|
463
|
+
try {
|
|
464
|
+
input.onPublished({ dir: dirIdentity, db: identityOf(fs, target) });
|
|
465
|
+
} catch {
|
|
466
|
+
// Reporting the identity is never worth failing a seed that was published.
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
return true;
|
|
470
|
+
} catch {
|
|
471
|
+
abandon();
|
|
472
|
+
return false;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Rolls back the seed this call published — and only that, and only on a positive reading. The directory must still be
|
|
478
|
+
* the very one this session created, and the database must be either still the one it published or positively gone
|
|
479
|
+
* (ENOENT). A database that differs, and one whose identity is UNKNOWN because its stat failed, both keep everything:
|
|
480
|
+
* unknown never authorizes a removal. Never throws; reports whether anything was removed.
|
|
481
|
+
*/
|
|
482
|
+
function removePublishedSeed(fs, cwd, identity = {}) {
|
|
483
|
+
const targetDir = nodePath.join(cwd, '.codegraph');
|
|
484
|
+
const target = nodePath.join(targetDir, 'codegraph.db');
|
|
485
|
+
try {
|
|
486
|
+
if (!sameIdentity(identityOf(fs, targetDir), identity.dir)) return false;
|
|
487
|
+
// The database is removed only when it is provably the one this session published; a positively absent one is no
|
|
488
|
+
// protection at all. A foreign one, or one that cannot be read, is left where it is — with its directory.
|
|
489
|
+
const published = identityOf(fs, target);
|
|
490
|
+
if (!sameIdentity(published, identity.db) && !isPositivelyAbsent(published)) return false;
|
|
491
|
+
fs.rmSync(targetDir, { recursive: true, force: true });
|
|
492
|
+
return true;
|
|
493
|
+
} catch {
|
|
494
|
+
// A rollback that cannot finish is not worth turning into a different outcome: the seed is unconfirmed either way.
|
|
495
|
+
return false;
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* Seeds the unindexed linked worktrees of one repository, each one under its own index lock, exactly like the
|
|
501
|
+
* per-directory seed: a worktree whose index another session is writing is left alone, a fresh decision is taken once
|
|
502
|
+
* the lock is held, and a failed copy leaves nothing behind. The main checkout is never seeded (it is not a worktree).
|
|
503
|
+
* Never throws.
|
|
504
|
+
*/
|
|
505
|
+
function seedLinkedWorktrees(input = {}) {
|
|
506
|
+
const fs = fsOf(input);
|
|
507
|
+
const exists = typeof input.exists === 'function' ? input.exists : (p) => fs.existsSync(p);
|
|
508
|
+
const lock = input.lock === undefined ? realInitLock : (input.lock || undefined);
|
|
509
|
+
// Without an explicit source check the main checkout's own lock decides, exactly as the create path does.
|
|
510
|
+
const sourceBusy = typeof input.sourceBusy === 'function' ? input.sourceBusy : (root) => lock?.isHeld(root) ?? false;
|
|
511
|
+
const copy = typeof input.copy === 'function' ? input.copy : defaultCopySeed;
|
|
512
|
+
const result = { seeded: [], skipped: [] };
|
|
513
|
+
for (const root of Array.isArray(input.worktrees) ? input.worktrees : []) {
|
|
514
|
+
try {
|
|
515
|
+
const found = worktreeOf(root, { fs });
|
|
516
|
+
if (!found.worktree) continue; // The main checkout and anything not linked is not our business here.
|
|
517
|
+
if (exists(nodePath.join(root, '.codegraph'))) {
|
|
518
|
+
result.skipped.push({ worktree: root, reason: 'already has an index' });
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
const attempt = lock?.acquire(root, { kind: 'init' });
|
|
522
|
+
if (attempt?.status === 'busy') {
|
|
523
|
+
result.skipped.push({ worktree: root, reason: "another session is writing this worktree's index" });
|
|
524
|
+
continue;
|
|
525
|
+
}
|
|
526
|
+
try {
|
|
527
|
+
// Judged again under the lock: another session may have seeded it while this one waited.
|
|
528
|
+
if (exists(nodePath.join(root, '.codegraph'))) {
|
|
529
|
+
result.skipped.push({ worktree: root, reason: 'already has an index' });
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
if (sourceBusy(found.commonRoot)) {
|
|
533
|
+
result.skipped.push({ worktree: root, reason: "the main checkout's index is being written" });
|
|
534
|
+
continue;
|
|
535
|
+
}
|
|
536
|
+
let joined = false;
|
|
537
|
+
const seeded = seedWorktreeIndex({
|
|
538
|
+
worktree: root,
|
|
539
|
+
commonRoot: found.commonRoot,
|
|
540
|
+
sourceBusy: () => sourceBusy(found.commonRoot),
|
|
541
|
+
copy,
|
|
542
|
+
rename: renamerOf(input),
|
|
543
|
+
fs,
|
|
544
|
+
onJoined: () => {
|
|
545
|
+
joined = true;
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
if (seeded) result.seeded.push(nodePath.join(root, '.codegraph', 'codegraph.db'));
|
|
549
|
+
else if (joined) result.skipped.push({ worktree: root, reason: 'already has an index' });
|
|
550
|
+
else result.skipped.push({ worktree: root, reason: 'the seed copy failed' });
|
|
551
|
+
} finally {
|
|
552
|
+
attempt?.release();
|
|
553
|
+
}
|
|
554
|
+
} catch (error) {
|
|
555
|
+
result.skipped.push({ worktree: root, reason: `unexpected: ${error instanceof Error ? error.message : String(error)}` });
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return result;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* The linked worktrees of the repository `cwd` belongs to, from one `git worktree list` through the async runner
|
|
563
|
+
* (never a blocking one). A `list` seam that answers a porcelain text or a path list replaces the git read; a
|
|
564
|
+
* directory that is not a Git repository, or a git that cannot answer, yields nothing instead of throwing.
|
|
565
|
+
*/
|
|
566
|
+
async function linkedWorktrees(input = {}) {
|
|
567
|
+
try {
|
|
568
|
+
const repoRootFound = worktreeOf(input.cwd, { fs: input.fs });
|
|
569
|
+
const repoRoot = repoRootFound.worktree ? repoRootFound.commonRoot : input.cwd;
|
|
570
|
+
const listed = typeof input.list === 'function'
|
|
571
|
+
? await input.list(repoRoot)
|
|
572
|
+
: (await listWorktreesAsync(repoRoot, { runAsync: input.runAsync, timeoutMs: input.timeoutMs })).map((entry) => entry.path);
|
|
573
|
+
if (Array.isArray(listed)) return listed.filter((entry) => typeof entry === 'string' && entry.length > 0);
|
|
574
|
+
if (typeof listed !== 'string') return [];
|
|
575
|
+
return listed
|
|
576
|
+
.split('\n')
|
|
577
|
+
.filter((line) => line.startsWith('worktree '))
|
|
578
|
+
.map((line) => line.slice('worktree '.length).trim())
|
|
579
|
+
.filter((root) => root.length > 0);
|
|
580
|
+
} catch {
|
|
581
|
+
return [];
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// ---- The coordinated sync (S3) ----
|
|
586
|
+
|
|
587
|
+
/** The honest reading of one coordination result: only a run that came back is `synced`. */
|
|
588
|
+
function coordinatedSyncOutcome(outcome) {
|
|
589
|
+
if (outcome.status === 'ran') return outcome.ok ? 'synced' : 'failed';
|
|
590
|
+
if (outcome.status === 'coalesced') return 'coalesced';
|
|
591
|
+
if (outcome.status === 'queued') return 'pending';
|
|
592
|
+
return 'unavailable';
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
/** The honest reading of one attempt made under the index lock alone, with no lease to wait on. */
|
|
596
|
+
function attemptOutcome(attempt) {
|
|
597
|
+
if (!attempt.ran) return 'pending';
|
|
598
|
+
return attempt.ok ? 'synced' : 'failed';
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/**
|
|
602
|
+
* One sync attempt under the coordination. It takes the package's index lock for the whole run, so an init can never
|
|
603
|
+
* begin in the middle of a sync: the lock is taken, not merely observed, which is what closes the window between
|
|
604
|
+
* deciding to sync and starting it. When an init (or any other writer of this package) holds the lock, nothing runs
|
|
605
|
+
* and the request stays pending instead of being dropped. The process it starts is reported to `onSpawn`, so the
|
|
606
|
+
* coordination can tell a run that ended from one that outlived its session.
|
|
607
|
+
*/
|
|
608
|
+
async function runSyncAttempt(input, onSpawn) {
|
|
609
|
+
const attempt = input.lock?.acquire(input.cwd, { kind: 'sync' });
|
|
610
|
+
if (attempt?.status === 'busy') return { ran: false };
|
|
611
|
+
const adopt = attempt?.status === 'acquired' ? attempt.adopt : () => {};
|
|
612
|
+
try {
|
|
613
|
+
const ok = await input.run(['sync', '-q'], input.cwd, SYNC_TIMEOUT_MS, (pid, options) => {
|
|
614
|
+
try {
|
|
615
|
+
adopt(pid, options);
|
|
616
|
+
} catch {
|
|
617
|
+
// Recording the pid is never worth failing the sync.
|
|
618
|
+
}
|
|
619
|
+
try {
|
|
620
|
+
if (typeof onSpawn === 'function') onSpawn(pid, options);
|
|
621
|
+
} catch {
|
|
622
|
+
// The coordination record is never worth failing the sync.
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
return { ran: true, ok };
|
|
626
|
+
} finally {
|
|
627
|
+
attempt?.release();
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
/** One coordinated sync with resolved seams: the lease decides whether this session runs it or joins a follow-up. */
|
|
632
|
+
async function coordinatedSync(input) {
|
|
633
|
+
const attempt = (onSpawn) => runSyncAttempt({ cwd: input.project, lock: input.lock, run: input.run }, onSpawn);
|
|
634
|
+
if (!input.sync || typeof input.sync.request !== 'function') return attemptOutcome(await attempt(() => {}));
|
|
635
|
+
return coordinatedSyncOutcome(await input.sync.request(input.project, attempt));
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/** Asks the coordination for one sync of `project` and reports what it achieved, never overstating it. */
|
|
639
|
+
async function requestCoordinatedSync(input = {}) {
|
|
640
|
+
return coordinatedSync({
|
|
641
|
+
project: input.project,
|
|
642
|
+
sync: syncOf(input.sync),
|
|
643
|
+
lock: lockOf(input.lock),
|
|
644
|
+
run: input.run === undefined ? runCodegraph : input.run,
|
|
645
|
+
});
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// ---- The session's own preparation (S2) ----
|
|
649
|
+
|
|
650
|
+
/**
|
|
651
|
+
* A subagent child may run in a linked git worktree of its own instead of the parent's project. There it does the
|
|
652
|
+
* same background work a fresh session would: seed its own index from the main checkout's, or initialise one.
|
|
653
|
+
* Everywhere else a child keeps skipping: it shares the parent's cwd and the parent already did the work.
|
|
654
|
+
*/
|
|
655
|
+
function childWorktreeNeedsIndex(input, mayWrite) {
|
|
656
|
+
if (!mayWrite) return false;
|
|
657
|
+
if (!worktreeOf(input.cwd, { fs: input.fs }).worktree) return false;
|
|
658
|
+
if (input.exists(nodePath.join(input.cwd, '.codegraph'))) return false;
|
|
659
|
+
const action = worktreeIndexAction(input.cwd, input.exists, { fs: input.fs }).action;
|
|
660
|
+
return action === 'seed' || action === 'init';
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/** Subagent children of one parent share the parent's project, and a /reload is not a new session. */
|
|
664
|
+
function skipsSession(input, mayWrite) {
|
|
665
|
+
const child = Boolean(input.env) && input.env[CHILD_ENV] === '1';
|
|
666
|
+
if (child && !childWorktreeNeedsIndex(input, mayWrite)) return true;
|
|
667
|
+
return input.reason === 'reload';
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
/**
|
|
671
|
+
* Brings the index of the checkout up to date, or creates it, and reports which of the four actions it took: `init`,
|
|
672
|
+
* `seed`, `sync` or `none`. Never rejects, never blocks a caller that awaits it, and never claims a write another
|
|
673
|
+
* session made. A joined, coalesced, queued or unavailable request is reported as exactly that.
|
|
674
|
+
*/
|
|
675
|
+
async function autoIndex(input = {}) {
|
|
676
|
+
const fs = fsOf(input);
|
|
677
|
+
const exists = typeof input.exists === 'function' ? input.exists : (p) => fs.existsSync(p);
|
|
678
|
+
const cwd = input.cwd;
|
|
679
|
+
const env = input.env || {};
|
|
680
|
+
const run = typeof input.run === 'function' ? input.run : runCodegraph;
|
|
681
|
+
const lock = lockOf(input.lock);
|
|
682
|
+
const sync = syncOf(input.sync);
|
|
683
|
+
const codegraphBusy = typeof input.codegraphBusy === 'function' ? input.codegraphBusy : (project) => codegraphWritingIndex(project);
|
|
684
|
+
const mayWrite = mayWriteHere(input);
|
|
685
|
+
try {
|
|
686
|
+
if (!mayWrite) return { action: 'none', ok: true, skipped: 'read-only' };
|
|
687
|
+
if (skipsSession({ cwd, env, reason: input.reason, exists, fs }, mayWrite)) return { action: 'none', ok: true };
|
|
688
|
+
if (!cliAvailable({ hasBinary: input.hasBinary })) return { action: 'none', ok: true, skipped: 'no-cli' };
|
|
689
|
+
const worktreeAction = worktreeIndexAction(cwd, exists, { fs });
|
|
690
|
+
const action = worktreeAction.action;
|
|
691
|
+
if (action === 'none') return { action, ok: true };
|
|
692
|
+
const announce = () => {
|
|
693
|
+
try {
|
|
694
|
+
if (typeof input.onStart === 'function') input.onStart(action);
|
|
695
|
+
} catch {
|
|
696
|
+
// Telling the caller is never worth stopping the index.
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
if (action === 'seed') {
|
|
701
|
+
// Two sessions starting at once in the same worktree must not seed twice: the worktree's own init lock covers
|
|
702
|
+
// the whole seed-plus-sync, exactly like a plain init.
|
|
703
|
+
const attempt = lock?.acquire(cwd);
|
|
704
|
+
if (attempt?.status === 'busy') return { action, ok: true, joined: true };
|
|
705
|
+
const adopt = attempt?.status === 'acquired' ? attempt.adopt : () => {};
|
|
706
|
+
try {
|
|
707
|
+
if (exists(nodePath.join(cwd, '.codegraph'))) return { action, ok: true, joined: true };
|
|
708
|
+
const commonRoot = worktreeAction.commonRoot;
|
|
709
|
+
const busy = typeof input.sourceBusy === 'function' ? input.sourceBusy : (root) => lock?.isHeld(root) ?? false;
|
|
710
|
+
if (busy(commonRoot)) return { action, ok: true, joined: true };
|
|
711
|
+
announce();
|
|
712
|
+
// The identity of what this call creates, so the rollback below can prove ownership instead of inferring it.
|
|
713
|
+
let published;
|
|
714
|
+
let joined = false;
|
|
715
|
+
const seeded = seedWorktreeIndex({
|
|
716
|
+
worktree: cwd,
|
|
717
|
+
commonRoot,
|
|
718
|
+
sourceBusy: () => busy(commonRoot),
|
|
719
|
+
copy: typeof input.copySeed === 'function' ? input.copySeed : defaultCopySeed,
|
|
720
|
+
rename: renamerOf(input),
|
|
721
|
+
fs,
|
|
722
|
+
onPublished: (identity) => {
|
|
723
|
+
published = identity;
|
|
724
|
+
},
|
|
725
|
+
onJoined: () => {
|
|
726
|
+
joined = true;
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
// Another actor created the directory in the window and its index is already in it: this session publishes
|
|
730
|
+
// nothing, syncs nothing, and says exactly what it says when it finds that directory under the lock.
|
|
731
|
+
if (joined) return { action, ok: true, joined: true };
|
|
732
|
+
if (!seeded) return { action, ok: false };
|
|
733
|
+
// The seeded db reflects the main tree; the worktree's first sync reconciles it to this tree.
|
|
734
|
+
let synced = false;
|
|
735
|
+
try {
|
|
736
|
+
synced = await run(['sync', '-q'], cwd, SYNC_TIMEOUT_MS, (pid, options) => adopt(pid, options));
|
|
737
|
+
} catch {
|
|
738
|
+
synced = false;
|
|
739
|
+
}
|
|
740
|
+
if (!synced) {
|
|
741
|
+
// Nothing this session published survives a failed validation, and nothing it did not publish is touched: the
|
|
742
|
+
// rollback removes only the directory and db that still carry the identity captured at creation time.
|
|
743
|
+
removePublishedSeed(fs, cwd, published);
|
|
744
|
+
return { action, ok: false };
|
|
745
|
+
}
|
|
746
|
+
return { action, ok: true };
|
|
747
|
+
} finally {
|
|
748
|
+
attempt?.release();
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
if (action === 'sync') {
|
|
753
|
+
// An init holds the index: nothing may touch it meanwhile, and this session leaves it to that one. A sync
|
|
754
|
+
// holding it is different: the index exists, so this request is coalesced into it instead.
|
|
755
|
+
if (lock?.isHeld(cwd) && (typeof lock.isInitRunning === 'function' ? lock.isInitRunning(cwd) : true)) {
|
|
756
|
+
return { action, ok: true, joined: true };
|
|
757
|
+
}
|
|
758
|
+
announce();
|
|
759
|
+
// Every write goes through the coordination: the shared lease when there is one, and always through the
|
|
760
|
+
// package's index lock, so an init cannot begin in the middle of this sync (nor this one inside an init).
|
|
761
|
+
const outcome = await coordinatedSync({ project: cwd, sync, lock, run });
|
|
762
|
+
if (outcome === 'synced') return { action, ok: true };
|
|
763
|
+
if (outcome === 'coalesced') return { action, ok: true, coalesced: true };
|
|
764
|
+
if (outcome === 'pending') return { action, ok: true, queued: true };
|
|
765
|
+
if (outcome === 'unavailable') return { action, ok: false, unavailable: true };
|
|
766
|
+
return { action, ok: false };
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
const attempt = lock?.acquire(cwd);
|
|
770
|
+
if (attempt?.status === 'busy') return { action, ok: true, joined: true };
|
|
771
|
+
const adopt = attempt?.status === 'acquired' ? attempt.adopt : () => {};
|
|
772
|
+
try {
|
|
773
|
+
if (exists(nodePath.join(cwd, '.codegraph'))) {
|
|
774
|
+
// Another party (another tool, a terminal) created the index while this session waited for the lock.
|
|
775
|
+
return { action, ok: true, joined: true };
|
|
776
|
+
}
|
|
777
|
+
announce();
|
|
778
|
+
// The lock records the pid of the init, so it stays held while that process lives, even after this session.
|
|
779
|
+
const initialised = await run(['init', '-y'], cwd, INIT_TIMEOUT_MS, (pid, options) => adopt(pid, options));
|
|
780
|
+
if (!initialised && codegraphBusy(cwd)) {
|
|
781
|
+
// CodeGraph's own lock still names a live init: another party is building this index, not this session.
|
|
782
|
+
return { action, ok: true, joined: true };
|
|
783
|
+
}
|
|
784
|
+
// A failure of this session's own init, with or without a half-built index, is a failure.
|
|
785
|
+
return { action, ok: initialised };
|
|
786
|
+
} finally {
|
|
787
|
+
attempt?.release();
|
|
788
|
+
}
|
|
789
|
+
} catch {
|
|
790
|
+
return { action: planIndexAction(cwd, exists), ok: false };
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* The index first, then whatever the caller warms: `lib/codegraph-index.js` runs no warm-up of its own (the daemon
|
|
796
|
+
* belongs to another unit), so a caller that supplies `warm` gets it after a preparation that left an index, and one
|
|
797
|
+
* that does not gets `skipped`. Never rejects.
|
|
798
|
+
*/
|
|
799
|
+
async function prepareProject(input = {}) {
|
|
800
|
+
const index = await autoIndex(input);
|
|
801
|
+
if (index.action !== 'none') {
|
|
802
|
+
try {
|
|
803
|
+
if (typeof input.onIndexed === 'function') input.onIndexed(index);
|
|
804
|
+
} catch {
|
|
805
|
+
// Telling the caller is never worth stopping the warm-up.
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
// A sync that failed still leaves an index to warm; a failed init or seed leaves nothing worth warming.
|
|
809
|
+
const hasIndex = !index.joined
|
|
810
|
+
&& (index.action === 'sync' || (index.action === 'init' && index.ok) || (index.action === 'seed' && index.ok));
|
|
811
|
+
const fs = fsOf(input);
|
|
812
|
+
const exists = typeof input.exists === 'function' ? input.exists : (p) => fs.existsSync(p);
|
|
813
|
+
const skipped = skipsSession({ cwd: input.cwd, env: input.env || {}, reason: input.reason, exists, fs }, mayWriteHere(input));
|
|
814
|
+
if (skipped || !hasIndex || typeof input.warm !== 'function') return { index, warm: 'skipped' };
|
|
815
|
+
try {
|
|
816
|
+
if (typeof input.onWarmStart === 'function') input.onWarmStart();
|
|
817
|
+
} catch {
|
|
818
|
+
// Telling the caller is never worth stopping the warm-up.
|
|
819
|
+
}
|
|
820
|
+
try {
|
|
821
|
+
return { index, warm: (await input.warm(input.cwd)) ? 'ok' : 'failed' };
|
|
822
|
+
} catch {
|
|
823
|
+
return { index, warm: 'failed' };
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// ---- The observed native `init` (S3) ----
|
|
828
|
+
|
|
829
|
+
/**
|
|
830
|
+
* After a native `codegraph init` came back successfully, requests exactly one coordinated sync of that checkout
|
|
831
|
+
* through the package's own coordination, never a second uncoordinated `init` or `sync`. It returns `completed` only
|
|
832
|
+
* for a run that really came back, `pending` for a request that is still recorded on disk, and `failed` or
|
|
833
|
+
* `unavailable` otherwise; the final outcome is logged even when the bounded wait already returned `pending`.
|
|
834
|
+
* Never throws.
|
|
835
|
+
*/
|
|
836
|
+
async function syncAfterNativeInit(input = {}) {
|
|
837
|
+
const started = Date.now();
|
|
838
|
+
const exists = typeof input.exists === 'function' ? input.exists : (p) => nodeFs.existsSync(p);
|
|
839
|
+
const log = (outcome) => {
|
|
840
|
+
try {
|
|
841
|
+
if (typeof input.log === 'function') input.log({ cwd: input.cwd, outcome, ms: Date.now() - started });
|
|
842
|
+
} catch {
|
|
843
|
+
// A log is never worth failing the tool call.
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
try {
|
|
847
|
+
if (!mayWriteHere(input)) return 'skipped-read-only';
|
|
848
|
+
if (!exists(nodePath.join(input.cwd, '.codegraph'))) {
|
|
849
|
+
// A successful init that left no index gives nothing to sync, and syncing a missing index would fail.
|
|
850
|
+
log('init-sync-failed');
|
|
851
|
+
return 'failed';
|
|
852
|
+
}
|
|
853
|
+
const request = coordinatedSync({
|
|
854
|
+
project: input.cwd,
|
|
855
|
+
sync: syncOf(input.sync),
|
|
856
|
+
lock: lockOf(input.lock),
|
|
857
|
+
run: input.run === undefined ? runCodegraph : input.run,
|
|
858
|
+
});
|
|
859
|
+
// The request keeps going after the wait below; its real outcome is what gets logged, once.
|
|
860
|
+
const settled = request.then(
|
|
861
|
+
(value) => {
|
|
862
|
+
log(`init-sync-${value}`);
|
|
863
|
+
return value;
|
|
864
|
+
},
|
|
865
|
+
() => {
|
|
866
|
+
log('init-sync-failed');
|
|
867
|
+
return 'failed';
|
|
868
|
+
},
|
|
869
|
+
);
|
|
870
|
+
const waitMs = Math.max(1, Number.isFinite(input.waitMs) ? input.waitMs : POST_INIT_SYNC_WAIT_MS);
|
|
871
|
+
let timer;
|
|
872
|
+
const raced = await Promise.race([
|
|
873
|
+
settled,
|
|
874
|
+
new Promise((resolve) => {
|
|
875
|
+
timer = setTimeout(() => resolve(undefined), waitMs);
|
|
876
|
+
}),
|
|
877
|
+
]);
|
|
878
|
+
clearTimeout(timer);
|
|
879
|
+
if (raced === undefined) return 'pending';
|
|
880
|
+
if (raced === 'synced' || raced === 'coalesced') return 'completed';
|
|
881
|
+
if (raced === 'pending') return 'pending';
|
|
882
|
+
if (raced === 'unavailable') return 'unavailable';
|
|
883
|
+
return 'failed';
|
|
884
|
+
} catch {
|
|
885
|
+
return 'failed';
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
|
|
889
|
+
// ---- The notices (S2, S3) ----
|
|
890
|
+
|
|
891
|
+
/** Nearest directory at or above `cwd` holding `.codegraph/codegraph.db`. */
|
|
892
|
+
function findIndexRoot(cwd, exists = (p) => nodeFs.existsSync(p)) {
|
|
893
|
+
for (let dir = nodePath.resolve(cwd); ;) {
|
|
894
|
+
if (exists(nodePath.join(dir, '.codegraph', 'codegraph.db'))) return dir;
|
|
895
|
+
const parent = nodePath.dirname(dir);
|
|
896
|
+
if (parent === dir) return undefined;
|
|
897
|
+
dir = parent;
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
/**
|
|
902
|
+
* The session's tools: the selected ones plus, in a subagent child, the ones the host requested for it. The MCP
|
|
903
|
+
* tools are not in `selectedTools` yet when the prompt is built, so the requested list counts there too.
|
|
904
|
+
*/
|
|
905
|
+
function noticeTools(selectedTools, requestedEnv, child) {
|
|
906
|
+
const selected = Array.isArray(selectedTools) ? selectedTools.filter((tool) => typeof tool === 'string') : [];
|
|
907
|
+
const requested = child && typeof requestedEnv === 'string'
|
|
908
|
+
? requestedEnv.split(',').map((tool) => tool.trim()).filter(Boolean)
|
|
909
|
+
: [];
|
|
910
|
+
return [...new Set([...selected, ...requested])];
|
|
911
|
+
}
|
|
912
|
+
|
|
913
|
+
/**
|
|
914
|
+
* What the index preparation is doing, said before it starts. Create-or-sync is one policy, and the wording names
|
|
915
|
+
* which of the three actions this session took: an init, a worktree seed, or a sync of an existing index.
|
|
916
|
+
*/
|
|
917
|
+
function indexStartNotice(action) {
|
|
918
|
+
if (action === 'init') return 'creating the CodeGraph index of this project...';
|
|
919
|
+
if (action === 'seed') return "seeding this worktree's CodeGraph index from the main repo's index...";
|
|
920
|
+
return 'syncing the CodeGraph index...';
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
/**
|
|
924
|
+
* How one index preparation ended, in honest terms. Only a run of this session that came back can be called synced or
|
|
925
|
+
* created: a joined, coalesced, queued or unavailable request is reported as what it is, and a failed command is
|
|
926
|
+
* never presented as a current index.
|
|
927
|
+
*/
|
|
928
|
+
function indexOutcomeNotice(result, cwd) {
|
|
929
|
+
if (result.joined) {
|
|
930
|
+
return {
|
|
931
|
+
text: result.action === 'init'
|
|
932
|
+
? 'another session is creating the CodeGraph index of this project'
|
|
933
|
+
: "another session is writing this project's CodeGraph index; this session did not sync it",
|
|
934
|
+
level: 'info',
|
|
935
|
+
};
|
|
936
|
+
}
|
|
937
|
+
if (result.coalesced) return { text: "another session's run completed the CodeGraph index sync requested here", level: 'info' };
|
|
938
|
+
if (result.queued) return { text: 'the CodeGraph index sync is queued, not run yet: it waits for the index to be free', level: 'info' };
|
|
939
|
+
if (result.unavailable) return { text: `could not coordinate the CodeGraph index sync in ${cwd}; no sync was started`, level: 'warning' };
|
|
940
|
+
if (!result.ok) return { text: `codegraph ${result.action} failed in ${cwd}; the index is not up to date`, level: 'warning' };
|
|
941
|
+
if (result.action === 'init') return { text: 'CodeGraph index created', level: 'info' };
|
|
942
|
+
if (result.action === 'seed') return { text: 'CodeGraph index seeded from the main repo and synced', level: 'info' };
|
|
943
|
+
return { text: 'CodeGraph index synced', level: 'info' };
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
/** The warm-up's outcome, kept apart from the index's: a warm daemon says nothing about the index. */
|
|
947
|
+
function warmOutcomeNotice(outcome, cwd) {
|
|
948
|
+
return outcome === 'ok'
|
|
949
|
+
? { text: 'CodeGraph ready', level: 'info' }
|
|
950
|
+
: { text: `CodeGraph warm-up failed in ${cwd}`, level: 'warning' };
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
/** Whether this finished call was a successful native `codegraph init`: the one call the hook observes. */
|
|
954
|
+
function isNativeInitResult(event) {
|
|
955
|
+
return Boolean(event)
|
|
956
|
+
&& event.toolName === NATIVE_CODEGRAPH_TOOL
|
|
957
|
+
&& Boolean(event.input) && event.input.operation === 'init'
|
|
958
|
+
&& event.isError === false;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* What the post-`init` hook does with one finished tool call: only a successful native `codegraph init` is followed
|
|
963
|
+
* by the package's own coordinated sync; a failed init keeps its original error and triggers nothing.
|
|
964
|
+
*/
|
|
965
|
+
function initHookDecision(event, role) {
|
|
966
|
+
if (!event || event.toolName !== NATIVE_CODEGRAPH_TOOL || !event.input || event.input.operation !== 'init') return 'skip-not-a-native-init';
|
|
967
|
+
if (event.isError) return 'skip-failed-init';
|
|
968
|
+
if (!mayInitiateIndexWrite(role)) return 'skip-read-only';
|
|
969
|
+
return 'sync';
|
|
970
|
+
}
|
|
971
|
+
|
|
972
|
+
/**
|
|
973
|
+
* The line the hook appends to the tool's own result. A completed sync appends
|
|
974
|
+
* nothing at all (S4): the tool's own content is the whole answer. Only a sync that
|
|
975
|
+
* did NOT complete earns one short line, and it never calls an unconfirmed index
|
|
976
|
+
* current — no plugin prefix, no second paragraph, and never the word `completed`.
|
|
977
|
+
*/
|
|
978
|
+
function postInitSyncNotice(outcome) {
|
|
979
|
+
if (outcome === 'completed') return undefined;
|
|
980
|
+
if (outcome === 'pending') return 'CodeGraph index sync pending; this index is not confirmed current.';
|
|
981
|
+
if (outcome === 'unavailable') return 'CodeGraph index sync could not start; this index is not confirmed current.';
|
|
982
|
+
if (outcome === 'skipped-read-only') return 'CodeGraph index sync skipped (read-only session); this index is not confirmed current.';
|
|
983
|
+
return 'CodeGraph index sync failed; this index may be behind.';
|
|
984
|
+
}
|
|
985
|
+
|
|
986
|
+
module.exports = {
|
|
987
|
+
CHILD_ENV,
|
|
988
|
+
INIT_PROJECT_MARKERS,
|
|
989
|
+
INIT_TIMEOUT_MS,
|
|
990
|
+
KILL_ESCALATION_MS,
|
|
991
|
+
KILL_WAIT_MS,
|
|
992
|
+
NATIVE_CODEGRAPH_TOOL,
|
|
993
|
+
POST_INIT_SYNC_WAIT_MS,
|
|
994
|
+
SYNC_TIMEOUT_MS,
|
|
995
|
+
attemptOutcome,
|
|
996
|
+
autoIndex,
|
|
997
|
+
binaryOnPath,
|
|
998
|
+
cliAvailable,
|
|
999
|
+
codegraphWritingIndex,
|
|
1000
|
+
coordinatedSyncOutcome,
|
|
1001
|
+
findIndexRoot,
|
|
1002
|
+
indexOutcomeNotice,
|
|
1003
|
+
indexStartNotice,
|
|
1004
|
+
initHookDecision,
|
|
1005
|
+
isNativeInitResult,
|
|
1006
|
+
linkedWorktrees,
|
|
1007
|
+
noticeTools,
|
|
1008
|
+
planIndexAction,
|
|
1009
|
+
postInitSyncNotice,
|
|
1010
|
+
prepareProject,
|
|
1011
|
+
requestCoordinatedSync,
|
|
1012
|
+
runCodegraph,
|
|
1013
|
+
runSyncAttempt,
|
|
1014
|
+
seedLinkedWorktrees,
|
|
1015
|
+
seedWorktreeIndex,
|
|
1016
|
+
syncAfterNativeInit,
|
|
1017
|
+
warmOutcomeNotice,
|
|
1018
|
+
worktreeIndexAction,
|
|
1019
|
+
worktreeOf,
|
|
1020
|
+
};
|