@evomap/evolver-cli 2.0.48 → 2.0.49

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.
@@ -3,7 +3,7 @@ import { closeSync, constants, existsSync, fstatSync, ftruncateSync, fsyncSync,
3
3
  import { basename, dirname, isAbsolute, join, relative, resolve } from 'node:path';
4
4
  import { userInfo } from 'node:os';
5
5
  import { gzipSync, gunzipSync } from 'node:zlib';
6
- import { reference, algo, events, util } from '@evomap/evolver-core';
6
+ import { reference, algo, events, util, assetstore } from '@evomap/evolver-core';
7
7
  import { MAX_TRIGGER_FEEDBACK_BYTES, TRIGGER_FEEDBACK_FILE, readLocalTriggerFeedback, upsertLocalTriggerFeedback, triggerFeedbackRecords } from './localTriggerFeedback.js';
8
8
  import { authorizeTriggerFeedbackDelivery, claimTriggerFeedbackDelivery, markTriggerFeedbackDispatched, settleTriggerFeedbackDelivery } from './triggerFeedbackSyncState.js';
9
9
  const ACTIVE_FILE = 'memory_graph.v2.jsonl';
@@ -524,7 +524,7 @@ export class LocalMemoryGraph {
524
524
  const payload = this.readResetSource(file);
525
525
  const destination = join(backup.pendingDir, file.name);
526
526
  this.writeAtomic(destination, payload);
527
- const copiedIdentity = lstatSync(destination, { bigint: true });
527
+ const copiedIdentity = graphPathSnapshot(destination);
528
528
  const copiedPayload = this.readRawBounded(destination, payload.length);
529
529
  if (!copiedIdentity.isFile() || copiedIdentity.isSymbolicLink()
530
530
  || copiedPayload === null || !copiedPayload.equals(payload)) {
@@ -596,7 +596,7 @@ export class LocalMemoryGraph {
596
596
  const path = join(this.dir, name);
597
597
  let identity;
598
598
  try {
599
- identity = lstatSync(path, { bigint: true });
599
+ identity = graphPathSnapshot(path);
600
600
  }
601
601
  catch (error) {
602
602
  if (isObject(error) && error['code'] === 'ENOENT')
@@ -661,7 +661,7 @@ export class LocalMemoryGraph {
661
661
  cleanupResetPendingDirectory(backup, copied) {
662
662
  for (const file of [...copied].reverse()) {
663
663
  try {
664
- const current = lstatSync(file.path, { bigint: true });
664
+ const current = graphPathSnapshot(file.path);
665
665
  if (current.isFile() && !current.isSymbolicLink()
666
666
  && sameGraphFileIdentity(file.identity, current))
667
667
  unlinkSync(file.path);
@@ -773,7 +773,7 @@ export class LocalMemoryGraph {
773
773
  const path = join(this.dir, EPOCH_FILE);
774
774
  let identity;
775
775
  try {
776
- identity = lstatSync(path, { bigint: true });
776
+ identity = graphPathSnapshot(path);
777
777
  }
778
778
  catch (error) {
779
779
  if (isObject(error) && error['code'] === 'ENOENT') {
@@ -856,7 +856,7 @@ export class LocalMemoryGraph {
856
856
  if (!baseline)
857
857
  return false;
858
858
  try {
859
- const current = lstatSync(join(this.dir, COMPACT_FILE), { bigint: true });
859
+ const current = graphPathSnapshot(join(this.dir, COMPACT_FILE));
860
860
  return current.isFile() && !current.isSymbolicLink()
861
861
  && serializedSnapshotMatches(baseline, current);
862
862
  }
@@ -886,7 +886,7 @@ export class LocalMemoryGraph {
886
886
  const path = join(this.dir, ACTIVE_FILE);
887
887
  let identity;
888
888
  try {
889
- identity = lstatSync(path, { bigint: true });
889
+ identity = graphPathSnapshot(path);
890
890
  }
891
891
  catch (error) {
892
892
  if (isObject(error) && error['code'] === 'ENOENT') {
@@ -955,7 +955,7 @@ export class LocalMemoryGraph {
955
955
  if (!expected)
956
956
  return true;
957
957
  try {
958
- const current = lstatSync(join(this.dir, file), { bigint: true });
958
+ const current = graphPathSnapshot(join(this.dir, file));
959
959
  return !current.isFile() || current.isSymbolicLink()
960
960
  || !serializedSnapshotMatches(expected, current);
961
961
  }
@@ -1074,7 +1074,7 @@ export class LocalMemoryGraph {
1074
1074
  const archives = this.archiveFiles().length;
1075
1075
  let activeOversized = false;
1076
1076
  if (existsSync(activePath) && this.secureRegularFile(activePath)) {
1077
- const activeIdentity = lstatSync(activePath, { bigint: true });
1077
+ const activeIdentity = graphPathSnapshot(activePath);
1078
1078
  const window = this.activeLogicalWindow(epoch, activeIdentity);
1079
1079
  activeOversized = window.invalid || window.size > this.maxActiveBytes;
1080
1080
  }
@@ -1199,7 +1199,7 @@ export class LocalMemoryGraph {
1199
1199
  const path = join(this.dir, file);
1200
1200
  let stat;
1201
1201
  try {
1202
- stat = lstatSync(path, { bigint: true });
1202
+ stat = graphPathSnapshot(path);
1203
1203
  }
1204
1204
  catch (error) {
1205
1205
  if (isObject(error) && error['code'] === 'ENOENT')
@@ -1681,7 +1681,7 @@ export class LocalMemoryGraph {
1681
1681
  rotationTargetMatches(path, target) {
1682
1682
  let identity;
1683
1683
  try {
1684
- identity = lstatSync(path, { bigint: true });
1684
+ identity = graphPathSnapshot(path);
1685
1685
  }
1686
1686
  catch (error) {
1687
1687
  if (isObject(error) && error['code'] === 'ENOENT')
@@ -1716,7 +1716,7 @@ export class LocalMemoryGraph {
1716
1716
  removeVerifiedRotationFile(path, identity, reason) {
1717
1717
  let current;
1718
1718
  try {
1719
- current = lstatSync(path, { bigint: true });
1719
+ current = graphPathSnapshot(path);
1720
1720
  }
1721
1721
  catch {
1722
1722
  throw new Error(reason);
@@ -1736,7 +1736,7 @@ export class LocalMemoryGraph {
1736
1736
  readVerifiedRotationFile(path, maxBytes, optional, reason, range) {
1737
1737
  let pathBefore;
1738
1738
  try {
1739
- pathBefore = lstatSync(path, { bigint: true });
1739
+ pathBefore = graphPathSnapshot(path);
1740
1740
  }
1741
1741
  catch (error) {
1742
1742
  if (optional && isObject(error) && error['code'] === 'ENOENT')
@@ -1772,7 +1772,7 @@ export class LocalMemoryGraph {
1772
1772
  const openedAfter = fstatSync(fd, { bigint: true });
1773
1773
  let pathAfter;
1774
1774
  try {
1775
- pathAfter = lstatSync(path, { bigint: true });
1775
+ pathAfter = graphPathSnapshot(path);
1776
1776
  }
1777
1777
  catch {
1778
1778
  throw new Error(reason);
@@ -1811,7 +1811,7 @@ export class LocalMemoryGraph {
1811
1811
  const path = join(this.dir, name);
1812
1812
  let identity;
1813
1813
  try {
1814
- identity = lstatSync(path, { bigint: true });
1814
+ identity = graphPathSnapshot(path);
1815
1815
  }
1816
1816
  catch (error) {
1817
1817
  if (isObject(error) && error['code'] === 'ENOENT')
@@ -1935,7 +1935,7 @@ export class LocalMemoryGraph {
1935
1935
  if (!this.secureRegularFile(activePath)) {
1936
1936
  throw new MemoryGraphImportStateRejectedError();
1937
1937
  }
1938
- const activeWindow = this.activeLogicalWindow(epoch, lstatSync(activePath, { bigint: true }));
1938
+ const activeWindow = this.activeLogicalWindow(epoch, graphPathSnapshot(activePath));
1939
1939
  if (activeWindow.invalid || activeWindow.size > this.maxActiveBytes) {
1940
1940
  throw new MemoryGraphImportStateRejectedError();
1941
1941
  }
@@ -2044,7 +2044,7 @@ export class LocalMemoryGraph {
2044
2044
  let closed = false;
2045
2045
  let published = false;
2046
2046
  try {
2047
- tempIdentity = lstatSync(temp, { bigint: true });
2047
+ tempIdentity = graphPathSnapshot(temp);
2048
2048
  const descriptorIdentity = fstatSync(fd, { bigint: true });
2049
2049
  if (!tempIdentity.isFile() || tempIdentity.isSymbolicLink()
2050
2050
  || !descriptorIdentity.isFile() || descriptorIdentity.isSymbolicLink()
@@ -2071,7 +2071,7 @@ export class LocalMemoryGraph {
2071
2071
  }
2072
2072
  if (!published && tempIdentity !== null) {
2073
2073
  try {
2074
- const currentIdentity = lstatSync(temp, { bigint: true });
2074
+ const currentIdentity = graphPathSnapshot(temp);
2075
2075
  if (currentIdentity.isFile() && !currentIdentity.isSymbolicLink()
2076
2076
  && sameGraphFileIdentity(tempIdentity, currentIdentity))
2077
2077
  unlinkSync(temp);
@@ -2187,7 +2187,7 @@ export class LocalMemoryGraph {
2187
2187
  if (!existsSync(path))
2188
2188
  return null;
2189
2189
  try {
2190
- const identity = lstatSync(path, { bigint: true });
2190
+ const identity = graphPathSnapshot(path);
2191
2191
  if (epoch.baseline?.recovery
2192
2192
  && serializedSnapshotMatches(epoch.baseline.recovery, identity))
2193
2193
  return null;
@@ -2718,6 +2718,10 @@ function writeAll(fd, payload, position = null) {
2718
2718
  offset += written;
2719
2719
  }
2720
2720
  }
2721
+ function graphPathSnapshot(path) {
2722
+ const named = lstatSync(path, { bigint: true });
2723
+ return named.isFile() && !named.isSymbolicLink() ? assetstore.captureRegularAssetFileSnapshot(path) : named;
2724
+ }
2721
2725
  function sameGraphFileIdentity(left, right) {
2722
2726
  const hasStableFileId = left.dev !== 0n || left.ino !== 0n || right.dev !== 0n || right.ino !== 0n;
2723
2727
  if (hasStableFileId)
@@ -1,4 +1,5 @@
1
1
  import * as recall from '@evomap/evolver-core/prompt-recall';
2
+ import { type ProtectedAuditSessionNoticeOptions } from './protectedAuditStatus.js';
2
3
  type HookInputReader = (signal?: AbortSignal) => string | undefined | Promise<string | undefined>;
3
4
  export interface PromptRecallHookDeps {
4
5
  store?: recall.AssetStoreProvider;
@@ -15,6 +16,8 @@ export interface PromptRecallHookDeps {
15
16
  /** External delivery writers must own preparation, projection and terminal release. */
16
17
  ingestor?: Pick<recall.Ingestor, 'prepareContextDelivery'> & Partial<Pick<recall.Ingestor, 'prepareContextDeliveryAsync' | 'recoverContextDeliveries'>>;
17
18
  selectionTimeoutMs?: number;
19
+ /** Test seam for the protected audit probe and its per-session notice state. */
20
+ protectedAuditNotice?: ProtectedAuditSessionNoticeOptions;
18
21
  }
19
22
  /**
20
23
  * Shared Claude Code/Codex UserPromptSubmit entrypoint. It is intentionally local-only and fail-open: no Hub
@@ -2,6 +2,7 @@ import * as recall from '@evomap/evolver-core/prompt-recall';
2
2
  import { createHash } from 'node:crypto';
3
3
  import { performance } from 'node:perf_hooks';
4
4
  import { deliverContextOutput, waitContextDelivery } from './contextDelivery.js';
5
+ import { writeProtectedAuditSessionNotice, protectedAuditNoticeStatePath } from './protectedAuditStatus.js';
5
6
  import { MAX_PROMPT_RECALL_STDIN_BYTES, MAX_PROMPT_RECALL_LOCAL_FILE_BYTES, MAX_PROMPT_RECALL_LOCAL_TOTAL_BYTES, promptRecallMode, wrapGeneContext, writeHookStdout, writeContextReadDiagnostic } from './promptRecallShared.js';
6
7
  const PROMPT_RECALL_STDIN_TIMEOUT_MS = 250;
7
8
  const PROMPT_RECALL_SELECTION_TIMEOUT_MS = 750;
@@ -543,6 +544,11 @@ async function runPromptRecallHookOwned(argv, deps) {
543
544
  if (typeof input.hook_event_name === 'string' && input.hook_event_name !== 'UserPromptSubmit') {
544
545
  throw new Error('unexpected hook event');
545
546
  }
547
+ const auditReadiness = (deps.protectedAuditNotice?.readiness ?? recall.protectedAuditReadiness)();
548
+ if (auditReadiness.state === 'unavailable') {
549
+ await writeProtectedAuditSessionNotice(typeof input.session_id === 'string' ? input.session_id : undefined, auditReadiness, deps.protectedAuditNotice?.statePath ?? protectedAuditNoticeStatePath(recall.evomapHome(env)), deps, '{}\n');
550
+ return 0;
551
+ }
546
552
  const prompt = input.prompt;
547
553
  if (typeof prompt !== 'string')
548
554
  throw new Error('prompt is not recallable');
@@ -11,6 +11,8 @@ export declare function waitContextDelivery<T>(promise: Promise<T>, timeoutMs?:
11
11
  export declare function promptRecallMode(env?: NodeJS.ProcessEnv): PromptRecallMode;
12
12
  /** Rebind section offsets/digest to the actual prompt, including wrappers; never slice an assembled body. */
13
13
  export declare function wrapGeneContext(context: assetstore.AssembledGeneContext, prefix: string, suffix: string): assetstore.AssembledGeneContext;
14
+ /** Only the transport's own pre-dispatch refusal proves no bytes were submitted. */
15
+ export declare function hookStdoutNotSubmitted(error: unknown): boolean;
14
16
  /** A successful callback means stdout_written, not host_received. One attempt only, even on EPIPE. */
15
17
  export declare function writeHookStdout(text: string, options?: {
16
18
  destroyOnTimeout?: boolean;
@@ -47,13 +47,23 @@ export function wrapGeneContext(context, prefix, suffix) {
47
47
  // One submitted write owns the stream until callback/close, including after
48
48
  // caller timeout. Refuse retries instead of accumulating listeners and queued bytes.
49
49
  const pendingStdoutWrites = new WeakMap();
50
+ class HookStdoutNotSubmittedError extends Error {
51
+ constructor() { super('hook_stdout_unconfirmed'); }
52
+ }
53
+ /** Only the transport's own pre-dispatch refusal proves no bytes were submitted. */
54
+ export function hookStdoutNotSubmitted(error) {
55
+ return error instanceof HookStdoutNotSubmittedError;
56
+ }
50
57
  /** A successful callback means stdout_written, not host_received. One attempt only, even on EPIPE. */
51
58
  export function writeHookStdout(text, options = {}) {
52
59
  return new Promise((resolve, reject) => {
53
60
  const stdout = process.stdout;
54
- if (pendingStdoutWrites.has(stdout)) {
55
- options.onSettled?.(false);
56
- reject(new Error('hook_stdout_unconfirmed'));
61
+ if (pendingStdoutWrites.has(stdout) || stdout.destroyed || stdout.writableEnded) {
62
+ try {
63
+ options.onSettled?.(false);
64
+ }
65
+ catch { /* The observer does not own the stream. */ }
66
+ reject(new HookStdoutNotSubmittedError());
57
67
  return;
58
68
  }
59
69
  const owner = {};
@@ -0,0 +1,22 @@
1
+ import { type ProtectedAuditReadiness } from '@evomap/evolver-core/prompt-recall';
2
+ export type { ProtectedAuditReadiness };
3
+ export type ProtectedAuditInstallState = 'ready' | 'not_required' | 'not_provisioned' | 'unavailable';
4
+ export declare const PROTECTED_AUDIT_INSTALL_GUIDE: string;
5
+ export interface ProtectedAuditInstallReport {
6
+ protected_audit: ProtectedAuditInstallState;
7
+ protected_audit_next_step?: string;
8
+ }
9
+ export declare function protectedAuditInstallReport(readiness: ProtectedAuditReadiness): ProtectedAuditInstallReport;
10
+ export interface ProtectedAuditSessionNoticeOptions {
11
+ readiness?: () => ProtectedAuditReadiness;
12
+ statePath?: string;
13
+ }
14
+ export declare function protectedAuditNoticeStatePath(evomapHome: string): string;
15
+ interface NoticeWriter {
16
+ /** A trusted writer resolves only after its output is complete. */
17
+ stdout?: (text: string) => void | Promise<void>;
18
+ stdoutWithSettlement?: (text: string, onSettled: (written: boolean) => void) => Promise<void>;
19
+ onOutputWritten?: () => void;
20
+ }
21
+ /** Reserve before attempting one write; only the actual transport acknowledgement confirms it. */
22
+ export declare function writeProtectedAuditSessionNotice(sessionId: string | undefined, readiness: ProtectedAuditReadiness, path: string, writer: NoticeWriter, emptyOutput?: string): Promise<void>;
@@ -0,0 +1,234 @@
1
+ import { createHash, randomUUID } from 'node:crypto';
2
+ import { closeSync, constants, fstatSync, mkdirSync, openSync, readFileSync, readSync, renameSync, unlinkSync, writeFileSync } from 'node:fs';
3
+ import { dirname, join } from 'node:path';
4
+ import { acquireLock, releaseLock } from '@evomap/evolver-core/prompt-recall';
5
+ import { hookStdoutNotSubmitted, writeHookStdout } from './promptRecallShared.js';
6
+ export const PROTECTED_AUDIT_INSTALL_GUIDE = 'an administrator must install the protected audit service with install-protected-audit-service.sh '
7
+ + 'from the same sealed release as this evolver binary (docs/release-smoke.md, section "POSIX 用户实际安装边界")';
8
+ const NOT_PROVISIONED_REASONS = new Set(['service_not_provisioned', 'client_config_missing']);
9
+ const MAX_NOTIFIED_SESSIONS = 256;
10
+ const NOTICE_OWNER = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/;
11
+ function protectedAuditInstallState(readiness) {
12
+ if (readiness.state !== 'unavailable')
13
+ return readiness.state;
14
+ return NOT_PROVISIONED_REASONS.has(readiness.reason) ? 'not_provisioned' : 'unavailable';
15
+ }
16
+ export function protectedAuditInstallReport(readiness) {
17
+ const state = protectedAuditInstallState(readiness);
18
+ if (state === 'ready' || state === 'not_required')
19
+ return { protected_audit: state };
20
+ const reason = readiness.state === 'unavailable' ? readiness.reason : state;
21
+ return {
22
+ protected_audit: state,
23
+ protected_audit_next_step: `Evolver cannot record audit events until the protected audit service is available (${reason}); ${PROTECTED_AUDIT_INSTALL_GUIDE}.`,
24
+ };
25
+ }
26
+ export function protectedAuditNoticeStatePath(evomapHome) {
27
+ return join(evomapHome, 'evolution', 'protected-audit-session-notice.json');
28
+ }
29
+ function decodeNoticeState(text) {
30
+ const data = JSON.parse(text);
31
+ const sessions = data.sessions;
32
+ if (!Array.isArray(sessions) || sessions.length > MAX_NOTIFIED_SESSIONS
33
+ || sessions.some((key) => typeof key !== 'string' || !/^[a-f0-9]{64}$/.test(key)))
34
+ throw new Error('invalid_audit_notice_state');
35
+ if (data.version === 1)
36
+ return { sessions, pending: {} };
37
+ const pending = data.pending;
38
+ if (data.version !== 2 || !pending || typeof pending !== 'object' || Array.isArray(pending)
39
+ || Object.entries(pending).some(([key, owner]) => !sessions.includes(key) || typeof owner !== 'string' || !NOTICE_OWNER.test(owner))) {
40
+ throw new Error('invalid_audit_notice_state');
41
+ }
42
+ return { sessions, pending };
43
+ }
44
+ function readNoticeState(path) {
45
+ try {
46
+ return decodeNoticeState(readFileSync(path, 'utf8'));
47
+ }
48
+ catch (error) {
49
+ if (error.code === 'ENOENT')
50
+ return { sessions: [], pending: {} };
51
+ throw error;
52
+ }
53
+ }
54
+ function writeOwnedNoticeFile(path, text) {
55
+ const fd = openSync(path, 'wx', 0o600);
56
+ try {
57
+ try {
58
+ writeFileSync(fd, text, 'utf8');
59
+ }
60
+ finally {
61
+ closeSync(fd);
62
+ }
63
+ }
64
+ catch (error) {
65
+ removeNoticeFile(path);
66
+ throw error;
67
+ }
68
+ }
69
+ function removeNoticeFile(path) {
70
+ try {
71
+ unlinkSync(path);
72
+ }
73
+ catch { /* The state file remains authoritative. */ }
74
+ }
75
+ function writeNoticeState(path, state) {
76
+ const temporary = `${path}.${randomUUID()}.tmp`;
77
+ writeOwnedNoticeFile(temporary, `${JSON.stringify({ version: 2, ...state })}\n`);
78
+ try {
79
+ renameSync(temporary, path);
80
+ }
81
+ catch (error) {
82
+ removeNoticeFile(temporary);
83
+ throw error;
84
+ }
85
+ }
86
+ function applyNoticeSettlement(state, key, owner, outcome) {
87
+ if (state.pending[key] !== owner)
88
+ return false;
89
+ delete state.pending[key];
90
+ if (outcome === 'not_submitted')
91
+ state.sessions.splice(state.sessions.indexOf(key), 1);
92
+ return true;
93
+ }
94
+ function noticeSettlementPath(path, owner) {
95
+ return `${path}.${owner}.settled`;
96
+ }
97
+ function readNoticeSettlement(path, key) {
98
+ try {
99
+ const fd = openSync(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
100
+ try {
101
+ const info = fstatSync(fd);
102
+ if (!info.isFile() || info.size > 80)
103
+ return undefined;
104
+ const bytes = Buffer.alloc(80);
105
+ const length = readSync(fd, bytes, 0, bytes.length, 0);
106
+ if (length !== info.size)
107
+ return undefined;
108
+ const receipt = bytes.toString('utf8', 0, length);
109
+ if (receipt === `${key}:written\n`)
110
+ return 'written';
111
+ if (receipt === `${key}:not_submitted\n`)
112
+ return 'not_submitted';
113
+ }
114
+ finally {
115
+ closeSync(fd);
116
+ }
117
+ }
118
+ catch { /* An unavailable receipt cannot authorize replay. */ }
119
+ return undefined;
120
+ }
121
+ function recoverNoticeSettlements(path, state, key) {
122
+ const candidates = state.sessions.length === MAX_NOTIFIED_SESSIONS ? Object.keys(state.pending) : [key];
123
+ const consumed = [];
124
+ for (const session of candidates) {
125
+ const owner = state.pending[session];
126
+ if (!owner)
127
+ continue;
128
+ const receipt = noticeSettlementPath(path, owner);
129
+ const outcome = readNoticeSettlement(receipt, session);
130
+ if (outcome && applyNoticeSettlement(state, session, owner, outcome))
131
+ consumed.push(receipt);
132
+ }
133
+ return consumed;
134
+ }
135
+ function updateNoticeState(path, update, recoveryKey) {
136
+ try {
137
+ mkdirSync(dirname(path), { recursive: true, mode: 0o700 });
138
+ const lockPath = `${path}.lock`;
139
+ const owner = acquireLock(lockPath, { maxTries: 1, waitMs: 0 });
140
+ let changed = false, released = false;
141
+ try {
142
+ const state = readNoticeState(path);
143
+ const consumed = recoveryKey ? recoverNoticeSettlements(path, state, recoveryKey) : [];
144
+ changed = update(state);
145
+ if (changed || consumed.length > 0)
146
+ writeNoticeState(path, state);
147
+ for (const receipt of consumed)
148
+ removeNoticeFile(receipt);
149
+ }
150
+ finally {
151
+ released = releaseLock(lockPath, owner).released;
152
+ }
153
+ return changed && released;
154
+ }
155
+ catch {
156
+ return false;
157
+ }
158
+ }
159
+ function settleNotice(path, key, owner, outcome) {
160
+ // The callback can outlive the caller or lose the state lock to another hook.
161
+ // An exclusive receipt preserves the exact outcome without waiting on that lock.
162
+ try {
163
+ writeOwnedNoticeFile(noticeSettlementPath(path, owner), `${key}:${outcome}\n`);
164
+ }
165
+ catch (error) {
166
+ if (error.code !== 'EEXIST') {
167
+ updateNoticeState(path, (state) => applyNoticeSettlement(state, key, owner, outcome));
168
+ return;
169
+ }
170
+ }
171
+ updateNoticeState(path, () => false, key);
172
+ }
173
+ function claimProtectedAuditSessionNotice(sessionId, readiness, path) {
174
+ if (readiness.state !== 'unavailable' || !sessionId)
175
+ return undefined;
176
+ const key = createHash('sha256').update(sessionId).digest('hex');
177
+ const owner = randomUUID();
178
+ const claimed = updateNoticeState(path, (state) => {
179
+ if (state.sessions.includes(key))
180
+ return false;
181
+ if (state.sessions.length === MAX_NOTIFIED_SESSIONS) {
182
+ // An interrupted write may have delivered bytes. Never evict an unconfirmed reservation.
183
+ const oldestConfirmed = state.sessions.findIndex((session) => !Object.hasOwn(state.pending, session));
184
+ if (oldestConfirmed < 0)
185
+ return false;
186
+ state.sessions.splice(oldestConfirmed, 1);
187
+ }
188
+ state.sessions.push(key);
189
+ state.pending[key] = owner;
190
+ return true;
191
+ }, key);
192
+ if (!claimed)
193
+ return undefined;
194
+ return {
195
+ message: `[evolver] Memory recall and recording are paused: the protected audit service is unavailable (${readiness.reason}); ${PROTECTED_AUDIT_INSTALL_GUIDE}.`,
196
+ settle: (outcome) => settleNotice(path, key, owner, outcome),
197
+ };
198
+ }
199
+ /** Reserve before attempting one write; only the actual transport acknowledgement confirms it. */
200
+ export async function writeProtectedAuditSessionNotice(sessionId, readiness, path, writer, emptyOutput = '') {
201
+ const notice = claimProtectedAuditSessionNotice(sessionId, readiness, path);
202
+ const text = notice ? `${JSON.stringify({ systemMessage: notice.message })}\n` : emptyOutput;
203
+ if (!text)
204
+ return;
205
+ let settled = false, outputWritten = false;
206
+ const actual = (written) => {
207
+ if (settled)
208
+ return;
209
+ settled = true;
210
+ if (!written)
211
+ return;
212
+ outputWritten = true;
213
+ notice?.settle('written');
214
+ try {
215
+ writer.onOutputWritten?.();
216
+ }
217
+ catch { /* An observer cannot invalidate confirmed stdout. */ }
218
+ };
219
+ try {
220
+ if (writer.stdoutWithSettlement)
221
+ await writer.stdoutWithSettlement(text, actual);
222
+ else if (writer.stdout) {
223
+ await writer.stdout(text);
224
+ actual(true);
225
+ }
226
+ else
227
+ await writeHookStdout(text, { onSettled: actual });
228
+ }
229
+ catch (error) {
230
+ // EPIPE, timeout and other post-dispatch errors can follow a partial delivery.
231
+ if (!outputWritten && hookStdoutNotSubmitted(error))
232
+ notice?.settle('not_submitted');
233
+ }
234
+ }
package/dist/recall.js CHANGED
@@ -5,10 +5,9 @@
5
5
  // `<session_id>.jsonl`, so recall matches them by session id (falling back to the most-recent inject for un-stamped
6
6
  // events / runtimes with no id). Pure logic lives in evolver-core/ops/recall; this module is the IO glue (read
7
7
  // transcript -> turns, resolve genes from the store, pull geneIds off the matching inject event).
8
- import { readFileSync } from 'node:fs';
9
8
  import { basename } from 'node:path';
10
9
  import { assetstore, events, ops } from '@evomap/evolver-core';
11
- import { adapterForPath } from '@evomap/evolver-runtime-adapters';
10
+ import { adapterForPath, readSessionLog } from '@evomap/evolver-runtime-adapters';
12
11
  /** Claude Code names a transcript `<session_id>.jsonl`, so the basename (minus extension) is the session id used to
13
12
  * match the inject event that produced THIS session (#205). Other runtimes' names simply won't match any stamped
14
13
  * sessionId, and the caller falls back to the most-recent inject — safe, never wrong, just less precise. */
@@ -146,7 +145,7 @@ export async function runRecall(argv, deps = {}) {
146
145
  }
147
146
  let content;
148
147
  try {
149
- content = (deps.readFile ?? ((p) => readFileSync(p, 'utf8')))(transcript);
148
+ content = (deps.readFile ?? readSessionLog)(transcript);
150
149
  }
151
150
  catch (e) {
152
151
  err(`recall: cannot read ${transcript}: ${e instanceof Error ? e.message : String(e)}`);
@@ -1,5 +1,5 @@
1
1
  type RuntimeCapabilityStatus = 'supported' | 'experimental' | 'unsupported';
2
- type RuntimeCapabilityId = 'claude-code' | 'codex' | 'cursor' | 'gemini' | 'antigravity' | 'kimi' | 'kiro' | 'opencode' | 'generic-chat' | 'llm';
2
+ type RuntimeCapabilityId = 'claude-code' | 'codex' | 'cursor' | 'gemini' | 'antigravity' | 'kimi' | 'workbuddy' | 'dsh' | 'grok' | 'kiro' | 'opencode' | 'generic-chat' | 'llm';
3
3
  interface RuntimeCapability {
4
4
  status: RuntimeCapabilityStatus;
5
5
  evidence: string;
@@ -59,6 +59,30 @@ export const RUNTIME_CAPABILITY_MATRIX = {
59
59
  verify: unsupported('no Kimi execution runner exists'),
60
60
  resume: unsupported('no verified Kimi resume contract'),
61
61
  },
62
+ workbuddy: {
63
+ runtime: 'workbuddy',
64
+ ingest: supported('WorkBuddy ~/.workbuddy/projects JSONL adapter verified against a sanitized real-log golden'),
65
+ inject: unsupported('no Evolver CLI injection installer; live hooks come from evolver-agent-plugin'),
66
+ execute: unsupported('no verified WorkBuddy runner contract'),
67
+ verify: unsupported('no WorkBuddy execution runner exists'),
68
+ resume: unsupported('no verified WorkBuddy resume contract'),
69
+ },
70
+ dsh: {
71
+ runtime: 'dsh',
72
+ ingest: supported('DeepSeek Harness session.v4.jsonl.zstd adapter verified against a sanitized real-log golden; needs Node zstd support'),
73
+ inject: unsupported('no Evolver CLI injection installer; live hooks come from evolver-agent-plugin'),
74
+ execute: unsupported('no verified DeepSeek Harness runner contract'),
75
+ verify: unsupported('no DeepSeek Harness execution runner exists'),
76
+ resume: unsupported('no verified DeepSeek Harness resume contract'),
77
+ },
78
+ grok: {
79
+ runtime: 'grok',
80
+ ingest: supported('Grok CLI chat_history.jsonl adapter verified against a sanitized real-log golden'),
81
+ inject: unsupported('no Evolver CLI injection installer; live hooks come from evolver-agent-plugin'),
82
+ execute: unsupported('no verified Grok runner contract'),
83
+ verify: unsupported('no Grok execution runner exists'),
84
+ resume: unsupported('no verified Grok resume contract'),
85
+ },
62
86
  kiro: {
63
87
  runtime: 'kiro',
64
88
  ingest: unsupported('transcript adapter is not registered; no real-log golden fixture'),
@@ -1,7 +1,7 @@
1
- import { readFileSync, realpathSync } from 'node:fs';
1
+ import { realpathSync } from 'node:fs';
2
2
  import { homedir } from 'node:os';
3
3
  import { isAbsolute, join, relative, resolve } from 'node:path';
4
- import { adapterForPath, isCursorStateVscdbPath, parseJsonlLinesWithStats, parseCursorStateVscdb, stripUtf8Bom, } from '@evomap/evolver-runtime-adapters';
4
+ import { adapterForPath, isCursorStateVscdbPath, parseJsonlLinesWithStats, parseCursorStateVscdb, readSessionLog, stripUtf8Bom, } from '@evomap/evolver-runtime-adapters';
5
5
  const EMPTY_DIAGNOSTICS = { rowsScanned: 0, rowsRead: 0, invalidJson: 0 };
6
6
  function canonicalNativeSessionSource(path, agent, nativeSessionHome) {
7
7
  const runtimeRoot = agent === 'claude-code'
@@ -46,7 +46,7 @@ function diagnosticsForRuntimeSource(raw) {
46
46
  return parseJsonlLinesWithStats(raw).stats;
47
47
  }
48
48
  }
49
- export function parseRuntimeSessionSourcesWithDiagnostics(path, readSource = (p) => readFileSync(p, 'utf8'), nativeSessionHome = homedir()) {
49
+ export function parseRuntimeSessionSourcesWithDiagnostics(path, readSource = readSessionLog, nativeSessionHome = homedir()) {
50
50
  const absPath = resolve(path);
51
51
  if (isCursorStateVscdbPath(absPath)) {
52
52
  const sources = parseCursorStateVscdb(absPath)
@@ -103,6 +103,6 @@ export function parseRuntimeSessionSourcesWithDiagnostics(path, readSource = (p)
103
103
  diagnostics: diagnosticsForRuntimeSource(raw),
104
104
  };
105
105
  }
106
- export function parseRuntimeSessionSources(path, readSource = (p) => readFileSync(p, 'utf8'), nativeSessionHome = homedir()) {
106
+ export function parseRuntimeSessionSources(path, readSource = readSessionLog, nativeSessionHome = homedir()) {
107
107
  return parseRuntimeSessionSourcesWithDiagnostics(path, readSource, nativeSessionHome).sources;
108
108
  }
@@ -92,6 +92,9 @@ const MATERIAL_SOURCE_AGENTS = new Set([
92
92
  'gemini',
93
93
  'antigravity',
94
94
  'kimi',
95
+ 'workbuddy',
96
+ 'dsh',
97
+ 'grok',
95
98
  'kiro',
96
99
  'opencode',
97
100
  'generic-chat',
@@ -1,11 +1,14 @@
1
1
  import { type InstallScope } from '@evomap/evolver-mcp';
2
2
  import { assetstore } from '@evomap/evolver-core';
3
3
  import { maybeEmitNonGitWorkspaceNotice } from './nonGitWorkspaceNotice.js';
4
+ import { type ProtectedAuditReadiness } from './protectedAuditStatus.js';
4
5
  interface SetupHooksDeps {
5
6
  emitNonGitWorkspaceNotice?: typeof maybeEmitNonGitWorkspaceNotice;
6
7
  runtimeAvailable?: (runtime: 'opencode' | 'kiro', configRoot: string, scope: InstallScope) => boolean;
7
8
  /** Test seam proving service-only/manual paths do not resolve an unrelated MCP Node executable. */
8
9
  resolveMcpNodePath?: () => string;
10
+ /** Test seam for the read-only protected audit service probe. */
11
+ protectedAudit?: () => ProtectedAuditReadiness;
9
12
  }
10
13
  export declare function commandNamesForPath(command: string, platform: NodeJS.Platform, pathExt: string | undefined): string[];
11
14
  /** Paths under package-manager stores are volatile: the linked Node disappears on the next install/upgrade,