@awebai/oats 0.60.0 → 0.62.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 +15 -19
- package/bin/oats.mjs +68 -21
- package/docs/capabilities.md +1 -1
- package/docs/configuration.md +9 -0
- package/docs/desktop-cli-api.md +28 -5
- package/docs/desktop.md +7 -0
- package/docs/execution-targets.md +49 -3
- package/docs/first-team.md +8 -0
- package/docs/implementation.md +2 -1
- package/docs/named-test-runs.md +382 -0
- package/docs/official-catalog.md +1 -1
- package/docs/packages.md +5 -5
- package/docs/release-notes/v0.61.0.md +155 -0
- package/docs/release-notes/v0.62.0.md +223 -0
- package/docs/tui.md +10 -4
- package/docs/upgrading.md +133 -11
- package/docs/workspaces.md +1 -1
- package/lib/core.mjs +2 -2
- package/lib/doctor-capture.mjs +35 -0
- package/lib/session-viewer.mjs +86 -7
- package/package-catalog.json +1 -1
- package/package.json +1 -1
- package/packages/client/cli-locator.mjs +2 -2
- package/packages/client/instance-presentation.mjs +10 -0
- package/packages/client/instance-tree.mjs +48 -6
- package/packages/record/README.md +87 -13
- package/packages/record/bin/capture-hook.mjs +8 -0
- package/packages/record/bin/capture.mjs +143 -124
- package/packages/record/bin/recall.mjs +8 -3
- package/packages/record/bin/setup.mjs +115 -225
- package/packages/record/bin/turn-record.mjs +2 -2
- package/packages/record/docs/capture-service.md +1443 -28
- package/packages/record/docs/capture-status.schema.json +429 -12
- package/packages/record/lib/capture-admission.mjs +82 -0
- package/packages/record/lib/capture-aw-unit.mjs +137 -0
- package/packages/record/lib/capture-aw.mjs +31 -12
- package/packages/record/lib/capture-budget.mjs +31 -0
- package/packages/record/lib/capture-cc.mjs +39 -6
- package/packages/record/lib/capture-cleanup-queue.mjs +135 -0
- package/packages/record/lib/capture-cleanup-work.mjs +77 -0
- package/packages/record/lib/capture-command-operation.mjs +37 -0
- package/packages/record/lib/capture-command-output.mjs +61 -0
- package/packages/record/lib/capture-command-worker.mjs +6 -0
- package/packages/record/lib/capture-command.mjs +48 -0
- package/packages/record/lib/capture-completion.mjs +152 -0
- package/packages/record/lib/capture-context.mjs +50 -0
- package/packages/record/lib/capture-default-roots.mjs +30 -0
- package/packages/record/lib/capture-discovery.mjs +114 -0
- package/packages/record/lib/capture-failures.mjs +45 -0
- package/packages/record/lib/capture-health-doctor.mjs +13 -0
- package/packages/record/lib/capture-health-installation.mjs +117 -0
- package/packages/record/lib/capture-health.mjs +116 -0
- package/packages/record/lib/capture-hook-ownership.mjs +58 -0
- package/packages/record/lib/capture-hook-runner.mjs +17 -0
- package/packages/record/lib/capture-hook.mjs +26 -0
- package/packages/record/lib/capture-index-inventory.mjs +205 -0
- package/packages/record/lib/capture-index-outcomes.mjs +113 -0
- package/packages/record/lib/capture-index-reset.mjs +109 -0
- package/packages/record/lib/capture-index-work.mjs +77 -0
- package/packages/record/lib/capture-issue-preparation.mjs +73 -0
- package/packages/record/lib/capture-issues.mjs +15 -2
- package/packages/record/lib/capture-lock.mjs +102 -16
- package/packages/record/lib/capture-native-unit.mjs +322 -0
- package/packages/record/lib/capture-pass.mjs +102 -0
- package/packages/record/lib/capture-recovery-snapshot.mjs +182 -0
- package/packages/record/lib/capture-retained-scratch.mjs +213 -0
- package/packages/record/lib/capture-retry.mjs +102 -0
- package/packages/record/lib/capture-run.mjs +125 -0
- package/packages/record/lib/capture-scratch.mjs +12 -3
- package/packages/record/lib/capture-service-definition.mjs +104 -0
- package/packages/record/lib/capture-service-install.mjs +362 -0
- package/packages/record/lib/capture-service-ownership.mjs +137 -0
- package/packages/record/lib/capture-service-runner.mjs +18 -0
- package/packages/record/lib/capture-small-snapshot.mjs +85 -0
- package/packages/record/lib/capture-source-discovery.mjs +319 -0
- package/packages/record/lib/capture-source-queue.mjs +199 -0
- package/packages/record/lib/capture-source-work.mjs +85 -0
- package/packages/record/lib/capture-state.mjs +16 -71
- package/packages/record/lib/capture-status.mjs +171 -0
- package/packages/record/lib/capture-supervisor.mjs +117 -0
- package/packages/record/lib/capture-watch.mjs +32 -0
- package/packages/record/lib/capture-work-session.mjs +238 -0
- package/packages/record/lib/capture-worker.mjs +58 -0
- package/packages/record/lib/derived-state.mjs +28 -15
- package/packages/record/lib/file-lines.mjs +22 -6
- package/packages/record/lib/formats.mjs +4 -3
- package/packages/record/lib/index-capture.mjs +97 -0
- package/packages/record/lib/index-db.mjs +3 -17
- package/packages/record/lib/index-reset.mjs +19 -0
- package/packages/record/lib/store.mjs +36 -11
- package/packages/record/lib/transcript-prefix.mjs +125 -0
- package/packages/tui/lib/client.mjs +2 -2
- package/packages/tui/lib/model.mjs +15 -5
- package/packages/tui/lib/views/palette.mjs +7 -3
- package/skills/oats-getting-started/SKILL.md +1 -1
- package/docs/macos-test-runs.md +0 -246
|
@@ -12,34 +12,39 @@
|
|
|
12
12
|
// accounts) whose sources are never captured — see lib/ignore.mjs.
|
|
13
13
|
// Reconciliation is the capture; hooks and watch only decide when to run it.
|
|
14
14
|
|
|
15
|
-
import { closeSync, constants, fstatSync, openSync, readFileSync, watch } from "node:fs";
|
|
15
|
+
import { closeSync, constants, fstatSync, openSync, readFileSync, realpathSync, watch } from "node:fs";
|
|
16
16
|
import { homedir, hostname } from "node:os";
|
|
17
|
-
import { basename, join, resolve } from "node:path";
|
|
17
|
+
import { basename, isAbsolute, join, resolve } from "node:path";
|
|
18
18
|
import process from "node:process";
|
|
19
19
|
|
|
20
20
|
import { RecordStore } from "../lib/store.mjs";
|
|
21
|
-
import {
|
|
21
|
+
import { captureSessions } from "../lib/capture-cc.mjs";
|
|
22
22
|
import { sessionsForHome } from "../lib/sessions-for-home.mjs";
|
|
23
23
|
import { SESSION_FORMATS } from "../lib/formats.mjs";
|
|
24
24
|
import { cwdOfLine } from "../lib/sessions-for-home.mjs";
|
|
25
25
|
import { stageSnapshot } from "../lib/session-snapshot.mjs";
|
|
26
26
|
import { cleanupCaptureScratch } from "../lib/capture-scratch.mjs";
|
|
27
27
|
import { bufferLines } from "../lib/file-lines.mjs";
|
|
28
|
-
import { captureAwLogs, defaultCommLogDir } from "../lib/capture-aw.mjs";
|
|
29
28
|
import { withReceiptSummaries } from "../lib/receipt-summary.mjs";
|
|
30
29
|
import { RecordIndex } from "../lib/index-db.mjs";
|
|
31
30
|
import { IgnoreError, ignoreFilePath, loadIgnore } from "../lib/ignore.mjs";
|
|
32
|
-
import { CAPTURE_SOURCES, captureHealth, resetSourceCursors,
|
|
31
|
+
import { CAPTURE_SOURCES, captureHealth, resetSourceCursors, writeCaptureStatus } from "../lib/capture-state.mjs";
|
|
33
32
|
import { acquireCaptureLock } from "../lib/capture-lock.mjs";
|
|
33
|
+
import { captureHealthForDoctor } from "../lib/capture-health.mjs";
|
|
34
|
+
import { captureDefaultRootPlan, resolveCaptureDefaultRoots } from "../lib/capture-default-roots.mjs";
|
|
35
|
+
import { captureCommandPass, reportLockInitializationFailure, reportReclaimedLock, releaseDetail } from "../lib/capture-command-output.mjs";
|
|
36
|
+
import { captureWatchQueue } from "../lib/capture-watch.mjs";
|
|
37
|
+
import { launchCaptureHook } from "../lib/capture-hook.mjs";
|
|
34
38
|
|
|
35
39
|
// Fail closed but actionably: an unreadable ignore file must stop capture,
|
|
36
40
|
// as one clear line naming the file — never an uncaught stack trace.
|
|
37
|
-
|
|
41
|
+
class PrintedCaptureFailure extends Error {}
|
|
42
|
+
function loadIgnoreForCommand(recordRoot) {
|
|
38
43
|
try {
|
|
39
44
|
return loadIgnore(recordRoot);
|
|
40
45
|
} catch (err) {
|
|
41
46
|
console.error(err instanceof IgnoreError ? err.message : String(err));
|
|
42
|
-
|
|
47
|
+
throw new PrintedCaptureFailure();
|
|
43
48
|
}
|
|
44
49
|
}
|
|
45
50
|
|
|
@@ -51,6 +56,7 @@ function loadIgnoreOrExit(recordRoot) {
|
|
|
51
56
|
// it does not understand before anything can be written.
|
|
52
57
|
const VALUE_FLAGS = new Set(["root", "owner", "home", "file", "format", "source"]);
|
|
53
58
|
const BOOL_FLAGS = new Set([
|
|
59
|
+
"hook",
|
|
54
60
|
"reset-cursors",
|
|
55
61
|
"retry-set-aside",
|
|
56
62
|
"health",
|
|
@@ -71,10 +77,12 @@ const USAGE = `capture — land sessions and aw client logs in the turn record.
|
|
|
71
77
|
capture one reconciliation pass (sessions + aw logs)
|
|
72
78
|
capture --sessions-only only session transcripts (Claude Code, pi, codex)
|
|
73
79
|
capture --aw-only only aw client comm logs
|
|
80
|
+
capture --hook launch detached capture; exit 0 acknowledges
|
|
81
|
+
launch only, never capture completion
|
|
74
82
|
capture --watch pass now, then re-pass on filesystem change
|
|
75
83
|
(debounced) and every 15 minutes regardless
|
|
76
84
|
capture --status show store/stream summary, capture nothing
|
|
77
|
-
capture --health [--json] read
|
|
85
|
+
capture --health [--json] read offline installation, run and issue diagnosis
|
|
78
86
|
capture --reset-cursors [--source aw|cc|pi|codex]
|
|
79
87
|
reset selected source cursors and exit; the next
|
|
80
88
|
pass reprocesses them with journal deduplication
|
|
@@ -132,6 +140,10 @@ Every invocation with no explicit subcommand WRITES. Reconciliation is the
|
|
|
132
140
|
capture; hooks and watch only decide when to run it.`;
|
|
133
141
|
|
|
134
142
|
class UsageError extends Error {}
|
|
143
|
+
const hookRequested = process.argv.slice(2).some(arg => arg === "--hook" || arg.startsWith("--hook="));
|
|
144
|
+
function hookLaunchError(error) {
|
|
145
|
+
console.error(`capture hook launch failed: ${String(error.message).replace(/[\r\n]+/g, " ")}`);
|
|
146
|
+
}
|
|
135
147
|
|
|
136
148
|
function parseArgs(argv) {
|
|
137
149
|
const args = {};
|
|
@@ -144,7 +156,7 @@ function parseArgs(argv) {
|
|
|
144
156
|
const name = a.slice(2);
|
|
145
157
|
if (VALUE_FLAGS.has(name)) {
|
|
146
158
|
const value = argv[++i];
|
|
147
|
-
if (value === undefined) throw new UsageError(`${a} needs a value`);
|
|
159
|
+
if (value === undefined || hookRequested && value.startsWith("--")) throw new UsageError(`${a} needs a value`);
|
|
148
160
|
if (name === "file" && args.file !== undefined) throw new UsageError("one --file per call");
|
|
149
161
|
args[name] = value;
|
|
150
162
|
} else if (BOOL_FLAGS.has(name)) {
|
|
@@ -156,6 +168,12 @@ function parseArgs(argv) {
|
|
|
156
168
|
return args;
|
|
157
169
|
}
|
|
158
170
|
|
|
171
|
+
// Terminal branches return instead of forcing termination while stdout/stderr
|
|
172
|
+
// may still contain queued pipe writes. Returning also prevents reporting from
|
|
173
|
+
// falling through to capture. Lock/child owners finish before returning; watch
|
|
174
|
+
// retains its signal lifecycle. No stream is closed or given an arbitrary delay.
|
|
175
|
+
const finish = code => { process.exitCode = code; };
|
|
176
|
+
async function main() {
|
|
159
177
|
let args;
|
|
160
178
|
try {
|
|
161
179
|
args = parseArgs(process.argv.slice(2));
|
|
@@ -163,60 +181,93 @@ try {
|
|
|
163
181
|
if (recovery.length > 1) throw new UsageError("choose one recovery or health operation");
|
|
164
182
|
if (args.source !== undefined && (!args["reset-cursors"] || !CAPTURE_SOURCES.includes(args.source))) throw new UsageError("--source requires --reset-cursors and aw|cc|pi|codex");
|
|
165
183
|
if (recovery.length && ["home", "file", "format", "watch", "status", "install-hint", "current-roots", "sessions-only", "aw-only"].some(key => args[key])) throw new UsageError("recovery/health cannot be combined with another capture mode");
|
|
184
|
+
if (args.hook && ["home", "file", "format", "watch", "status", "install-hint", "help", "current-roots", "json", ...recovery].some(key => args[key] !== undefined))
|
|
185
|
+
throw new UsageError("--hook cannot be combined with proof, recovery, JSON or another capture mode");
|
|
166
186
|
} catch (err) {
|
|
167
187
|
if (!(err instanceof UsageError)) throw err;
|
|
188
|
+
// Claude treats hook exit2 as blocking/model feedback. Explicit hook usage
|
|
189
|
+
// failures report launch failure on stderr/exit1, never that special status.
|
|
190
|
+
if (hookRequested) {
|
|
191
|
+
hookLaunchError(err);
|
|
192
|
+
return finish(1);
|
|
193
|
+
}
|
|
168
194
|
// --file --json answers JSON even for a usage error: it is for programs.
|
|
169
195
|
if (process.argv.includes("--json")) {
|
|
170
196
|
console.log(JSON.stringify({ status: "failed", complete: false, code: "E_USAGE", error: err.message }, null, 2));
|
|
171
|
-
|
|
197
|
+
return finish(2);
|
|
172
198
|
}
|
|
173
199
|
console.error(`capture: ${err.message}\n\n${USAGE}`);
|
|
174
|
-
|
|
200
|
+
return finish(2);
|
|
175
201
|
}
|
|
176
202
|
|
|
177
203
|
if (args.help) {
|
|
178
204
|
console.log(USAGE);
|
|
179
|
-
|
|
205
|
+
return finish(0);
|
|
180
206
|
}
|
|
181
207
|
|
|
182
208
|
const root = args.root ?? process.env.TURN_RECORD_ROOT ?? join(homedir(), ".turn-record");
|
|
183
209
|
const ownerExplicit = args.owner !== undefined || process.env.TURN_RECORD_OWNER !== undefined;
|
|
184
210
|
const owner = args.owner ?? process.env.TURN_RECORD_OWNER ?? hostname().split(".")[0];
|
|
185
211
|
const quiet = Boolean(args.quiet || args.json && (args["reset-cursors"] || args["retry-set-aside"]));
|
|
186
|
-
const store = new RecordStore(root, { owner });
|
|
212
|
+
const store = args.hook || args.health ? null : new RecordStore(root, { owner });
|
|
187
213
|
|
|
188
214
|
if (args.health) {
|
|
189
215
|
try {
|
|
190
|
-
|
|
216
|
+
// Remedies name the command the person has: `oats` when the kernel runs
|
|
217
|
+
// this script (it imports it, so argv[1] is the kernel's entry, an npm bin
|
|
218
|
+
// symlink named oats included) or handed a node, as setup's remedies do;
|
|
219
|
+
// `turn-record` when run alone.
|
|
220
|
+
const entry = (() => {
|
|
221
|
+
try { return realpathSync(process.argv[1] ?? ""); }
|
|
222
|
+
catch (error) { if (error.code === "ENOENT") return process.argv[1] ?? ""; throw error; }
|
|
223
|
+
})();
|
|
224
|
+
const viaKernel = basename(entry) === "oats.mjs" || isAbsolute(process.env.OATS_NODE_BIN ?? "");
|
|
225
|
+
const health = viaKernel ? captureHealthForDoctor(root) : captureHealth(root);
|
|
191
226
|
if (args.json) console.log(JSON.stringify(health, null, 2));
|
|
192
227
|
else {
|
|
193
228
|
console.log(`capture: ${health.status}`);
|
|
194
229
|
for (const row of health.rows) console.log(`${row.code}: ${row.message}`);
|
|
195
230
|
for (const entry of health.backlog.setAside) console.log(`${entry.source}: ${entry.path}:${entry.line ?? "?"} offset ${entry.offset}: ${entry.reason}`);
|
|
196
231
|
if (health.backlog.truncated) console.log("showing first 100 set-aside inputs");
|
|
232
|
+
for (const entry of health.backlog.failed) console.log(`${entry.stream}: unit starting at byte ${entry.offset} (failing frame unknown): ${entry.reason}; attempts ${entry.attempts}; next retry ${entry.nextRetryAt}`);
|
|
233
|
+
if (health.backlog.failedTruncated) console.log("showing first 100 failed stream units");
|
|
197
234
|
}
|
|
198
235
|
} catch (err) {
|
|
199
236
|
if (args.json) console.log(JSON.stringify({ status: "failed", error: err.message }));
|
|
200
237
|
else console.error(`capture: ${err.message}`);
|
|
201
238
|
process.exitCode = 1;
|
|
202
239
|
}
|
|
203
|
-
|
|
240
|
+
return;
|
|
204
241
|
}
|
|
205
242
|
if (args["reset-cursors"] || args["retry-set-aside"]) {
|
|
206
243
|
try {
|
|
207
244
|
const result = args["reset-cursors"]
|
|
208
245
|
? withCaptureLock(() => { resetSourceCursors(root, owner, args.source); return { reset: true, sources: args.source ? [args.source] : CAPTURE_SOURCES }; })
|
|
209
|
-
: pass({ retry: true });
|
|
246
|
+
: await pass({ retry: true });
|
|
210
247
|
if (result.skipped) throw new Error("capture lock held; recovery was not performed");
|
|
211
248
|
if (process.exitCode) throw new Error("recovery failed to release its capture lock");
|
|
212
249
|
if (args.json) console.log(JSON.stringify(result));
|
|
213
250
|
else if (args["reset-cursors"]) log(`capture: reset source cursors (${result.sources.join(", ")})`);
|
|
214
251
|
} catch (err) {
|
|
252
|
+
if (err instanceof PrintedCaptureFailure) throw err;
|
|
215
253
|
if (args.json) console.log(JSON.stringify({ status: "failed", complete: false, error: err.message }));
|
|
216
254
|
else console.error(`capture: ${err.message}`);
|
|
217
255
|
process.exitCode = 1;
|
|
218
256
|
}
|
|
219
|
-
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (args.hook) {
|
|
261
|
+
try {
|
|
262
|
+
await launchCaptureHook(root, { owner, plan: commandPlan(), indexEnabled: !args["no-index"], trigger: "hook", retrySetAside: false });
|
|
263
|
+
log("capture launched; launch is not completion (see capture --health)");
|
|
264
|
+
} catch (error) {
|
|
265
|
+
hookLaunchError(error);
|
|
266
|
+
process.exitCode = 1;
|
|
267
|
+
}
|
|
268
|
+
// No capture work or discovery in the harness process. The detached owner
|
|
269
|
+
// takes the lock and retains the existing worker lifetime/reaping contract.
|
|
270
|
+
return;
|
|
220
271
|
}
|
|
221
272
|
|
|
222
273
|
// The owner decides the stream namespace, and turn ids hash it into the
|
|
@@ -265,18 +316,9 @@ function withCaptureLock(fn) {
|
|
|
265
316
|
lock = acquireCaptureLock(root);
|
|
266
317
|
// Said by the pass that removed it, never quiet, whether or not it then took the lock: a pass that
|
|
267
318
|
// died holding the lock is worth knowing about.
|
|
268
|
-
if (lock.reclaimed)
|
|
319
|
+
if (lock.reclaimed) reportReclaimedLock({ path: lock.path, ...lock.reclaimed });
|
|
269
320
|
} catch (err) {
|
|
270
|
-
|
|
271
|
-
const c = err.lockCleanup;
|
|
272
|
-
const outcome = c.removed ? "the initializing lock was removed"
|
|
273
|
-
: c.reason === "gone" ? "the initializing lock was already gone (removed by another party)"
|
|
274
|
-
: c.reason === "replaced" ? (c.owner
|
|
275
|
-
? `the lock now belongs to pid ${c.owner.pid} (started ${c.owner.startedAt || "?"}) and was left alone`
|
|
276
|
-
: "the lock directory changed or its identity could not be verified, no owner record was readable, and it was left alone")
|
|
277
|
-
: `the initializing lock could NOT be removed${c.error ? ` (${c.error})` : ""}; ${c.recovery}`;
|
|
278
|
-
console.error(`capture: could not write the owner record of ${c.path}: ${err.message}; ${outcome}`);
|
|
279
|
-
}
|
|
321
|
+
reportLockInitializationFailure(err);
|
|
280
322
|
throw err;
|
|
281
323
|
}
|
|
282
324
|
if (lock.held) {
|
|
@@ -303,72 +345,27 @@ function withCaptureLock(fn) {
|
|
|
303
345
|
if (!r.released) {
|
|
304
346
|
// Say what was observed: gone, unreadable (unknown), another owner, or
|
|
305
347
|
// our own lock that would not go away; never a guess about liveness.
|
|
306
|
-
|
|
307
|
-
: r.reason === "not-owner" ? `it now belongs to pid ${r.owner.pid} (started ${r.owner.startedAt || "?"}); left alone`
|
|
308
|
-
: r.reason === "unknown-owner" ? `its owner record is missing or unreadable, so it may be an operator removal in progress or a newer pass initializing; left alone; ${r.recovery}`
|
|
309
|
-
: `${r.error ? `${r.error}; ` : ""}${r.recovery}`;
|
|
310
|
-
console.error(`capture: did not release ${lock.path} (${r.reason}): ${detail}`);
|
|
348
|
+
console.error(`capture: did not release ${lock.path} (${r.reason}): ${releaseDetail(r)}`);
|
|
311
349
|
process.exitCode = 1;
|
|
312
350
|
}
|
|
313
351
|
}
|
|
314
352
|
}
|
|
315
353
|
|
|
316
|
-
function
|
|
317
|
-
//
|
|
318
|
-
//
|
|
319
|
-
const
|
|
320
|
-
return
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
`sessions: ${r.sessions} scanned, ${r.appended} new turns in ${r.streams} sessions${extras ? ` (${extras})` : ""} -> ${r.stream}`,
|
|
332
|
-
);
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
if (!args["sessions-only"]) {
|
|
336
|
-
let awEntries = 0;
|
|
337
|
-
let awAppended = 0;
|
|
338
|
-
let awFailed = 0;
|
|
339
|
-
let awFiles = 0;
|
|
340
|
-
let awIgnored = 0;
|
|
341
|
-
for (const r of captureAwLogs(store, { owner, ignore, collect: false })) {
|
|
342
|
-
if (r.ignored) {
|
|
343
|
-
awIgnored++;
|
|
344
|
-
continue;
|
|
345
|
-
}
|
|
346
|
-
awFiles++;
|
|
347
|
-
awEntries += r.entries;
|
|
348
|
-
awAppended += r.appended;
|
|
349
|
-
awFailed += r.failed;
|
|
350
|
-
out.pending ||= r.failed > 0;
|
|
351
|
-
out.appended += r.appended;
|
|
352
|
-
if (r.failed) console.error(`aw-log ${r.account}: ${r.failed} entries failed to project`);
|
|
353
|
-
}
|
|
354
|
-
const ignored = awIgnored ? `, ${awIgnored} ignored` : "";
|
|
355
|
-
log(`aw-logs: ${awFiles} files, ${awEntries} entries, ${awAppended} new, ${awFailed} failed${ignored}`);
|
|
356
|
-
}
|
|
357
|
-
// Index whenever this pass may index, not only when THIS pass appended:
|
|
358
|
-
// an append-only pass (--no-index, the hook form) leaves turns behind
|
|
359
|
-
// that the next indexing pass must pick up. index.update() walks
|
|
360
|
-
// per-stream cursors, so a pass with nothing new is cheap.
|
|
361
|
-
if (!args["no-index"]) {
|
|
362
|
-
const index = new RecordIndex(store);
|
|
363
|
-
try {
|
|
364
|
-
index.update();
|
|
365
|
-
log("index: updated");
|
|
366
|
-
} finally {
|
|
367
|
-
index.close();
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
return out;
|
|
371
|
-
});
|
|
354
|
+
function commandPlan() {
|
|
355
|
+
// Copy caller selection before spawning; only the admitted worker resolves
|
|
356
|
+
// the capture roots. Both selection flags retain their existing empty union.
|
|
357
|
+
const sources = CAPTURE_SOURCES.filter(source => source === "aw" ? !args["sessions-only"] : !args["aw-only"]);
|
|
358
|
+
return captureDefaultRootPlan({ home: homedir(), cwd: process.cwd(), env: process.env, sources });
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
async function pass({ retry = false, trigger = "manual" } = {}) {
|
|
362
|
+
// Privacy refusal unwinds to the command boundary before the lock is
|
|
363
|
+
// taken, leaving no admitted child or lock. The worker independently
|
|
364
|
+
// reloads privacy rules; this preflight supplies the existing actionable error.
|
|
365
|
+
loadIgnoreForCommand(root);
|
|
366
|
+
// Recovery JSON keeps its existing small shape. Never read a later status
|
|
367
|
+
// file after releasing the lock to reconstruct this pass's counters.
|
|
368
|
+
return captureCommandPass(root, { owner, plan: commandPlan(), indexEnabled: !args["no-index"], trigger, retrySetAside: retry }, { log });
|
|
372
369
|
}
|
|
373
370
|
|
|
374
371
|
/** A final capture of exact files, one batch per format, under the lock: counts into `outcome`, issues into
|
|
@@ -527,36 +524,40 @@ function fileCapture() {
|
|
|
527
524
|
} finally { pinned.close(); }
|
|
528
525
|
}
|
|
529
526
|
|
|
530
|
-
if (args.file !== undefined || args.format !== undefined || args.json)
|
|
527
|
+
if (args.file !== undefined || args.format !== undefined || args.json) return finish(fileCapture());
|
|
531
528
|
|
|
532
529
|
if (args["install-hint"]) {
|
|
533
|
-
const self = new URL(import.meta.url).pathname;
|
|
530
|
+
const self = new URL("./capture-hook.mjs", import.meta.url).pathname;
|
|
534
531
|
console.log(`Add to Claude Code settings.json to capture on session stop/end:
|
|
535
532
|
|
|
536
533
|
{
|
|
537
534
|
"hooks": {
|
|
538
|
-
"Stop": [{"hooks": [{"type": "command", "command": "node ${self} --sessions-only --no-index --quiet"}]}],
|
|
539
|
-
"SessionEnd": [{"hooks": [{"type": "command", "command": "node ${self} --sessions-only --no-index --quiet"}]}]
|
|
535
|
+
"Stop": [{"hooks": [{"type": "command", "command": "node ${self} --sessions-only --no-index --quiet", "async": false, "timeout": 10}]}],
|
|
536
|
+
"SessionEnd": [{"hooks": [{"type": "command", "command": "node ${self} --sessions-only --no-index --quiet", "async": false, "timeout": 10}]}]
|
|
540
537
|
}
|
|
541
538
|
}
|
|
542
539
|
|
|
543
|
-
Hook
|
|
540
|
+
Hook acknowledgement means capture launched, not capture completed. The
|
|
541
|
+
harness waits only for the launcher (async:false, timeout:10); its detached
|
|
542
|
+
supervisor inherits no harness output pipes. Hook failures exit 1, never 2.
|
|
543
|
+
These hook passes append turns only (--no-index); the search index is updated by
|
|
544
544
|
capture --watch (every 15 minutes and on change) or by a plain capture pass.
|
|
545
|
-
One pass runs per record root at a time:
|
|
546
|
-
|
|
547
|
-
|
|
545
|
+
One pass runs per record root at a time: the detached supervisor skips an
|
|
546
|
+
overlap; launch acknowledgement does not report that later decision. A dropped
|
|
547
|
+
hook is recovered by any later pass.`);
|
|
548
|
+
return finish(0);
|
|
548
549
|
}
|
|
549
550
|
|
|
550
551
|
if (args.status) {
|
|
551
552
|
console.log(`root: ${root}\nowner: ${owner}`);
|
|
552
|
-
const ignore =
|
|
553
|
+
const ignore = loadIgnoreForCommand(root);
|
|
553
554
|
if (ignore.size > 0) {
|
|
554
555
|
console.log(`ignore: ${ignore.size} pattern${ignore.size === 1 ? "" : "s"} (${ignoreFilePath(root)})`);
|
|
555
556
|
}
|
|
556
557
|
for (const streamId of store.listStreams()) {
|
|
557
558
|
console.log(` ${streamId}: ${store.readStream(streamId).length} turns`);
|
|
558
559
|
}
|
|
559
|
-
|
|
560
|
+
return finish(0);
|
|
560
561
|
}
|
|
561
562
|
|
|
562
563
|
// One instance home: capture its own sessions and report them with exact
|
|
@@ -629,39 +630,57 @@ if (args.home) {
|
|
|
629
630
|
|
|
630
631
|
warnOnStrangerOwner();
|
|
631
632
|
try {
|
|
632
|
-
pass();
|
|
633
|
+
await pass({ trigger: args.watch ? "watch" : "manual" });
|
|
633
634
|
} catch (err) {
|
|
635
|
+
if (err instanceof PrintedCaptureFailure) throw err;
|
|
634
636
|
// The lock's finally has run by now; one line, then the status.
|
|
635
637
|
console.error(`capture pass failed: ${err.message}`);
|
|
636
|
-
|
|
638
|
+
return finish(1);
|
|
637
639
|
}
|
|
638
640
|
|
|
639
641
|
if (args.watch) {
|
|
640
|
-
const
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
}
|
|
654
|
-
}, 2000);
|
|
655
|
-
};
|
|
656
|
-
for (const dir of roots) {
|
|
642
|
+
const queue = captureWatchQueue(() => pass({ trigger: "watch" }), {
|
|
643
|
+
onError: err => {
|
|
644
|
+
process.exitCode = 1;
|
|
645
|
+
// A privacy refusal used to terminate immediately. It still stops the
|
|
646
|
+
// watch, before child admission, but lets its already printed error drain.
|
|
647
|
+
if (err instanceof PrintedCaptureFailure) { stop(); return; }
|
|
648
|
+
console.error(`capture pass failed: ${err.message}`);
|
|
649
|
+
},
|
|
650
|
+
});
|
|
651
|
+
const watchers = [], plan = commandPlan();
|
|
652
|
+
// These are notification hints only. Their enumeration has parent metadata
|
|
653
|
+
// cost, supplies no capture authority, and may fail independently of a pass.
|
|
654
|
+
for (const source of plan.sources) {
|
|
657
655
|
try {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
656
|
+
for (const dir of resolveCaptureDefaultRoots(plan, source)) {
|
|
657
|
+
try {
|
|
658
|
+
const watcher = watch(dir, { recursive: true }, () => queue.schedule());
|
|
659
|
+
watcher.on("error", err => { console.error(`cannot watch ${dir}: ${err.message}`); watcher.close(); });
|
|
660
|
+
watchers.push(watcher);
|
|
661
|
+
log(`watching ${dir}`);
|
|
662
|
+
} catch (err) { console.error(`cannot watch ${dir}: ${err.message}`); }
|
|
663
|
+
}
|
|
664
|
+
} catch (err) { console.error(`cannot select ${source} watch hints: ${err.message}`); }
|
|
663
665
|
}
|
|
664
|
-
setInterval(schedule, 15 * 60 * 1000);
|
|
666
|
+
const interval = setInterval(() => queue.schedule(), 15 * 60 * 1000);
|
|
667
|
+
const stop = () => {
|
|
668
|
+
queue.close(); clearInterval(interval);
|
|
669
|
+
for (const watcher of watchers) watcher.close();
|
|
670
|
+
process.off("SIGINT", stop); process.off("SIGTERM", stop);
|
|
671
|
+
// If a pass is active its supervisor also observes this signal and owns
|
|
672
|
+
// child termination/reaping and lock release. No new pass may start.
|
|
673
|
+
};
|
|
674
|
+
process.on("SIGINT", stop); process.on("SIGTERM", stop);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
}
|
|
665
678
|
}
|
|
666
679
|
|
|
680
|
+
try { await main(); }
|
|
681
|
+
catch (error) {
|
|
682
|
+
if (!(error instanceof PrintedCaptureFailure)) throw error;
|
|
683
|
+
// Privacy already printed its one actionable error. No duplicate diagnostic
|
|
684
|
+
// and no later mode may run, but both output pipes can finish normally.
|
|
685
|
+
process.exitCode = 1;
|
|
667
686
|
}
|
|
@@ -3,14 +3,19 @@
|
|
|
3
3
|
//
|
|
4
4
|
// recall <query...> FTS5 query over mail, chat, sessions
|
|
5
5
|
// recall --kind mail <query...> filter by kind (mail|chat|session|note)
|
|
6
|
-
// recall --thread <thread> [query] filter/list by thread
|
|
7
|
-
//
|
|
6
|
+
// recall --thread <thread> [query] filter/list by thread; text listings
|
|
7
|
+
// without a query are timestamp-sorted
|
|
8
|
+
// recall --thread <thread> --json the thread's turns in capture sequence,
|
|
8
9
|
// [--after <id>] [--until <id>] with extracted text; exact id bounds
|
|
9
10
|
// [--limit n] [--ids-only] (after is exclusive, until inclusive);
|
|
10
11
|
// --ids-only lists id, ts and the bytes
|
|
11
12
|
// each turn occupies in the --json output
|
|
12
13
|
// (text extracted but not emitted), so a
|
|
13
|
-
// consumer can size a window it will read
|
|
14
|
+
// consumer can size a window it will read.
|
|
15
|
+
// For a thread spanning aw accounts the
|
|
16
|
+
// cross-account sequence is unspecified
|
|
17
|
+
// and an id window may hold turns from
|
|
18
|
+
// more than one account
|
|
14
19
|
// recall --from <name> <query...> filter by speaker
|
|
15
20
|
// recall --limit N max results (default 20)
|
|
16
21
|
// recall --show <turn-id> print one turn as JSON
|