codemem 0.48.0 → 0.48.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +350 -9
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.js
CHANGED
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
import { ACCOUNT_CONNECTION_MIGRATION_STATEMENTS, ACCOUNT_UNLINK_MIGRATION_STATEMENTS, AUTH_LINK_AUTHORITY_CUTOVER_SQL, ContextOnlyReplayError, CoordinatorAccountLinkError, DEDUP_KEY_BACKFILL_JOB, DEFAULT_COORDINATOR_DB_PATH, DEFAULT_RAW_EVENT_FLUSH_MAX_EVENTS, DedupKeyBackfillRunner, DeviceIdentityError, EXTRACTION_BENCHMARK_QUALITY_WEIGHTS, FILE_CONTEXT_TRANSPORT_MAX_BYTES, FILE_CONTEXT_TRANSPORT_PROFILE, LEGACY_OWNER_RESOLUTION_SCHEMA_STATEMENTS, MUTATING_TOOL_NAMES, MemoryStore, ObserverClient, ObserverOutputError, ObserverOutputTransportError, OwnerProfileEnrollmentError, PROMPT_TRANSPORT_PROTOCOL_RANGE, REF_BACKFILL_JOB, RawEventIngestValidationError, RawEventSweeper, RefBackfillRunner, RemoteCoordinatorRequestError, SCOPE_BACKFILL_JOB, SESSION_CONTEXT_BACKFILL_JOB, SUMMARY_DEDUP_BACKFILL_JOB, ScopeBackfillRunner, SessionContextBackfillRunner, SummaryDedupBackfillRunner, SyncRetentionRunner, TRUSTED_HOOK_MAPPER_OPTIONS, VERSION, VectorModelMigrationRunner, aiBackfillStructuredContent, applyBootstrapSnapshot, applyDistillRule, arePromptTransportProtocolRangesCompatible, atomicReplaceConfigFile, backfillMemoryDedupKeys, backfillNarrativeFromBody, backfillTagsText, backfillVectors, buildBaseUrl, buildDirectPeerAuthHeaders, buildDistillReport, buildPiFlushSignalFromEvent, buildRawEventEnvelopeFromHook, buildRawEventEnvelopeFromPiEvent, buildTieredObserverSelection, buildViewerIdentityTarget, classifyPromptTransportFailure, clonePromptPackAttempt, collectOperationalStatus, compareMemoryRoleReports, connect, connectReadOnly, coordinatorAuthControllerReviewAction, coordinatorCreateGroupAction, coordinatorCreateInviteAction, coordinatorCreateScopeAction, coordinatorDisableDeviceAction, coordinatorEnrollDeviceAction, coordinatorGrantIdentityGroupAction, coordinatorGrantScopeMembershipAction, coordinatorImportInviteAction, coordinatorListBootstrapGrantsAction, coordinatorListDevicesAction, coordinatorListGroupsAction, coordinatorListJoinRequestsAction, coordinatorListLegacyTeamCompletionsAction, coordinatorListScopeMembershipsAction, coordinatorListScopesAction, coordinatorQualifyOwnerAction, coordinatorRemoveDeviceAction, coordinatorRenameDeviceAction, coordinatorReviewInviteAction, coordinatorReviewJoinRequestAction, coordinatorRevokeBootstrapGrantAction, coordinatorRevokeDeviceAction, coordinatorRevokeScopeMembershipAction, coordinatorUpdateScopeAction, createBetterSqliteCoordinatorApp, createFileContextRunner, deactivateLowSignalMemories, deactivateLowSignalObservations, dedupNearDuplicateMemories, describePiObserverStatus, detectInstallKind, diagnoseLegacyTeamSetupCompletion, dispatchFileContextTransport, draftDistillRule, enrollOwnerProfile, ensureDeviceIdentity, ensureSchemaBootstrapped, estimateExtractionModelCost, expandUserPath, exportMemories, extractApplyPatchPaths, extractionReplayObserverIdentity, fetchAllSnapshotPages, fingerprintPublicKey, flushRawEvents, formatHostPort, getAttributionDiagnostics, getCodememConfigPath, getExtractionBenchmarkProfile, getExtractionModelPricing, getInjectionEvalScenarioPack, getInjectionEvalScenarioPrompts, getMaintenanceJob, getMemoryArtifactReport, getMemoryRoleReport, getRawEventRelinkPlan, getRawEventRelinkReport, getRawEventStatus, getSemanticIndexDiagnostics, getSessionExtractionEval, getSessionExtractionEvalScenario, getUpdateStatus, getWorkspaceCodememConfigPath, hasPendingDedupKeyBackfill, hasPendingRefBackfill, hasPendingScopeBackfill, hasPendingSessionContextBackfill, hasPendingSummaryDedupBackfill, hasUnsyncedSharedMemoryChanges, importMemories, importPiSessions, ingestRawEvents, initDatabase, isAutomaticRecallMeasurement, isCoordinatorControllerAttestationReference, isEmbeddingDisabled, isExplicitUpdateInstallEligible, isReleaseVersionForChannel, judgeDistillReport, legacyTeamCandidateId, linkCoordinatorAccount, linkCoordinatorAccountHeadless, listMaintenanceJobs, listPerPeerScopeSyncState, listRetentionScopeIds, loadObserverConfig, loadPublicKey, loadRuntimeSigningPublicKey, loadSqliteVec, mdnsEnabled, mutateCodememConfigFile, normalizeCoordinatorAccountLinkOrigin, normalizePromptTransportProtocolRange, observerBaseUrlForProviderOverride, parseControllerHistoryEvidence, parseFileContextTransportRequest, planReplicationOpsAgePrune, probeCodememViewerLiveness, probeCodememViewerLiveness as probeCodememViewerLiveness$1, probeRequiredNativeRuntime, projectMatchesFilter, promptPackArtifactFingerprint, pruneReplicationOpsUntilCaughtUp, rawEventsGate, readAccountLinkDevice, readCodememConfigFile, readCodememConfigFileAtPath, readCoordinatorAccountLinkStatus, readCoordinatorOwnerReviewLocalEvidence, readCoordinatorSyncConfig, readImportPayload, recordAutomaticRecall, recordPromptPackArtifacts, recordPromptPackTerminal, renderUnifiedDiff, replayBatchExtraction, replayBatchExtractionWithTierRouting, requestJson, resolveCodememConfigPath, resolveComparablePath, resolveDbPath, resolveHookProject, resolveKeyPaths, resolvePiAgentDir, resolvePiObserverConfig, resolveProject, resolveProjectRoot, retryRawEventFailures, runSyncDaemon, runSyncPass, scanSecretsRetroactive, schema, scoreExtractionBenchmarkOutput, searchPiSessions, setPeerProjectFilter, syncPassPreflight, tryUpdateRetrievalDelivery, updatePeerAddresses, upgradeCoordinatorAccountSchemaFile, upgradeCoordinatorAuthSchemaFile, upgradeCoordinatorOwnerResolutionSchemaFile, vacuumDatabase, viewerUrl, withDiagnosticStoreSnapshot, writeCodememConfigFile } from "@codemem/core";
|
|
3
3
|
import { Command, Option } from "commander";
|
|
4
4
|
import omelette from "omelette";
|
|
5
|
-
import {
|
|
5
|
+
import { isUtf8 } from "node:buffer";
|
|
6
|
+
import { createHash, randomInt, randomUUID } from "node:crypto";
|
|
7
|
+
import { appendFileSync, constants, copyFileSync, existsSync, mkdirSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, rmdirSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { lstat, mkdir, open, readFile, readdir, stat, unlink } from "node:fs/promises";
|
|
6
9
|
import { homedir, networkInterfaces } from "node:os";
|
|
7
10
|
import { dirname, isAbsolute, join, posix, relative, resolve, sep, win32 } from "node:path";
|
|
8
11
|
import { isDeepStrictEqual, styleText } from "node:util";
|
|
9
|
-
import { randomInt, randomUUID } from "node:crypto";
|
|
10
12
|
import * as p from "@clack/prompts";
|
|
11
13
|
import { serve } from "@hono/node-server";
|
|
12
14
|
import { execFileSync, spawn, spawnSync } from "node:child_process";
|
|
@@ -16,7 +18,236 @@ import { applyEdits, createScanner, findNodeAtLocation, modify, parse, parseTree
|
|
|
16
18
|
import { desc, eq } from "drizzle-orm";
|
|
17
19
|
import { drizzle } from "drizzle-orm/better-sqlite3";
|
|
18
20
|
import { approveRelayServiceKey, canonicalRelayServiceKey, listRelayServicePins, readRelayServicePin, relayCoordinatorEndpoint } from "@codemem/core/internal/relay-runtime";
|
|
19
|
-
|
|
21
|
+
//#region ../opencode-plugin/.opencode/lib/raw-event-spool.js
|
|
22
|
+
var MAX_REJECTED_RAW_EVENT_INSPECTION_BYTES = 16777216;
|
|
23
|
+
var INSPECTION_READ_CHUNK_BYTES = 65536;
|
|
24
|
+
var RAW_EVENT_SPOOL_CONFLICT_CODE = "raw_event_spool_conflict";
|
|
25
|
+
var SPOOL_DIRECTORY_NAME = "opencode-raw-event-spool";
|
|
26
|
+
var resolveSpoolDirectory = (homeDir = homedir()) => join(homeDir, ".codemem", SPOOL_DIRECTORY_NAME);
|
|
27
|
+
var spoolFilename = (eventId) => {
|
|
28
|
+
return `${createHash("sha256").update(String(eventId)).digest("hex")}.json`;
|
|
29
|
+
};
|
|
30
|
+
var rejectedReasons = /* @__PURE__ */ new Map([[400, "invalid_payload"], [413, "payload_too_large"]]);
|
|
31
|
+
var parseRejectedFilename = (name) => {
|
|
32
|
+
const match = /^rejected-([a-f0-9]{64})-(400|413)-(invalid_payload|payload_too_large)\.json$/.exec(name);
|
|
33
|
+
if (!match) return null;
|
|
34
|
+
const status = Number(match[2]);
|
|
35
|
+
if (rejectedReasons.get(status) !== match[3]) return null;
|
|
36
|
+
return {
|
|
37
|
+
digest: match[1],
|
|
38
|
+
status,
|
|
39
|
+
reason: match[3]
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
var requirePrivateSpoolDirectory = async (directory) => {
|
|
43
|
+
for (const path of [dirname(directory), directory]) {
|
|
44
|
+
const details = await lstat(path);
|
|
45
|
+
if (!details.isDirectory() || details.isSymbolicLink()) throw new Error("raw event spool requires a real directory");
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var readRegularSpoolFile = async (path, { makePrivate = false } = {}) => {
|
|
49
|
+
const handle = await open(path, constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK);
|
|
50
|
+
try {
|
|
51
|
+
const details = await handle.stat();
|
|
52
|
+
if (!details.isFile()) throw new Error("raw event spool requires a regular file");
|
|
53
|
+
const bytes = await handle.readFile();
|
|
54
|
+
if (!isUtf8(bytes)) throw new Error("raw event spool requires UTF-8 JSON");
|
|
55
|
+
const serialized = bytes.toString("utf8");
|
|
56
|
+
if (makePrivate) {
|
|
57
|
+
await handle.chmod(384);
|
|
58
|
+
await handle.sync();
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
serialized,
|
|
62
|
+
details
|
|
63
|
+
};
|
|
64
|
+
} finally {
|
|
65
|
+
await handle.close();
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var requireMatchingIdentity = (serialized, filename) => {
|
|
69
|
+
let envelope;
|
|
70
|
+
try {
|
|
71
|
+
envelope = JSON.parse(serialized);
|
|
72
|
+
} catch (error) {
|
|
73
|
+
error.spoolConflict = {
|
|
74
|
+
branch: "rejected_identity",
|
|
75
|
+
reason: "invalid_json"
|
|
76
|
+
};
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
let eventId;
|
|
80
|
+
try {
|
|
81
|
+
eventId = requireEventId(envelope);
|
|
82
|
+
} catch (error) {
|
|
83
|
+
error.spoolConflict = {
|
|
84
|
+
branch: "rejected_identity",
|
|
85
|
+
reason: "invalid_shape"
|
|
86
|
+
};
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
89
|
+
if (spoolFilename(eventId) !== filename) throw conflictingEntry({
|
|
90
|
+
branch: "rejected_identity",
|
|
91
|
+
reason: "identity_mismatch"
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
var rejectedMetadata = (name, entry, bytes) => ({
|
|
95
|
+
receipt: name,
|
|
96
|
+
bytes,
|
|
97
|
+
status: entry.status,
|
|
98
|
+
reason: entry.reason
|
|
99
|
+
});
|
|
100
|
+
var requireEventId = (envelope) => {
|
|
101
|
+
const eventId = typeof envelope?.event_id === "string" ? envelope.event_id.trim() : "";
|
|
102
|
+
if (!eventId) throw new Error("raw event spool requires event_id");
|
|
103
|
+
return eventId;
|
|
104
|
+
};
|
|
105
|
+
var conflictingEntry = (diagnostic) => {
|
|
106
|
+
const error = /* @__PURE__ */ new Error("raw event spool entry conflicts with existing event_id");
|
|
107
|
+
error.code = RAW_EVENT_SPOOL_CONFLICT_CODE;
|
|
108
|
+
if (diagnostic) error.spoolConflict = diagnostic;
|
|
109
|
+
return error;
|
|
110
|
+
};
|
|
111
|
+
var RawEventSpoolInspectionError = class extends Error {
|
|
112
|
+
constructor(code, message) {
|
|
113
|
+
super(message);
|
|
114
|
+
this.name = "RawEventSpoolInspectionError";
|
|
115
|
+
this.code = code;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var inspectionFailure = () => new RawEventSpoolInspectionError("inspection_failed", "Could not inspect retained events. Files were left untouched.");
|
|
119
|
+
var requireInspectionRegularFile = (details) => {
|
|
120
|
+
if (!details.isFile() || details.isSymbolicLink()) throw new RawEventSpoolInspectionError("unsafe_entry", "Receipt must name a regular file.");
|
|
121
|
+
};
|
|
122
|
+
var openRejectedEntryForInspection = async (path) => {
|
|
123
|
+
const expected = await lstat(path);
|
|
124
|
+
requireInspectionRegularFile(expected);
|
|
125
|
+
const flags = constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0) | (constants.O_NONBLOCK ?? 0);
|
|
126
|
+
const handle = await open(path, flags);
|
|
127
|
+
try {
|
|
128
|
+
for (const actual of [await handle.stat(), await lstat(path)]) {
|
|
129
|
+
requireInspectionRegularFile(actual);
|
|
130
|
+
if (actual.dev !== expected.dev || actual.ino !== expected.ino) throw new RawEventSpoolInspectionError("unsafe_entry", "Receipt changed while opening. Retry inspection.");
|
|
131
|
+
}
|
|
132
|
+
return handle;
|
|
133
|
+
} catch (error) {
|
|
134
|
+
await handle.close().catch(() => {});
|
|
135
|
+
throw error;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
var readWithinInspectionLimit = async (handle, maxBytes, { position = null } = {}) => {
|
|
139
|
+
const chunks = [];
|
|
140
|
+
let total = 0;
|
|
141
|
+
while (total <= maxBytes) {
|
|
142
|
+
const buffer = Buffer.alloc(Math.min(INSPECTION_READ_CHUNK_BYTES, maxBytes + 1 - total));
|
|
143
|
+
const offset = position === null ? null : position + total;
|
|
144
|
+
const { bytesRead } = await handle.read(buffer, 0, buffer.length, offset);
|
|
145
|
+
if (bytesRead === 0) return Buffer.concat(chunks, total);
|
|
146
|
+
total += bytesRead;
|
|
147
|
+
if (total > maxBytes) return null;
|
|
148
|
+
chunks.push(buffer.subarray(0, bytesRead));
|
|
149
|
+
}
|
|
150
|
+
return null;
|
|
151
|
+
};
|
|
152
|
+
var inspectOpenedRejectedEntry = async (handle, receipt, entry, maxBytes) => {
|
|
153
|
+
const before = await handle.stat();
|
|
154
|
+
requireInspectionRegularFile(before);
|
|
155
|
+
const metadata = rejectedMetadata(receipt, entry, before.size);
|
|
156
|
+
if (before.size > maxBytes) return {
|
|
157
|
+
...metadata,
|
|
158
|
+
validation: "read_limit_exceeded"
|
|
159
|
+
};
|
|
160
|
+
const bytes = await readWithinInspectionLimit(handle, maxBytes);
|
|
161
|
+
const after = await handle.stat();
|
|
162
|
+
if (!bytes || after.size > maxBytes) return {
|
|
163
|
+
...metadata,
|
|
164
|
+
bytes: after.size,
|
|
165
|
+
validation: "read_limit_exceeded"
|
|
166
|
+
};
|
|
167
|
+
if (before.size !== after.size || before.mtimeMs !== after.mtimeMs || before.ctimeMs !== after.ctimeMs) return {
|
|
168
|
+
...metadata,
|
|
169
|
+
validation: "changed_during_read"
|
|
170
|
+
};
|
|
171
|
+
try {
|
|
172
|
+
if (!isUtf8(bytes)) return {
|
|
173
|
+
...metadata,
|
|
174
|
+
validation: "invalid"
|
|
175
|
+
};
|
|
176
|
+
const serialized = bytes.toString("utf8");
|
|
177
|
+
requireMatchingIdentity(serialized, `${entry.digest}.json`);
|
|
178
|
+
return {
|
|
179
|
+
...metadata,
|
|
180
|
+
validation: "valid",
|
|
181
|
+
serialized
|
|
182
|
+
};
|
|
183
|
+
} catch {
|
|
184
|
+
return {
|
|
185
|
+
...metadata,
|
|
186
|
+
validation: "invalid"
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
var inspectRejectedRawEventSpoolEntry = async ({ receipt, homeDir = homedir(), maxBytes = MAX_REJECTED_RAW_EVENT_INSPECTION_BYTES }) => {
|
|
191
|
+
const entry = typeof receipt === "string" ? parseRejectedFilename(receipt) : null;
|
|
192
|
+
if (!entry) throw new RawEventSpoolInspectionError("invalid_receipt", "Use a receipt from capture list-rejected.");
|
|
193
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > 16777216) throw new RawEventSpoolInspectionError("invalid_limit", "Inspection limit must be between 1 byte and 16 MiB.");
|
|
194
|
+
let handle;
|
|
195
|
+
try {
|
|
196
|
+
const directory = resolveSpoolDirectory(homeDir);
|
|
197
|
+
await requirePrivateSpoolDirectory(directory);
|
|
198
|
+
handle = await openRejectedEntryForInspection(join(directory, receipt));
|
|
199
|
+
return await inspectOpenedRejectedEntry(handle, receipt, entry, maxBytes);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
if (error instanceof RawEventSpoolInspectionError) throw error;
|
|
202
|
+
if (error?.code === "ENOENT") throw new RawEventSpoolInspectionError("receipt_not_found", "Retained receipt was not found. Run capture list-rejected again.");
|
|
203
|
+
throw inspectionFailure();
|
|
204
|
+
} finally {
|
|
205
|
+
await handle?.close().catch(() => {});
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
var listRejectedEntries = async ({ homeDir, validation }) => {
|
|
209
|
+
const directory = resolveSpoolDirectory(homeDir);
|
|
210
|
+
let names;
|
|
211
|
+
try {
|
|
212
|
+
await requirePrivateSpoolDirectory(directory);
|
|
213
|
+
names = await readdir(directory, { withFileTypes: true });
|
|
214
|
+
} catch (error) {
|
|
215
|
+
if (error?.code === "ENOENT") return [];
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
const entries = [];
|
|
219
|
+
for (const candidate of names) {
|
|
220
|
+
const entry = parseRejectedFilename(candidate.name);
|
|
221
|
+
if (!candidate.isFile() || !entry) continue;
|
|
222
|
+
try {
|
|
223
|
+
if (validation === "metadata") {
|
|
224
|
+
const details = await lstat(join(directory, candidate.name));
|
|
225
|
+
if (details.isFile()) entries.push({
|
|
226
|
+
...rejectedMetadata(candidate.name, entry, details.size),
|
|
227
|
+
validation: "not_checked"
|
|
228
|
+
});
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const retained = await readRegularSpoolFile(join(directory, candidate.name));
|
|
232
|
+
requireMatchingIdentity(retained.serialized, `${entry.digest}.json`);
|
|
233
|
+
entries.push(rejectedMetadata(candidate.name, entry, retained.details.size));
|
|
234
|
+
} catch {}
|
|
235
|
+
}
|
|
236
|
+
return entries.sort((left, right) => left.receipt.localeCompare(right.receipt));
|
|
237
|
+
};
|
|
238
|
+
var listRejectedRawEventSpoolEntries = async ({ homeDir = homedir(), validation = "payload" } = {}) => {
|
|
239
|
+
if (!["metadata", "payload"].includes(validation)) throw new RawEventSpoolInspectionError("invalid_validation", "Unsupported inspection mode.");
|
|
240
|
+
try {
|
|
241
|
+
return await listRejectedEntries({
|
|
242
|
+
homeDir,
|
|
243
|
+
validation
|
|
244
|
+
});
|
|
245
|
+
} catch (error) {
|
|
246
|
+
if (validation === "payload") throw error;
|
|
247
|
+
throw inspectionFailure();
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
//#endregion
|
|
20
251
|
//#region src/help-style.ts
|
|
21
252
|
/**
|
|
22
253
|
* Shared Commander help style configuration.
|
|
@@ -81,6 +312,106 @@ function emitJsonError(errorCode, message, exitCode = 1) {
|
|
|
81
312
|
process.exitCode = exitCode;
|
|
82
313
|
}
|
|
83
314
|
//#endregion
|
|
315
|
+
//#region src/commands/capture.ts
|
|
316
|
+
var rejectedEventFormat = {
|
|
317
|
+
name: "opencode-raw-event-v1",
|
|
318
|
+
list: () => listRejectedRawEventSpoolEntries({ validation: "metadata" }),
|
|
319
|
+
inspect: (receipt) => inspectRejectedRawEventSpoolEntry({ receipt })
|
|
320
|
+
};
|
|
321
|
+
function safeJson(value) {
|
|
322
|
+
return JSON.stringify(value).replace(/[\u007f-\u009f\u2028-\u202e\u2066-\u2069]/g, (character) => `\\u${character.charCodeAt(0).toString(16).padStart(4, "0")}`);
|
|
323
|
+
}
|
|
324
|
+
function reportInspectionError(error, opts) {
|
|
325
|
+
let code = "inspection_failed";
|
|
326
|
+
let message = "Could not inspect retained events. Files were left untouched.";
|
|
327
|
+
if (error instanceof RawEventSpoolInspectionError) {
|
|
328
|
+
code = error.code;
|
|
329
|
+
message = error.message;
|
|
330
|
+
}
|
|
331
|
+
process.exitCode = code === "invalid_receipt" ? 2 : 1;
|
|
332
|
+
if (opts.json) {
|
|
333
|
+
process.stdout.write(`${safeJson({
|
|
334
|
+
error: code,
|
|
335
|
+
message
|
|
336
|
+
})}\n`);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
process.stderr.write(`${message}\n`);
|
|
340
|
+
}
|
|
341
|
+
function printRejectedMetadata(entry) {
|
|
342
|
+
process.stdout.write(`${entry.receipt}\t${entry.bytes} bytes\t${entry.status} ${entry.reason}\t${entry.validation}\n`);
|
|
343
|
+
}
|
|
344
|
+
function rawUnavailableMessage(validation) {
|
|
345
|
+
if (validation === "read_limit_exceeded") return "Raw event text exceeds the 16 MiB inspection limit. The file was left untouched.";
|
|
346
|
+
if (validation === "changed_during_read") return "The file changed while reading. Retry inspection. The file was left untouched.";
|
|
347
|
+
return "Raw event text failed validation. The file was left untouched.";
|
|
348
|
+
}
|
|
349
|
+
async function runListRejected(opts) {
|
|
350
|
+
try {
|
|
351
|
+
const entries = await rejectedEventFormat.list();
|
|
352
|
+
if (opts.json) {
|
|
353
|
+
process.stdout.write(`${safeJson({
|
|
354
|
+
format: rejectedEventFormat.name,
|
|
355
|
+
entries
|
|
356
|
+
})}\n`);
|
|
357
|
+
return;
|
|
358
|
+
}
|
|
359
|
+
if (!entries.length) {
|
|
360
|
+
process.stdout.write("No retained rejected events.\n");
|
|
361
|
+
return;
|
|
362
|
+
}
|
|
363
|
+
for (const entry of entries) printRejectedMetadata(entry);
|
|
364
|
+
} catch (error) {
|
|
365
|
+
reportInspectionError(error, opts);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
async function runShowRejected(receipt, opts) {
|
|
369
|
+
try {
|
|
370
|
+
const entry = await rejectedEventFormat.inspect(receipt);
|
|
371
|
+
const { receipt: name, bytes, status, reason, validation } = entry;
|
|
372
|
+
const result = {
|
|
373
|
+
format: rejectedEventFormat.name,
|
|
374
|
+
receipt: name,
|
|
375
|
+
bytes,
|
|
376
|
+
status,
|
|
377
|
+
reason,
|
|
378
|
+
validation
|
|
379
|
+
};
|
|
380
|
+
if (opts.raw && entry.validation === "valid") {
|
|
381
|
+
process.stdout.write(`${safeJson({
|
|
382
|
+
...result,
|
|
383
|
+
raw: entry.serialized
|
|
384
|
+
})}\n`);
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
if (opts.raw) {
|
|
388
|
+
const message = rawUnavailableMessage(entry.validation);
|
|
389
|
+
process.stdout.write(`${safeJson({
|
|
390
|
+
...result,
|
|
391
|
+
error: "raw_unavailable",
|
|
392
|
+
message
|
|
393
|
+
})}\n`);
|
|
394
|
+
process.exitCode = 1;
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
if (opts.json) {
|
|
398
|
+
process.stdout.write(`${safeJson(result)}\n`);
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
printRejectedMetadata(result);
|
|
402
|
+
} catch (error) {
|
|
403
|
+
reportInspectionError(error, { json: opts.json || opts.raw });
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
var captureCommand = new Command("capture").configureHelp(helpStyle).description("Inspect retained capture events");
|
|
407
|
+
var listRejectedCommand = new Command("list-rejected").configureHelp(helpStyle).description("List retained OpenCode rejections without reading payloads");
|
|
408
|
+
addJsonOption(listRejectedCommand);
|
|
409
|
+
listRejectedCommand.action(runListRejected);
|
|
410
|
+
var showRejectedCommand = new Command("show-rejected").configureHelp(helpStyle).description("Inspect one retained OpenCode rejection without modifying it").argument("<receipt>", "receipt from list-rejected").option("-r, --raw", "include private text as a JSON string (always output JSON)").addHelpText("after", "\n--raw also emits errors as JSON. If the file changes, retry inspection.\nFiles remain untouched.");
|
|
411
|
+
addJsonOption(showRejectedCommand);
|
|
412
|
+
showRejectedCommand.action(runShowRejected);
|
|
413
|
+
captureCommand.addCommand(listRejectedCommand).addCommand(showRejectedCommand);
|
|
414
|
+
//#endregion
|
|
84
415
|
//#region src/commands/claude-hook-file-context-transport.ts
|
|
85
416
|
/** Internal packaged-hook transport. Normal CLI invocation keeps its original guards/output. */
|
|
86
417
|
function runClaudeFileContextTransport(payload, opts) {
|
|
@@ -9741,6 +10072,15 @@ async function callMemoryToolForHost(store, name, args, caller) {
|
|
|
9741
10072
|
const { callCodememToolLocally } = await import("@codemem/mcp");
|
|
9742
10073
|
return callCodememToolLocally(store, name, args, caller);
|
|
9743
10074
|
}
|
|
10075
|
+
function foregroundAppOptions(store, rawEventOptions, options) {
|
|
10076
|
+
return {
|
|
10077
|
+
accountLink: options.accountLink.options,
|
|
10078
|
+
storeFactory: () => store,
|
|
10079
|
+
syncReachability: options.relay?.reachability,
|
|
10080
|
+
...rawEventOptions,
|
|
10081
|
+
getSyncRuntimeStatus: () => options.syncRuntimeStatus
|
|
10082
|
+
};
|
|
10083
|
+
}
|
|
9744
10084
|
function createBoundApp(createApp, options, listener) {
|
|
9745
10085
|
let boundAddress = null;
|
|
9746
10086
|
return {
|
|
@@ -9804,12 +10144,11 @@ async function startForegroundViewer(invocation) {
|
|
|
9804
10144
|
phase: syncEnabled ? "starting" : "disabled",
|
|
9805
10145
|
detail: syncEnabled ? "Waiting for viewer startup to finish" : "Sync is disabled"
|
|
9806
10146
|
};
|
|
9807
|
-
const appOpts = {
|
|
9808
|
-
accountLink
|
|
9809
|
-
|
|
9810
|
-
|
|
9811
|
-
|
|
9812
|
-
};
|
|
10147
|
+
const appOpts = foregroundAppOptions(store, rawEventProcessing.appOptions, {
|
|
10148
|
+
accountLink,
|
|
10149
|
+
relay,
|
|
10150
|
+
syncRuntimeStatus
|
|
10151
|
+
});
|
|
9813
10152
|
const { app, setBoundAddress } = createBoundApp(createApp, appOpts, {
|
|
9814
10153
|
invocation,
|
|
9815
10154
|
accountLink
|
|
@@ -13956,6 +14295,7 @@ var versionCommand = new Command("version").configureHelp(helpStyle).description
|
|
|
13956
14295
|
* until `registerRootCommands` is called.
|
|
13957
14296
|
*/
|
|
13958
14297
|
var ROOT_COMPLETION_COMMANDS = [
|
|
14298
|
+
"capture",
|
|
13959
14299
|
"config",
|
|
13960
14300
|
"coordinator",
|
|
13961
14301
|
"db",
|
|
@@ -14011,6 +14351,7 @@ function registerMemoryGroupWrappers() {
|
|
|
14011
14351
|
/** Register every root command (visible and hidden) on the given program. */
|
|
14012
14352
|
function registerRootCommands(program) {
|
|
14013
14353
|
registerMemoryGroupWrappers();
|
|
14354
|
+
program.addCommand(captureCommand);
|
|
14014
14355
|
program.addCommand(serveCommand);
|
|
14015
14356
|
program.addCommand(configCommand);
|
|
14016
14357
|
program.addCommand(coordinatorCommand);
|