recallnest 3.0.0 → 4.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/CHANGELOG.md +304 -0
- package/README.md +251 -258
- package/README_CN.md +226 -247
- package/assets/ui/app.js +6 -1
- package/bin/recallnest.mjs +20 -37
- package/docs/api-reference.md +8 -0
- package/docs/architecture.md +18 -13
- package/eval/cases-canary.json +107 -9
- package/integrations/examples/claude-agent-sdk/memory-agent.ts +2 -0
- package/integrations/examples/langchain/memory-chain.py +4 -0
- package/integrations/examples/openai-agents-sdk/memory-agent.py +4 -0
- package/package.json +12 -3
- package/src/activity-counter.ts +1 -0
- package/src/adaptive-retrieval.ts +23 -0
- package/src/api-server.ts +13 -11
- package/src/asset-sync.ts +26 -2
- package/src/audit-log.ts +2 -0
- package/src/auto-gc.ts +4 -3
- package/src/belief-history.ts +137 -31
- package/src/capture-engine.ts +459 -71
- package/src/cascade-forget.ts +7 -3
- package/src/checkpoint-mirror.ts +417 -0
- package/src/cli.ts +574 -54
- package/src/conflict-engine.ts +43 -15
- package/src/consolidation-engine.ts +24 -3
- package/src/context-collapse-renderer.ts +8 -1
- package/src/context-composer-stable.ts +5 -1
- package/src/context-composer.ts +11 -2
- package/src/distill-lock.ts +246 -74
- package/src/dream-pipeline.ts +3 -1
- package/src/embedder.ts +24 -0
- package/src/env-config.ts +136 -0
- package/src/flock.ts +97 -0
- package/src/forget-engine.ts +342 -58
- package/src/gateway-server.ts +4 -0
- package/src/ingest-plan.ts +56 -0
- package/src/ingest.ts +294 -121
- package/src/kg-contradiction.ts +753 -0
- package/src/kg-extractor.ts +17 -0
- package/src/kg-store.ts +1 -1
- package/src/known-item-eval.ts +455 -0
- package/src/llm-client.ts +13 -26
- package/src/llm-consolidation.ts +2 -2
- package/src/mcp-tool-deps.ts +6 -0
- package/src/mcp-tools-advanced.ts +80 -45
- package/src/mcp-tools-core.ts +23 -17
- package/src/mcp-tools-governance.ts +13 -7
- package/src/memory-assets.ts +144 -8
- package/src/memory-boundaries.ts +19 -0
- package/src/memory-evolution.ts +9 -0
- package/src/memory-lint.ts +1 -1
- package/src/memory-output.ts +311 -14
- package/src/memory-reconcile.ts +1437 -0
- package/src/memory-schema.ts +11 -0
- package/src/memory-store-port.ts +1 -0
- package/src/minis-archive.ts +151 -0
- package/src/noise-filter.ts +15 -2
- package/src/pii-detector.ts +31 -1
- package/src/pivot-apply.ts +55 -5
- package/src/pivot-evidence.ts +128 -0
- package/src/ppr-traversal.ts +25 -1
- package/src/preference-matcher.ts +40 -28
- package/src/prospective-memory.ts +7 -4
- package/src/retriever.ts +297 -57
- package/src/retroactive-boost.ts +3 -2
- package/src/runtime-config.ts +15 -1
- package/src/scope-policy.ts +1 -0
- package/src/session-distiller.ts +6 -2
- package/src/session-engine.ts +11 -4
- package/src/session-output.ts +20 -1
- package/src/session-schema.ts +5 -2
- package/src/session-store.ts +59 -12
- package/src/skill-promotion.ts +67 -1
- package/src/store-receipts.ts +109 -0
- package/src/store-write-budget.ts +37 -0
- package/src/store.ts +298 -57
- package/src/text-fingerprint.ts +25 -0
- package/src/trigger-store.ts +443 -0
- package/src/ui-server.ts +22 -21
- package/src/version-manager.ts +19 -5
- package/src/write-verifier.ts +16 -11
- package/src/__tests__/access-tracker-novelty.test.ts +0 -324
- package/src/__tests__/activity-counter.test.ts +0 -125
- package/src/__tests__/adaptive-fidelity.test.ts +0 -102
- package/src/__tests__/admission-control.test.ts +0 -206
- package/src/__tests__/age-label.test.ts +0 -33
- package/src/__tests__/anchor-generator.test.ts +0 -67
- package/src/__tests__/api-server-security.test.ts +0 -102
- package/src/__tests__/auto-consolidation.test.ts +0 -168
- package/src/__tests__/auto-recall.test.ts +0 -131
- package/src/__tests__/babel-integration.test.ts +0 -144
- package/src/__tests__/batch-dedup.test.ts +0 -65
- package/src/__tests__/belief-history.test.ts +0 -220
- package/src/__tests__/canary-eval.test.ts +0 -114
- package/src/__tests__/capture-engine.test.ts +0 -1328
- package/src/__tests__/capture-heuristic.test.ts +0 -171
- package/src/__tests__/cascade-forget.test.ts +0 -210
- package/src/__tests__/category-min-scores.test.ts +0 -116
- package/src/__tests__/cc8-cc1-essential-context.test.ts +0 -298
- package/src/__tests__/circuit-breaker.test.ts +0 -99
- package/src/__tests__/cluster-consolidation.test.ts +0 -1236
- package/src/__tests__/confidence-metadata.test.ts +0 -125
- package/src/__tests__/confidence-tracker.test.ts +0 -261
- package/src/__tests__/conflict-advisor.test.ts +0 -206
- package/src/__tests__/conflict-escalation.test.ts +0 -149
- package/src/__tests__/conflict-lifecycle.test.ts +0 -83
- package/src/__tests__/conflict-output.test.ts +0 -85
- package/src/__tests__/conflict-store.test.ts +0 -418
- package/src/__tests__/connector-v1.test.ts +0 -181
- package/src/__tests__/consolidation-engine.test.ts +0 -520
- package/src/__tests__/constructive-retrieval.test.ts +0 -509
- package/src/__tests__/context-collapse-renderer.test.ts +0 -214
- package/src/__tests__/context-composer-pins.test.ts +0 -64
- package/src/__tests__/context-composer-task-selection.test.ts +0 -24
- package/src/__tests__/context-reconstructor.test.ts +0 -65
- package/src/__tests__/context-renderer.test.ts +0 -91
- package/src/__tests__/continuity-eval.test.ts +0 -275
- package/src/__tests__/continuity-schema.test.ts +0 -97
- package/src/__tests__/contracts.test.ts +0 -262
- package/src/__tests__/conversation-importer.test.ts +0 -692
- package/src/__tests__/core-recall-eval.test.ts +0 -235
- package/src/__tests__/core-summary.test.ts +0 -109
- package/src/__tests__/data-checkup.test.ts +0 -304
- package/src/__tests__/decay-exemption.test.ts +0 -129
- package/src/__tests__/dedup-actions.test.ts +0 -58
- package/src/__tests__/dedup-guard.test.ts +0 -39
- package/src/__tests__/deterministic-id.test.ts +0 -39
- package/src/__tests__/distill-lock.test.ts +0 -305
- package/src/__tests__/distill-session-argshape.test.ts +0 -79
- package/src/__tests__/doctor.test.ts +0 -319
- package/src/__tests__/dream-pipeline.test.ts +0 -820
- package/src/__tests__/dream-scope-isolation.test.ts +0 -386
- package/src/__tests__/dream-write-batching.test.ts +0 -211
- package/src/__tests__/drill-down.test.ts +0 -108
- package/src/__tests__/embedder.test.ts +0 -122
- package/src/__tests__/emotion-decay.test.ts +0 -46
- package/src/__tests__/emotion-detector.test.ts +0 -56
- package/src/__tests__/emotion-phase1-integration.test.ts +0 -153
- package/src/__tests__/emotion-retrieval.test.ts +0 -56
- package/src/__tests__/entity-resolver.test.ts +0 -58
- package/src/__tests__/env-config-invariant.test.ts +0 -80
- package/src/__tests__/env-config.test.ts +0 -211
- package/src/__tests__/error-signature-boost.test.ts +0 -87
- package/src/__tests__/error-signature.test.ts +0 -95
- package/src/__tests__/error-taxonomy.test.ts +0 -129
- package/src/__tests__/ethics-layer.test.ts +0 -476
- package/src/__tests__/event-segmenter.test.ts +0 -153
- package/src/__tests__/feature-flags-integration.test.ts +0 -54
- package/src/__tests__/frequency-tracker.test.ts +0 -113
- package/src/__tests__/freshness.test.ts +0 -186
- package/src/__tests__/graph-export.test.ts +0 -489
- package/src/__tests__/hotness-blend.test.ts +0 -283
- package/src/__tests__/ingest-chunking.test.ts +0 -44
- package/src/__tests__/ingest-scope-prefix.test.ts +0 -69
- package/src/__tests__/ingest.test.ts +0 -360
- package/src/__tests__/interference-detector.test.ts +0 -203
- package/src/__tests__/kg-extractor.test.ts +0 -192
- package/src/__tests__/kg-store.test.ts +0 -300
- package/src/__tests__/llm-client-pivot.test.ts +0 -628
- package/src/__tests__/llm-consolidation.test.ts +0 -226
- package/src/__tests__/maintenance-locks.test.ts +0 -197
- package/src/__tests__/mcp-efficiency.test.ts +0 -288
- package/src/__tests__/mcp-related-scopes.test.ts +0 -151
- package/src/__tests__/memory-boundaries.test.ts +0 -282
- package/src/__tests__/memory-evolution-b2-b3-e1.test.ts +0 -362
- package/src/__tests__/memory-evolution.test.ts +0 -271
- package/src/__tests__/memory-health-rebalance.test.ts +0 -144
- package/src/__tests__/memory-lint.test.ts +0 -421
- package/src/__tests__/memory-output.test.ts +0 -224
- package/src/__tests__/memory-promotion.test.ts +0 -315
- package/src/__tests__/memory-utility.test.ts +0 -256
- package/src/__tests__/migrate-dedup-ids.test.ts +0 -65
- package/src/__tests__/multi-vector.test.ts +0 -242
- package/src/__tests__/narrative-architecture.test.ts +0 -456
- package/src/__tests__/noise-filter.test.ts +0 -205
- package/src/__tests__/noise-prototype-bank.test.ts +0 -280
- package/src/__tests__/obsidian-connector.test.ts +0 -363
- package/src/__tests__/omitted-reporting.test.ts +0 -98
- package/src/__tests__/openai-contract.test.ts +0 -513
- package/src/__tests__/pending-review.test.ts +0 -77
- package/src/__tests__/pii-redact.test.ts +0 -333
- package/src/__tests__/pivot-apply.test.ts +0 -373
- package/src/__tests__/pivot-distill-supervisor.test.ts +0 -457
- package/src/__tests__/pivot-distill.test.ts +0 -1178
- package/src/__tests__/post-retrieval-filter.test.ts +0 -178
- package/src/__tests__/ppr-traversal.test.ts +0 -256
- package/src/__tests__/prediction-engine.test.ts +0 -349
- package/src/__tests__/predictive-prospective-memory.test.ts +0 -416
- package/src/__tests__/preference-guard-smoke.test.ts +0 -211
- package/src/__tests__/preference-matcher.test.ts +0 -282
- package/src/__tests__/preference-slots.test.ts +0 -205
- package/src/__tests__/promotion-distinct-sources.test.ts +0 -162
- package/src/__tests__/prospective-memory.test.ts +0 -283
- package/src/__tests__/pull-from-macbook-sync-only.test.ts +0 -679
- package/src/__tests__/query-entity-detector.test.ts +0 -171
- package/src/__tests__/query-expander-alias.test.ts +0 -146
- package/src/__tests__/query-expander.test.ts +0 -34
- package/src/__tests__/recall-gate.test.ts +0 -266
- package/src/__tests__/recall-governor.test.ts +0 -227
- package/src/__tests__/recall-mode.test.ts +0 -64
- package/src/__tests__/resolve-db-path.test.ts +0 -130
- package/src/__tests__/resolve-tier.test.ts +0 -64
- package/src/__tests__/result-synthesizer.test.ts +0 -198
- package/src/__tests__/resume-context.test.ts +0 -4898
- package/src/__tests__/retrieval-eval.test.ts +0 -163
- package/src/__tests__/retrieval-trace.test.ts +0 -213
- package/src/__tests__/retrieve-audit-revision.test.ts +0 -255
- package/src/__tests__/retriever-boundary-weight.test.ts +0 -136
- package/src/__tests__/retriever-lazy-init-dispatch.test.ts +0 -123
- package/src/__tests__/retroactive-boost.test.ts +0 -223
- package/src/__tests__/salience-scoring.test.ts +0 -106
- package/src/__tests__/scope-inventory.test.ts +0 -200
- package/src/__tests__/scope-policy.test.ts +0 -69
- package/src/__tests__/scope-suggester.test.ts +0 -80
- package/src/__tests__/session-checkpoint.test.ts +0 -291
- package/src/__tests__/session-distiller.test.ts +0 -640
- package/src/__tests__/session-gc.test.ts +0 -215
- package/src/__tests__/skill-engine.test.ts +0 -552
- package/src/__tests__/skill-promotion.test.ts +0 -654
- package/src/__tests__/skill-verifier.test.ts +0 -122
- package/src/__tests__/source-heartbeat.test.ts +0 -254
- package/src/__tests__/stable-context-length-contract.test.ts +0 -62
- package/src/__tests__/store-patch-metadata.test.ts +0 -235
- package/src/__tests__/store-read-consistency.test.ts +0 -122
- package/src/__tests__/store-schema-migration.test.ts +0 -87
- package/src/__tests__/store-scope-audit.test.ts +0 -81
- package/src/__tests__/store-upsert.test.ts +0 -201
- package/src/__tests__/supersede-chain.test.ts +0 -154
- package/src/__tests__/synthesis-contract.test.ts +0 -252
- package/src/__tests__/synthesis-promotion.test.ts +0 -369
- package/src/__tests__/temporal-parser.test.ts +0 -241
- package/src/__tests__/temporal-validity.test.ts +0 -160
- package/src/__tests__/term-registry-terminal-roster.test.ts +0 -127
- package/src/__tests__/term-registry.test.ts +0 -121
- package/src/__tests__/tool-error-surfacing.test.ts +0 -98
- package/src/__tests__/tool-output-compressor.test.ts +0 -160
- package/src/__tests__/topic-tag.test.ts +0 -113
- package/src/__tests__/trusted-memory.test.ts +0 -867
- package/src/__tests__/ui-server-security.test.ts +0 -93
- package/src/__tests__/usage-tracker.test.ts +0 -287
- package/src/__tests__/utility-weight.test.ts +0 -57
- package/src/__tests__/verbatim-self-recall.test.ts +0 -279
- package/src/__tests__/version-manager.test.ts +0 -248
- package/src/__tests__/workflow-observation-skill-outcome.test.ts +0 -352
- package/src/__tests__/workflow-observation.test.ts +0 -433
- package/src/__tests__/write-verifier.test.ts +0 -122
|
@@ -1,457 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import {
|
|
3
|
-
chmodSync,
|
|
4
|
-
existsSync,
|
|
5
|
-
mkdtempSync,
|
|
6
|
-
readFileSync,
|
|
7
|
-
statSync,
|
|
8
|
-
writeFileSync,
|
|
9
|
-
} from "node:fs";
|
|
10
|
-
import { tmpdir } from "node:os";
|
|
11
|
-
import { join, resolve } from "node:path";
|
|
12
|
-
import { spawn, spawnSync } from "node:child_process";
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
SUPERVISED_TASKS,
|
|
16
|
-
tasksForMode,
|
|
17
|
-
type SupervisorMode,
|
|
18
|
-
} from "../../scripts/pivot-distill-supervisor.js";
|
|
19
|
-
|
|
20
|
-
const BUN = Bun.which("bun")!;
|
|
21
|
-
const REPO_ROOT = resolve(import.meta.dir, "../..");
|
|
22
|
-
const SUPERVISOR = join(REPO_ROOT, "scripts", "pivot-distill-supervisor.ts");
|
|
23
|
-
const LOADED_LABELS = [
|
|
24
|
-
"com.recallnest.incremental-ingest",
|
|
25
|
-
"com.recallnest.pull-from-macbook",
|
|
26
|
-
] as const;
|
|
27
|
-
const PRIOR_ABSENT_LABEL = "com.anxianjingya.agy-conversations-sync";
|
|
28
|
-
|
|
29
|
-
interface FakeHarness {
|
|
30
|
-
root: string;
|
|
31
|
-
stateDir: string;
|
|
32
|
-
launchState: string;
|
|
33
|
-
launchLog: string;
|
|
34
|
-
probeLog: string;
|
|
35
|
-
childMarker: string;
|
|
36
|
-
launchctl: string;
|
|
37
|
-
pgrep: string;
|
|
38
|
-
childScript: string;
|
|
39
|
-
env: NodeJS.ProcessEnv;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function executable(path: string, source: string): void {
|
|
43
|
-
writeFileSync(path, source, { mode: 0o700 });
|
|
44
|
-
chmodSync(path, 0o700);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function fakeHarness(loaded: readonly string[] = LOADED_LABELS): FakeHarness {
|
|
48
|
-
const root = mkdtempSync(join(tmpdir(), "pivot-supervisor-"));
|
|
49
|
-
const stateDir = join(root, "controller");
|
|
50
|
-
const launchState = join(root, "launch-state.json");
|
|
51
|
-
const launchLog = join(root, "launchctl.log");
|
|
52
|
-
const probeLog = join(root, "pgrep.log");
|
|
53
|
-
const childMarker = join(root, "child-started");
|
|
54
|
-
const launchctl = join(root, "fake-launchctl.ts");
|
|
55
|
-
const pgrep = join(root, "fake-pgrep.ts");
|
|
56
|
-
const childScript = join(root, "fake-child.ts");
|
|
57
|
-
writeFileSync(launchState, JSON.stringify([...loaded]));
|
|
58
|
-
|
|
59
|
-
executable(launchctl, `#!/usr/bin/env bun
|
|
60
|
-
import { appendFileSync, readFileSync, writeFileSync } from "node:fs";
|
|
61
|
-
import { basename } from "node:path";
|
|
62
|
-
const statePath = process.env.FAKE_LAUNCH_STATE!;
|
|
63
|
-
const logPath = process.env.FAKE_LAUNCH_LOG!;
|
|
64
|
-
const [operation, ...args] = process.argv.slice(2);
|
|
65
|
-
let loaded = JSON.parse(readFileSync(statePath, "utf8")) as string[];
|
|
66
|
-
const targetLabel = (target: string | undefined): string => (target || "").split("/").at(-1) || "";
|
|
67
|
-
let label = operation === "bootstrap"
|
|
68
|
-
? basename(args[1] || "", ".plist")
|
|
69
|
-
: targetLabel(args[0]);
|
|
70
|
-
appendFileSync(logPath, operation + "\\t" + label + "\\n");
|
|
71
|
-
if (operation === "print") {
|
|
72
|
-
if (process.env.FAKE_PRINT_ERROR_LABEL === label) process.exit(64);
|
|
73
|
-
if (
|
|
74
|
-
process.env.FAKE_PRINT_ERROR_AFTER_BOOTSTRAP_LABEL === label &&
|
|
75
|
-
readFileSync(logPath, "utf8").includes("bootstrap\\t" + label + "\\n")
|
|
76
|
-
) process.exit(65);
|
|
77
|
-
if (loaded.includes(label)) process.exit(0);
|
|
78
|
-
console.error('Could not find service "' + label + '" in domain for user gui: 501');
|
|
79
|
-
process.exit(113);
|
|
80
|
-
}
|
|
81
|
-
if (operation === "bootout") {
|
|
82
|
-
if (!loaded.includes(label)) process.exit(3);
|
|
83
|
-
loaded = loaded.filter((entry) => entry !== label);
|
|
84
|
-
writeFileSync(statePath, JSON.stringify(loaded));
|
|
85
|
-
process.exit(0);
|
|
86
|
-
}
|
|
87
|
-
if (operation === "bootstrap") {
|
|
88
|
-
if (!loaded.includes(label)) loaded.push(label);
|
|
89
|
-
writeFileSync(statePath, JSON.stringify(loaded));
|
|
90
|
-
process.exit(0);
|
|
91
|
-
}
|
|
92
|
-
process.exit(64);
|
|
93
|
-
`);
|
|
94
|
-
|
|
95
|
-
executable(pgrep, `#!/usr/bin/env bun
|
|
96
|
-
import { appendFileSync } from "node:fs";
|
|
97
|
-
const args = process.argv.slice(2);
|
|
98
|
-
if (args.length !== 2 || args[0] !== "-f") process.exit(64);
|
|
99
|
-
const pattern = args[1] || "";
|
|
100
|
-
appendFileSync(process.env.FAKE_PROBE_LOG!, args.join("\\t") + "\\n");
|
|
101
|
-
if (process.env.FAKE_ORPHAN === "1") {
|
|
102
|
-
console.log("4321 orphan-for-" + pattern);
|
|
103
|
-
process.exit(0);
|
|
104
|
-
}
|
|
105
|
-
process.exit(1);
|
|
106
|
-
`);
|
|
107
|
-
|
|
108
|
-
executable(childScript, `#!/usr/bin/env bun
|
|
109
|
-
import { writeFileSync } from "node:fs";
|
|
110
|
-
const [behavior, argument] = process.argv.slice(2);
|
|
111
|
-
writeFileSync(process.env.FAKE_CHILD_MARKER!, behavior || "unknown");
|
|
112
|
-
if (behavior === "estimate") {
|
|
113
|
-
const fakeHash = process.env.FAKE_EMPTY_HASHES === "1" ? "" : "b".repeat(64);
|
|
114
|
-
const summary = {
|
|
115
|
-
failedSessions: Number(process.env.FAKE_FAILED_SESSIONS || 0),
|
|
116
|
-
changedSessions: Number(process.env.FAKE_CHANGED_SESSIONS || 0),
|
|
117
|
-
frozenBundle: { bundleHash: fakeHash, requestProfileHash: fakeHash },
|
|
118
|
-
};
|
|
119
|
-
writeFileSync(argument, JSON.stringify({ summary }));
|
|
120
|
-
console.log(JSON.stringify(summary));
|
|
121
|
-
process.exit(0);
|
|
122
|
-
}
|
|
123
|
-
if (behavior === "fail") process.exit(Number(argument || 7));
|
|
124
|
-
if (behavior === "wait") setInterval(() => {}, 1_000);
|
|
125
|
-
console.log(JSON.stringify({ ok: true }));
|
|
126
|
-
`);
|
|
127
|
-
|
|
128
|
-
const home = join(root, "home");
|
|
129
|
-
const env: NodeJS.ProcessEnv = {
|
|
130
|
-
...process.env,
|
|
131
|
-
PIVOT_SUPERVISOR_HOME: home,
|
|
132
|
-
PIVOT_SUPERVISOR_LAUNCHCTL: launchctl,
|
|
133
|
-
PIVOT_SUPERVISOR_PGREP: pgrep,
|
|
134
|
-
FAKE_LAUNCH_STATE: launchState,
|
|
135
|
-
FAKE_LAUNCH_LOG: launchLog,
|
|
136
|
-
FAKE_PROBE_LOG: probeLog,
|
|
137
|
-
FAKE_CHILD_MARKER: childMarker,
|
|
138
|
-
};
|
|
139
|
-
return {
|
|
140
|
-
root,
|
|
141
|
-
stateDir,
|
|
142
|
-
launchState,
|
|
143
|
-
launchLog,
|
|
144
|
-
probeLog,
|
|
145
|
-
childMarker,
|
|
146
|
-
launchctl,
|
|
147
|
-
pgrep,
|
|
148
|
-
childScript,
|
|
149
|
-
env,
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function supervisorArgs(
|
|
154
|
-
harness: FakeHarness,
|
|
155
|
-
mode: SupervisorMode,
|
|
156
|
-
childArgs: string[],
|
|
157
|
-
supervisorFlags: string[] = [],
|
|
158
|
-
): string[] {
|
|
159
|
-
return [
|
|
160
|
-
SUPERVISOR,
|
|
161
|
-
"--mode",
|
|
162
|
-
mode,
|
|
163
|
-
"--state-dir",
|
|
164
|
-
harness.stateDir,
|
|
165
|
-
...supervisorFlags,
|
|
166
|
-
"--",
|
|
167
|
-
BUN,
|
|
168
|
-
harness.childScript,
|
|
169
|
-
...childArgs,
|
|
170
|
-
];
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function run(
|
|
174
|
-
harness: FakeHarness,
|
|
175
|
-
mode: SupervisorMode,
|
|
176
|
-
childArgs: string[],
|
|
177
|
-
supervisorFlags: string[] = [],
|
|
178
|
-
extraEnv: NodeJS.ProcessEnv = {},
|
|
179
|
-
) {
|
|
180
|
-
return spawnSync(BUN, supervisorArgs(harness, mode, childArgs, supervisorFlags), {
|
|
181
|
-
env: { ...harness.env, ...extraEnv },
|
|
182
|
-
encoding: "utf8",
|
|
183
|
-
timeout: 15_000,
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function launchLogLines(harness: FakeHarness): string[] {
|
|
188
|
-
if (!existsSync(harness.launchLog)) return [];
|
|
189
|
-
return readFileSync(harness.launchLog, "utf8").trim().split("\n").filter(Boolean);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
function loadedAfter(harness: FakeHarness): string[] {
|
|
193
|
-
return JSON.parse(readFileSync(harness.launchState, "utf8")) as string[];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
function expectRestored(harness: FakeHarness): void {
|
|
197
|
-
const lines = launchLogLines(harness);
|
|
198
|
-
for (const label of LOADED_LABELS) {
|
|
199
|
-
const bootout = lines.indexOf(`bootout\t${label}`);
|
|
200
|
-
const bootstrap = lines.indexOf(`bootstrap\t${label}`);
|
|
201
|
-
expect(bootout).toBeGreaterThanOrEqual(0);
|
|
202
|
-
expect(bootstrap).toBeGreaterThan(bootout);
|
|
203
|
-
expect(lines.slice(bootstrap + 1)).toContain(`print\t${label}`);
|
|
204
|
-
}
|
|
205
|
-
expect(lines).not.toContain(`bootstrap\t${PRIOR_ABSENT_LABEL}`);
|
|
206
|
-
expect(loadedAfter(harness).sort()).toEqual([...LOADED_LABELS].sort());
|
|
207
|
-
const statePath = join(harness.stateDir, "prior-state.json");
|
|
208
|
-
const state = JSON.parse(readFileSync(statePath, "utf8")) as { status: string };
|
|
209
|
-
expect(state.status).toBe("restored");
|
|
210
|
-
expect(statSync(harness.stateDir).mode & 0o777).toBe(0o700);
|
|
211
|
-
expect(statSync(statePath).mode & 0o777).toBe(0o600);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
async function waitForFile(path: string, timeoutMs = 5_000): Promise<void> {
|
|
215
|
-
const deadline = Date.now() + timeoutMs;
|
|
216
|
-
while (!existsSync(path)) {
|
|
217
|
-
if (Date.now() >= deadline) throw new Error(`Timed out waiting for ${path}`);
|
|
218
|
-
await Bun.sleep(20);
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
describe("pivot distill LaunchAgent supervisor policy", () => {
|
|
223
|
-
it("derives all task selection from the exact ten-item inventory", () => {
|
|
224
|
-
expect(SUPERVISED_TASKS.map((task) => [task.label, task.tier])).toEqual([
|
|
225
|
-
["com.recallnest.incremental-ingest", "required"],
|
|
226
|
-
["com.recallnest.pull-from-macbook", "required"],
|
|
227
|
-
["com.anxianjingya.agy-conversations-sync", "required"],
|
|
228
|
-
["com.anxianjingya.macbook-mirror-pull", "required"],
|
|
229
|
-
["com.anxianjingya.conversation-truth-refresh", "required"],
|
|
230
|
-
["com.recallnest.dream-consolidation", "required"],
|
|
231
|
-
["com.recallnest.dream-memory-weekly", "required"],
|
|
232
|
-
["com.recallnest.weekly-distill", "required"],
|
|
233
|
-
["com.recallnest.daily-optimize", "required"],
|
|
234
|
-
["com.anxianjingya.repos-autopull", "recommended"],
|
|
235
|
-
]);
|
|
236
|
-
expect(SUPERVISED_TASKS.every((task) => task.reason.length > 0 && task.processPatterns.length > 0)).toBe(true);
|
|
237
|
-
expect(SUPERVISED_TASKS.flatMap((task) => task.processPatterns)).toEqual(expect.arrayContaining([
|
|
238
|
-
"[a]gy-conversations-sync[.]sh",
|
|
239
|
-
"[a]ntigravity-brain-to-jsonl[.]py",
|
|
240
|
-
"[a]ntigravity-db-to-jsonl[.]py",
|
|
241
|
-
"[c]li[.]ts import",
|
|
242
|
-
"[r]efresh-conversation-truth[.]py",
|
|
243
|
-
"[r]ecallnest-optimize[.]js",
|
|
244
|
-
]));
|
|
245
|
-
expect(tasksForMode("sync-only")).toHaveLength(9);
|
|
246
|
-
expect(tasksForMode("estimate")).toHaveLength(9);
|
|
247
|
-
expect(tasksForMode("transport")).toHaveLength(9);
|
|
248
|
-
expect(tasksForMode("full")).toHaveLength(10);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
it("treats failedSessions in an exit-zero estimate as failure and restores prior state", () => {
|
|
252
|
-
const harness = fakeHarness();
|
|
253
|
-
const resultJson = join(harness.root, "estimate.json");
|
|
254
|
-
const result = run(
|
|
255
|
-
harness,
|
|
256
|
-
"estimate",
|
|
257
|
-
["estimate", resultJson],
|
|
258
|
-
["--result-json", resultJson],
|
|
259
|
-
{ FAKE_FAILED_SESSIONS: "2" },
|
|
260
|
-
);
|
|
261
|
-
expect(result.status).toBe(1);
|
|
262
|
-
expect(result.stderr).toContain("failedSessions=2");
|
|
263
|
-
expectRestored(harness);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it("treats changedSessions in an exit-zero estimate as failure and restores prior state", () => {
|
|
267
|
-
const harness = fakeHarness();
|
|
268
|
-
const resultJson = join(harness.root, "estimate.json");
|
|
269
|
-
const result = run(
|
|
270
|
-
harness,
|
|
271
|
-
"estimate",
|
|
272
|
-
["estimate", resultJson],
|
|
273
|
-
["--result-json", resultJson],
|
|
274
|
-
{ FAKE_CHANGED_SESSIONS: "1" },
|
|
275
|
-
);
|
|
276
|
-
expect(result.status).toBe(1);
|
|
277
|
-
expect(result.stderr).toContain("changedSessions=1");
|
|
278
|
-
expectRestored(harness);
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
it("rejects negative counters and empty hashes in an exit-zero estimate", () => {
|
|
282
|
-
const negative = fakeHarness();
|
|
283
|
-
const negativeJson = join(negative.root, "estimate.json");
|
|
284
|
-
const negativeResult = run(
|
|
285
|
-
negative,
|
|
286
|
-
"estimate",
|
|
287
|
-
["estimate", negativeJson],
|
|
288
|
-
["--result-json", negativeJson],
|
|
289
|
-
{ FAKE_FAILED_SESSIONS: "-1" },
|
|
290
|
-
);
|
|
291
|
-
expect(negativeResult.status).toBe(1);
|
|
292
|
-
expect(negativeResult.stderr).toContain("failedSessions=-1");
|
|
293
|
-
expectRestored(negative);
|
|
294
|
-
|
|
295
|
-
const emptyHash = fakeHarness();
|
|
296
|
-
const emptyHashJson = join(emptyHash.root, "estimate.json");
|
|
297
|
-
const emptyHashResult = run(
|
|
298
|
-
emptyHash,
|
|
299
|
-
"estimate",
|
|
300
|
-
["estimate", emptyHashJson],
|
|
301
|
-
["--result-json", emptyHashJson],
|
|
302
|
-
{ FAKE_EMPTY_HASHES: "1" },
|
|
303
|
-
);
|
|
304
|
-
expect(emptyHashResult.status).toBe(1);
|
|
305
|
-
expect(emptyHashResult.stderr).toContain("missing bundleHash/requestProfileHash");
|
|
306
|
-
expectRestored(emptyHash);
|
|
307
|
-
});
|
|
308
|
-
|
|
309
|
-
it("accepts only a zero-failure estimate with a frozen bundle, then restores prior state", () => {
|
|
310
|
-
const harness = fakeHarness();
|
|
311
|
-
const resultJson = join(harness.root, "estimate.json");
|
|
312
|
-
const result = run(
|
|
313
|
-
harness,
|
|
314
|
-
"estimate",
|
|
315
|
-
["estimate", resultJson],
|
|
316
|
-
["--result-json", resultJson],
|
|
317
|
-
);
|
|
318
|
-
expect(result.status).toBe(0);
|
|
319
|
-
expectRestored(harness);
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it("restores after an authorized transport child fails", () => {
|
|
323
|
-
const harness = fakeHarness();
|
|
324
|
-
const result = run(harness, "transport", ["fail", "7"], ["--allow-external-llm"]);
|
|
325
|
-
expect(result.status).toBe(1);
|
|
326
|
-
expect(result.stderr).toContain("child command failed (exit 7)");
|
|
327
|
-
expectRestored(harness);
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
it("runs full with both authorizations, includes recommended tasks, and restores", () => {
|
|
331
|
-
const harness = fakeHarness();
|
|
332
|
-
const result = run(
|
|
333
|
-
harness,
|
|
334
|
-
"full",
|
|
335
|
-
["ok"],
|
|
336
|
-
["--allow-external-llm", "--allow-full-run"],
|
|
337
|
-
);
|
|
338
|
-
expect(result.status).toBe(0);
|
|
339
|
-
expect(launchLogLines(harness)).toContain("print\tcom.anxianjingya.repos-autopull");
|
|
340
|
-
expect(readFileSync(harness.probeLog, "utf8")).toContain("-f\t[r]epos-autopull");
|
|
341
|
-
expectRestored(harness);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it("terminates the child, restores, and exits 143 on SIGTERM", async () => {
|
|
345
|
-
const harness = fakeHarness();
|
|
346
|
-
const child = spawn(BUN, supervisorArgs(harness, "sync-only", ["wait"]), {
|
|
347
|
-
env: harness.env,
|
|
348
|
-
stdio: ["ignore", "pipe", "pipe"],
|
|
349
|
-
});
|
|
350
|
-
await waitForFile(harness.childMarker);
|
|
351
|
-
child.kill("SIGTERM");
|
|
352
|
-
const exitCode = await new Promise<number | null>((resolveExit) => child.once("close", resolveExit));
|
|
353
|
-
expect(exitCode).toBe(143);
|
|
354
|
-
expectRestored(harness);
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
it("refuses missing transport authorization before any launchctl call", () => {
|
|
358
|
-
const harness = fakeHarness();
|
|
359
|
-
const result = run(harness, "transport", ["ok"]);
|
|
360
|
-
expect(result.status).toBe(1);
|
|
361
|
-
expect(result.stderr).toContain("transport refused");
|
|
362
|
-
expect(launchLogLines(harness)).toEqual([]);
|
|
363
|
-
expect(existsSync(harness.stateDir)).toBe(false);
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
it("fails closed on an operational launchctl print error before any mutation", () => {
|
|
367
|
-
const harness = fakeHarness();
|
|
368
|
-
const result = run(harness, "sync-only", ["ok"], [], {
|
|
369
|
-
FAKE_PRINT_ERROR_LABEL: "com.anxianjingya.agy-conversations-sync",
|
|
370
|
-
});
|
|
371
|
-
expect(result.status).toBe(1);
|
|
372
|
-
expect(result.stderr).toContain("launchctl print failed for com.anxianjingya.agy-conversations-sync (exit 64)");
|
|
373
|
-
expect(launchLogLines(harness).some((line) => line.startsWith("bootout\t"))).toBe(false);
|
|
374
|
-
expect(launchLogLines(harness).some((line) => line.startsWith("bootstrap\t"))).toBe(false);
|
|
375
|
-
expect(existsSync(harness.childMarker)).toBe(false);
|
|
376
|
-
});
|
|
377
|
-
|
|
378
|
-
it("continues restoring later tasks when one post-bootstrap print fails", () => {
|
|
379
|
-
const harness = fakeHarness();
|
|
380
|
-
const first = LOADED_LABELS[0];
|
|
381
|
-
const result = run(harness, "sync-only", ["ok"], [], {
|
|
382
|
-
FAKE_PRINT_ERROR_AFTER_BOOTSTRAP_LABEL: first,
|
|
383
|
-
});
|
|
384
|
-
expect(result.status).toBe(1);
|
|
385
|
-
expect(result.stderr).toContain(`launchctl print failed for ${first} (exit 65)`);
|
|
386
|
-
for (const label of LOADED_LABELS.slice(1)) {
|
|
387
|
-
expect(launchLogLines(harness)).toContain(`bootstrap\t${label}`);
|
|
388
|
-
}
|
|
389
|
-
expect(loadedAfter(harness).sort()).toEqual([...LOADED_LABELS].sort());
|
|
390
|
-
const state = JSON.parse(
|
|
391
|
-
readFileSync(join(harness.stateDir, "prior-state.json"), "utf8"),
|
|
392
|
-
) as { status: string };
|
|
393
|
-
expect(state.status).toBe("restore-failed");
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
it("blocks on an orphan process without killing it, then restores", () => {
|
|
397
|
-
const harness = fakeHarness();
|
|
398
|
-
const result = run(harness, "sync-only", ["ok"], [], { FAKE_ORPHAN: "1" });
|
|
399
|
-
expect(result.status).toBe(1);
|
|
400
|
-
expect(result.stderr).toContain("blocked: orphan process remains");
|
|
401
|
-
expect(existsSync(harness.childMarker)).toBe(false);
|
|
402
|
-
expectRestored(harness);
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
it("does not overwrite an unrecovered prior-state record", () => {
|
|
406
|
-
const harness = fakeHarness();
|
|
407
|
-
const first = run(harness, "sync-only", ["fail", "9"]);
|
|
408
|
-
expect(first.status).toBe(1);
|
|
409
|
-
const statePath = join(harness.stateDir, "prior-state.json");
|
|
410
|
-
const state = JSON.parse(readFileSync(statePath, "utf8")) as Record<string, unknown>;
|
|
411
|
-
state.status = "active";
|
|
412
|
-
state.outcome = "simulated-crash";
|
|
413
|
-
writeFileSync(statePath, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600 });
|
|
414
|
-
writeFileSync(harness.launchLog, "");
|
|
415
|
-
|
|
416
|
-
const second = run(harness, "sync-only", ["ok"]);
|
|
417
|
-
expect(second.status).toBe(1);
|
|
418
|
-
expect(second.stderr).toContain("run --recover first");
|
|
419
|
-
expect(launchLogLines(harness)).toEqual([]);
|
|
420
|
-
const preserved = JSON.parse(readFileSync(statePath, "utf8")) as Record<string, unknown>;
|
|
421
|
-
expect(preserved.outcome).toBe("simulated-crash");
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it("--recover restores only prior-loaded tasks and keeps prior-absent tasks absent", () => {
|
|
425
|
-
const harness = fakeHarness();
|
|
426
|
-
const first = run(harness, "sync-only", ["fail", "9"]);
|
|
427
|
-
expect(first.status).toBe(1);
|
|
428
|
-
const statePath = join(harness.stateDir, "prior-state.json");
|
|
429
|
-
const state = JSON.parse(readFileSync(statePath, "utf8")) as Record<string, unknown>;
|
|
430
|
-
state.status = "active";
|
|
431
|
-
delete state.restoredAt;
|
|
432
|
-
writeFileSync(statePath, `${JSON.stringify(state, null, 2)}\n`, { mode: 0o600 });
|
|
433
|
-
writeFileSync(harness.launchState, "[]");
|
|
434
|
-
writeFileSync(harness.launchLog, "");
|
|
435
|
-
|
|
436
|
-
const recovered = spawnSync(BUN, [
|
|
437
|
-
SUPERVISOR,
|
|
438
|
-
"--recover",
|
|
439
|
-
"--state-dir",
|
|
440
|
-
harness.stateDir,
|
|
441
|
-
], {
|
|
442
|
-
env: harness.env,
|
|
443
|
-
encoding: "utf8",
|
|
444
|
-
timeout: 15_000,
|
|
445
|
-
});
|
|
446
|
-
expect(recovered.status).toBe(0);
|
|
447
|
-
const lines = launchLogLines(harness);
|
|
448
|
-
expect(lines.some((line) => line.startsWith("bootout\t"))).toBe(false);
|
|
449
|
-
for (const label of LOADED_LABELS) {
|
|
450
|
-
const bootstrap = lines.indexOf(`bootstrap\t${label}`);
|
|
451
|
-
expect(bootstrap).toBeGreaterThanOrEqual(0);
|
|
452
|
-
expect(lines.slice(bootstrap + 1)).toContain(`print\t${label}`);
|
|
453
|
-
}
|
|
454
|
-
expect(lines).not.toContain(`bootstrap\t${PRIOR_ABSENT_LABEL}`);
|
|
455
|
-
expect(loadedAfter(harness).sort()).toEqual([...LOADED_LABELS].sort());
|
|
456
|
-
});
|
|
457
|
-
});
|