@gmickel/gno 2.15.0 → 2.17.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 +1 -1
- package/assets/skill/SKILL.md +27 -0
- package/assets/skill/cli-reference.md +24 -15
- package/assets/spa-production.json.gz +0 -0
- package/browser-extension/artifacts/{gno-browser-clipper-v2.15.0.zip → gno-browser-clipper-v2.17.0.zip} +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.17.0.zip.sha256 +1 -0
- package/browser-extension/dist/manifest.json +1 -1
- package/package.json +1 -1
- package/spec/cli.md +43 -3
- package/spec/db/schema.sql +53 -1
- package/spec/mcp.md +9 -3
- package/spec/output-schemas/doctor.schema.json +27 -0
- package/spec/output-schemas/retrieval-trace-payloads.schema.json +14 -0
- package/spec/output-schemas/search-results.schema.json +14 -0
- package/spec/output-schemas/status.schema.json +22 -0
- package/src/cli/commands/agents/commands.ts +1 -1
- package/src/cli/commands/ask.ts +1 -1
- package/src/cli/commands/context-build.ts +1 -1
- package/src/cli/commands/doctor.ts +101 -29
- package/src/cli/commands/embed.ts +2 -2
- package/src/cli/commands/links.ts +30 -6
- package/src/cli/commands/mcp/install.ts +2 -2
- package/src/cli/commands/mcp/status.ts +1 -1
- package/src/cli/commands/mcp/uninstall.ts +1 -1
- package/src/cli/commands/query.ts +1 -1
- package/src/cli/commands/shared.ts +4 -4
- package/src/cli/commands/skill/install.ts +1 -1
- package/src/cli/commands/skill/paths-cmd.ts +1 -1
- package/src/cli/commands/skill/uninstall.ts +1 -1
- package/src/cli/commands/status.ts +75 -58
- package/src/cli/commands/vec.ts +180 -8
- package/src/cli/config-cache.ts +86 -0
- package/src/cli/globals.ts +64 -0
- package/src/cli/program.ts +63 -36
- package/src/cli/run.ts +121 -67
- package/src/cli/runtime-health.ts +132 -122
- package/src/cli/session-binding.ts +11 -2
- package/src/config/saver.ts +8 -0
- package/src/config/types.ts +6 -0
- package/src/converters/adapters/browser-export/formats.ts +25 -15
- package/src/converters/adapters/email/adapter.ts +37 -53
- package/src/converters/adapters/email/html.ts +37 -20
- package/src/converters/adapters/email/mime.ts +71 -39
- package/src/converters/adapters/ical/adapter.ts +20 -12
- package/src/converters/adapters/jsonl/adapter.ts +8 -6
- package/src/converters/adapters/shared/html-text.ts +55 -37
- package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
- package/src/converters/adapters/shared/utf8-lines.ts +69 -31
- package/src/converters/adapters/transcript/adapter.ts +12 -7
- package/src/converters/adapters/xlsx/adapter.ts +10 -7
- package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
- package/src/converters/canonicalize.ts +17 -3
- package/src/converters/native/markdown.ts +24 -17
- package/src/converters/native/plaintext.ts +5 -6
- package/src/converters/registry.ts +130 -8
- package/src/core/activation-status.ts +4 -8
- package/src/core/change-diff.ts +38 -11
- package/src/core/context-compiler.ts +17 -18
- package/src/core/context-evidence.ts +116 -25
- package/src/core/context-verifier.ts +70 -31
- package/src/core/file-lock.ts +10 -2
- package/src/core/graph-analysis.ts +3 -3
- package/src/core/link-inventory-markdown.ts +2 -2
- package/src/core/links.ts +20 -87
- package/src/core/memory-fence.ts +16 -9
- package/src/core/memory-recall.ts +168 -34
- package/src/core/path-rules.ts +143 -0
- package/src/core/retrieval-trace-session.ts +3 -0
- package/src/core/retrieval-trace.ts +9 -0
- package/src/core/section-parse.ts +16 -6
- package/src/core/typed-metadata.ts +68 -0
- package/src/core/vector-partition-status.ts +13 -0
- package/src/core/wiki-link-syntax.ts +88 -0
- package/src/embed/backlog.ts +142 -60
- package/src/embed/retry.ts +39 -33
- package/src/embed/variant-backlog.ts +582 -116
- package/src/embed/variant-retry.ts +157 -48
- package/src/index.ts +3 -3
- package/src/ingestion/budget-error-codes.ts +13 -0
- package/src/ingestion/chunker.ts +60 -49
- package/src/ingestion/compiled-context.ts +4 -5
- package/src/ingestion/convert-file.ts +1 -1
- package/src/ingestion/document-metadata.ts +16 -9
- package/src/ingestion/excluded-ranges.ts +97 -0
- package/src/ingestion/file-processor.ts +122 -37
- package/src/ingestion/frontmatter.ts +35 -7
- package/src/ingestion/graph-reconciliation.ts +187 -51
- package/src/ingestion/language.ts +66 -61
- package/src/ingestion/position.ts +5 -5
- package/src/ingestion/prepare-file.ts +50 -29
- package/src/ingestion/record-adapter-canonical.ts +37 -26
- package/src/ingestion/record-adapter.ts +46 -26
- package/src/ingestion/record-container.ts +121 -53
- package/src/ingestion/record-path.ts +5 -2
- package/src/ingestion/source-availability/darwin-io.ts +10 -7
- package/src/ingestion/source-availability/darwin-path.ts +21 -3
- package/src/ingestion/source-availability/readers.ts +51 -0
- package/src/ingestion/strip.ts +39 -105
- package/src/ingestion/sync.ts +692 -386
- package/src/ingestion/typed-metadata.ts +10 -4
- package/src/ingestion/walker.ts +485 -158
- package/src/llm/cache.ts +128 -84
- package/src/llm/http-inference.ts +112 -35
- package/src/llm/http-policy.ts +101 -0
- package/src/llm/httpEmbedding.ts +8 -1
- package/src/llm/httpGeneration.ts +5 -1
- package/src/llm/httpRerank.ts +5 -1
- package/src/llm/inference-scope.ts +15 -2
- package/src/llm/lazy-ports.ts +33 -3
- package/src/llm/lockfile.ts +34 -7
- package/src/llm/model-cleanup.ts +24 -0
- package/src/llm/native-worker/client.ts +23 -12
- package/src/llm/native-worker/dispatcher.ts +19 -9
- package/src/llm/native-worker/embedding-identity.ts +42 -16
- package/src/llm/native-worker/entry.ts +2 -1
- package/src/llm/native-worker/owner.ts +1 -0
- package/src/llm/native-worker/ports.ts +86 -23
- package/src/llm/native-worker/protocol.ts +386 -55
- package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
- package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
- package/src/llm/nodeLlamaCpp/generation.ts +194 -30
- package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
- package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
- package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
- package/src/llm/types.ts +14 -0
- package/src/mcp/context.ts +342 -23
- package/src/mcp/http-transport.ts +21 -3
- package/src/mcp/tool-profile-types.ts +62 -0
- package/src/mcp/tool-profile.ts +32 -56
- package/src/mcp/tools/context.ts +5 -1
- package/src/mcp/tools/index.ts +269 -191
- package/src/mcp/tools/links.ts +14 -6
- package/src/mcp/tools/query.ts +60 -37
- package/src/mcp/tools/vsearch.ts +25 -14
- package/src/pipeline/answer.ts +133 -40
- package/src/pipeline/claim-verification.ts +293 -189
- package/src/pipeline/claim-verifier.ts +6 -7
- package/src/pipeline/egress-lineage.ts +37 -26
- package/src/pipeline/exclude.ts +34 -11
- package/src/pipeline/expansion.ts +233 -19
- package/src/pipeline/explain.ts +17 -2
- package/src/pipeline/filters.ts +169 -33
- package/src/pipeline/graph-retrieval.ts +117 -61
- package/src/pipeline/hybrid.ts +626 -330
- package/src/pipeline/hydration.ts +86 -24
- package/src/pipeline/intent.ts +15 -7
- package/src/pipeline/owner-fusion.ts +61 -19
- package/src/pipeline/query-language.ts +15 -2
- package/src/pipeline/rerank.ts +15 -22
- package/src/pipeline/search.ts +193 -72
- package/src/pipeline/snippet.ts +15 -2
- package/src/pipeline/temporal.ts +51 -10
- package/src/pipeline/types.ts +7 -0
- package/src/pipeline/vsearch.ts +269 -154
- package/src/publish/attachment-raster.ts +2 -16
- package/src/publish/encrypted-export.ts +15 -5
- package/src/serve/browse-tree.ts +50 -42
- package/src/serve/connectors.ts +2 -1
- package/src/serve/context.ts +13 -4
- package/src/serve/doc-events.ts +3 -0
- package/src/serve/public/app.tsx +49 -21
- package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
- package/src/serve/public/components/CaptureModal.tsx +14 -10
- package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
- package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
- package/src/serve/public/globals.built.css +1 -1
- package/src/serve/public/globals.css +19 -0
- package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
- package/src/serve/public/lib/metadata-filter.ts +234 -9
- package/src/serve/public/pages/Browse.tsx +61 -27
- package/src/serve/public/pages/DocView.tsx +44 -25
- package/src/serve/public/pages/GraphView.tsx +8 -3
- package/src/serve/resident-runtime.ts +199 -48
- package/src/serve/routes/api.ts +98 -67
- package/src/serve/routes/links.ts +25 -5
- package/src/serve/server.ts +1370 -1180
- package/src/serve/spa-bundle-source.ts +52 -27
- package/src/serve/status.ts +101 -52
- package/src/serve/watch-reconciliation-fallback.ts +11 -7
- package/src/serve/watch-reconciliation-shared.ts +42 -4
- package/src/serve/watch-reconciliation.ts +21 -8
- package/src/serve/watch-service-events.ts +7 -1
- package/src/serve/watch-service-hosts.ts +3 -1
- package/src/serve/watch-service.ts +46 -21
- package/src/serve/watch-snapshot-scan.ts +6 -15
- package/src/sessions/archive.ts +20 -8
- package/src/sessions/sanitize.ts +38 -18
- package/src/sessions/service.ts +180 -102
- package/src/store/migrations/037-performance-indexes.ts +56 -0
- package/src/store/migrations/038-vector-mirror-null-cosine.ts +47 -0
- package/src/store/migrations/039-vector-mirror-v2.ts +94 -0
- package/src/store/migrations/index.ts +6 -0
- package/src/store/sqlite/adapter.ts +1260 -651
- package/src/store/sqlite/chunking-policy.ts +15 -1
- package/src/store/sqlite/eligibility.ts +110 -70
- package/src/store/sqlite/graph-neighbors.ts +71 -46
- package/src/store/sqlite/graph-reference-state.ts +27 -3
- package/src/store/sqlite/graph-similarity.ts +59 -12
- package/src/store/sqlite/metadata-predicate.ts +123 -28
- package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
- package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
- package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
- package/src/store/types.ts +32 -0
- package/src/store/vector/coarse-router.ts +312 -0
- package/src/store/vector/eligibility.ts +39 -0
- package/src/store/vector/lazy.ts +17 -0
- package/src/store/vector/partition-index.ts +333 -59
- package/src/store/vector/proof-cache.ts +209 -0
- package/src/store/vector/runtime-compat.ts +6 -0
- package/src/store/vector/sqlite-vec.ts +270 -162
- package/src/store/vector/stats.ts +37 -73
- package/src/store/vector/status.ts +169 -53
- package/src/store/vector/stored-vectors.ts +131 -45
- package/src/store/vector/types.ts +19 -0
- package/src/store/vector/v2-mirror.ts +669 -0
- package/src/store/vector/variant-search.ts +1187 -111
- package/src/store/vector/variants.ts +964 -160
- package/browser-extension/artifacts/gno-browser-clipper-v2.15.0.zip.sha256 +0 -1
|
@@ -11,11 +11,20 @@ import { watch, type FSWatcher } from "node:fs";
|
|
|
11
11
|
import { normalize, sep } from "node:path";
|
|
12
12
|
|
|
13
13
|
import type { Collection } from "../config/types";
|
|
14
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
CollectionSyncResult,
|
|
16
|
+
SyncOptions,
|
|
17
|
+
WalkConfig,
|
|
18
|
+
} from "../ingestion";
|
|
15
19
|
import type { SqliteAdapter } from "../store/sqlite/adapter";
|
|
16
20
|
import type { DocumentEvent, DocumentEventBus } from "./doc-events";
|
|
17
21
|
import type { EmbedScheduler } from "./embed-scheduler";
|
|
18
|
-
import type {
|
|
22
|
+
import type {
|
|
23
|
+
WatchEventHost,
|
|
24
|
+
WatchQueueHost,
|
|
25
|
+
WatcherRetryKind,
|
|
26
|
+
} from "./watch-service-events";
|
|
27
|
+
import type { WatchLifecycleHost } from "./watch-service-lifecycle";
|
|
19
28
|
import type {
|
|
20
29
|
WatcherSnapshot,
|
|
21
30
|
WatcherSnapshotBuildResult,
|
|
@@ -23,6 +32,7 @@ import type {
|
|
|
23
32
|
WatcherSnapshotOptions,
|
|
24
33
|
} from "./watch-snapshot";
|
|
25
34
|
|
|
35
|
+
import { collectionToWalkConfig } from "../ingestion";
|
|
26
36
|
import {
|
|
27
37
|
WATCHER_MAX_DIRTY_HINTS,
|
|
28
38
|
WATCHER_MAX_EXACT_PATHS,
|
|
@@ -163,6 +173,11 @@ export class CollectionWatchService {
|
|
|
163
173
|
readonly #snapshotEntryCeiling: number | undefined;
|
|
164
174
|
readonly #acquireWriteLease: CollectionWatchServiceOptions["acquireWriteLease"];
|
|
165
175
|
readonly #reconcileOnStart: boolean;
|
|
176
|
+
readonly #walkConfigs = new Map<string, WalkConfig>();
|
|
177
|
+
readonly #hostStateObj: WatchServiceHostState;
|
|
178
|
+
readonly #eventHost: WatchEventHost;
|
|
179
|
+
readonly #queueHost: WatchQueueHost;
|
|
180
|
+
readonly #lifecycleHost: WatchLifecycleHost;
|
|
166
181
|
#nextCollectionGeneration = 0;
|
|
167
182
|
#disposed = false;
|
|
168
183
|
#lastEventAt: string | null = null;
|
|
@@ -188,6 +203,21 @@ export class CollectionWatchService {
|
|
|
188
203
|
this.#snapshotEntryCeiling = options.snapshotEntryCeiling;
|
|
189
204
|
this.#acquireWriteLease = options.acquireWriteLease;
|
|
190
205
|
this.#reconcileOnStart = options.reconcileOnStart ?? false;
|
|
206
|
+
this.#rebuildWalkConfigs(options.collections);
|
|
207
|
+
this.#hostStateObj = this.#createHostState();
|
|
208
|
+
this.#eventHost = buildEventHost(this.#hostStateObj);
|
|
209
|
+
this.#queueHost = buildQueueHost(this.#hostStateObj);
|
|
210
|
+
this.#lifecycleHost = buildLifecycleHost(this.#hostStateObj);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
#rebuildWalkConfigs(collections: readonly Collection[]): void {
|
|
214
|
+
this.#walkConfigs.clear();
|
|
215
|
+
for (const collection of collections) {
|
|
216
|
+
this.#walkConfigs.set(
|
|
217
|
+
collection.name,
|
|
218
|
+
collectionToWalkConfig(collection, 0)
|
|
219
|
+
);
|
|
220
|
+
}
|
|
191
221
|
}
|
|
192
222
|
|
|
193
223
|
start(): void {
|
|
@@ -212,11 +242,7 @@ export class CollectionWatchService {
|
|
|
212
242
|
collections: Collection[],
|
|
213
243
|
syncOptions?: SyncOptions
|
|
214
244
|
): void {
|
|
215
|
-
applyCollectionUpdate(
|
|
216
|
-
buildLifecycleHost(this.#hostState()),
|
|
217
|
-
collections,
|
|
218
|
-
syncOptions
|
|
219
|
-
);
|
|
245
|
+
applyCollectionUpdate(this.#lifecycleHost, collections, syncOptions);
|
|
220
246
|
}
|
|
221
247
|
|
|
222
248
|
suppress(absPath: string, ms = 5_000): void {
|
|
@@ -250,6 +276,7 @@ export class CollectionWatchService {
|
|
|
250
276
|
this.#collectionGenerations.clear();
|
|
251
277
|
this.#collectionFingerprints.clear();
|
|
252
278
|
this.#collections = [];
|
|
279
|
+
this.#walkConfigs.clear();
|
|
253
280
|
this.#pendingByCollection.clear();
|
|
254
281
|
this.#snapshots.clear();
|
|
255
282
|
this.#snapshotReady.clear();
|
|
@@ -275,12 +302,13 @@ export class CollectionWatchService {
|
|
|
275
302
|
};
|
|
276
303
|
}
|
|
277
304
|
|
|
278
|
-
#
|
|
305
|
+
#createHostState(): WatchServiceHostState {
|
|
279
306
|
return {
|
|
280
307
|
disposed: () => this.#disposed,
|
|
281
308
|
getCollections: () => this.#collections,
|
|
282
309
|
setCollections: (collections) => {
|
|
283
310
|
this.#collections = collections;
|
|
311
|
+
this.#rebuildWalkConfigs(collections);
|
|
284
312
|
},
|
|
285
313
|
getSyncOptions: () => this.#syncOptions,
|
|
286
314
|
setSyncOptions: (syncOptions) => {
|
|
@@ -305,25 +333,21 @@ export class CollectionWatchService {
|
|
|
305
333
|
},
|
|
306
334
|
watchFactory: this.#watchFactory,
|
|
307
335
|
onWatchEvent: (name, root, filename) => {
|
|
308
|
-
handleWatchEvent(
|
|
309
|
-
buildEventHost(this.#hostState()),
|
|
310
|
-
name,
|
|
311
|
-
root,
|
|
312
|
-
filename
|
|
313
|
-
);
|
|
336
|
+
handleWatchEvent(this.#eventHost, name, root, filename);
|
|
314
337
|
},
|
|
315
338
|
findCollection: (name) =>
|
|
316
339
|
this.#collections.find((entry) => entry.name === name),
|
|
340
|
+
getWalkConfig: (name) => this.#walkConfigs.get(name),
|
|
317
341
|
clock: this.#clock,
|
|
318
342
|
suppressedPaths: this.#suppressedPaths,
|
|
319
343
|
setLastEventAt: (iso) => {
|
|
320
344
|
this.#lastEventAt = iso;
|
|
321
345
|
},
|
|
322
346
|
enqueueExact: (name, relPath) => {
|
|
323
|
-
enqueueExactPath(
|
|
347
|
+
enqueueExactPath(this.#queueHost, name, relPath);
|
|
324
348
|
},
|
|
325
349
|
enqueueDirty: (name, hint) => {
|
|
326
|
-
enqueueDirtyHint(
|
|
350
|
+
enqueueDirtyHint(this.#queueHost, name, hint);
|
|
327
351
|
},
|
|
328
352
|
flushDebounceMs: this.#flushDebounceMs,
|
|
329
353
|
maxFlushDelayMs: this.#maxFlushDelayMs,
|
|
@@ -381,7 +405,7 @@ export class CollectionWatchService {
|
|
|
381
405
|
},
|
|
382
406
|
onReadyWithPending: (name) => {
|
|
383
407
|
if (pendingHasWork(this.#pendingByCollection.get(name))) {
|
|
384
|
-
scheduleFlush(
|
|
408
|
+
scheduleFlush(this.#queueHost, name);
|
|
385
409
|
}
|
|
386
410
|
},
|
|
387
411
|
getSyncOptions: () => this.#syncOptions,
|
|
@@ -408,7 +432,7 @@ export class CollectionWatchService {
|
|
|
408
432
|
snapshotInit: this.#snapshotInit,
|
|
409
433
|
suppressedPaths: this.#suppressedPaths,
|
|
410
434
|
clock: this.#clock,
|
|
411
|
-
queueHost:
|
|
435
|
+
queueHost: this.#queueHost,
|
|
412
436
|
callbacks: this.#callbacks,
|
|
413
437
|
onAfterSync: (current, relPaths) => {
|
|
414
438
|
this.#afterSync(current, relPaths);
|
|
@@ -417,7 +441,7 @@ export class CollectionWatchService {
|
|
|
417
441
|
this.#beginSnapshotInit(current);
|
|
418
442
|
},
|
|
419
443
|
clearLifecycleTombstones: (name) => {
|
|
420
|
-
clearLifecycleTombstones(
|
|
444
|
+
clearLifecycleTombstones(this.#lifecycleHost, name);
|
|
421
445
|
},
|
|
422
446
|
pruneSuppression: () => {
|
|
423
447
|
pruneSuppressionMap(
|
|
@@ -450,7 +474,8 @@ export class CollectionWatchService {
|
|
|
450
474
|
if (this.#disposed || relPaths.length === 0) {
|
|
451
475
|
return;
|
|
452
476
|
}
|
|
453
|
-
|
|
477
|
+
const changedAt = new Date(this.#clock()).toISOString();
|
|
478
|
+
this.#lastSyncAt = changedAt;
|
|
454
479
|
this.#scheduler?.notifySyncComplete(relPaths);
|
|
455
480
|
if (!this.#eventBus) {
|
|
456
481
|
return;
|
|
@@ -462,7 +487,7 @@ export class CollectionWatchService {
|
|
|
462
487
|
collection: collection.name,
|
|
463
488
|
relPath,
|
|
464
489
|
origin: "watcher",
|
|
465
|
-
changedAt
|
|
490
|
+
changedAt,
|
|
466
491
|
};
|
|
467
492
|
this.#eventBus.emit(event);
|
|
468
493
|
}
|
|
@@ -33,7 +33,7 @@ export const defaultFs: WatcherSnapshotFs = createDefaultWatcherFs();
|
|
|
33
33
|
|
|
34
34
|
/** Mutable hierarchical maps with incremental entry accounting. */
|
|
35
35
|
export interface MutableSnapshotMaps {
|
|
36
|
-
directories: Map<string,
|
|
36
|
+
directories: Map<string, ReadonlyMap<string, SnapshotEntryFingerprint>>;
|
|
37
37
|
entryCount: number;
|
|
38
38
|
unprovenSubtrees: Set<string>;
|
|
39
39
|
}
|
|
@@ -41,27 +41,18 @@ export interface MutableSnapshotMaps {
|
|
|
41
41
|
export function cloneDirectoryMaps(
|
|
42
42
|
source: WatcherSnapshot
|
|
43
43
|
): MutableSnapshotMaps {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
directories.set(dir, new Map(entries));
|
|
47
|
-
}
|
|
44
|
+
// Inner directory maps are immutable ReadonlyMaps replaced whole by
|
|
45
|
+
// setDirectoryEntries, so shallow-copying the outer map is O(total_dirs).
|
|
48
46
|
return {
|
|
49
|
-
directories,
|
|
47
|
+
directories: new Map(source.directories),
|
|
50
48
|
entryCount: source.entryCount,
|
|
51
49
|
unprovenSubtrees: new Set(source.unprovenSubtrees ?? []),
|
|
52
50
|
};
|
|
53
51
|
}
|
|
54
52
|
|
|
55
53
|
export function freezeSnapshot(state: MutableSnapshotMaps): WatcherSnapshot {
|
|
56
|
-
const frozen = new Map<
|
|
57
|
-
string,
|
|
58
|
-
ReadonlyMap<string, SnapshotEntryFingerprint>
|
|
59
|
-
>();
|
|
60
|
-
for (const [dir, entries] of state.directories) {
|
|
61
|
-
frozen.set(dir, entries);
|
|
62
|
-
}
|
|
63
54
|
return {
|
|
64
|
-
directories:
|
|
55
|
+
directories: state.directories,
|
|
65
56
|
entryCount: state.entryCount,
|
|
66
57
|
unprovenSubtrees: new Set(state.unprovenSubtrees),
|
|
67
58
|
};
|
|
@@ -71,7 +62,7 @@ export function freezeSnapshot(state: MutableSnapshotMaps): WatcherSnapshot {
|
|
|
71
62
|
export function setDirectoryEntries(
|
|
72
63
|
state: MutableSnapshotMaps,
|
|
73
64
|
dirRel: string,
|
|
74
|
-
entries:
|
|
65
|
+
entries: ReadonlyMap<string, SnapshotEntryFingerprint>
|
|
75
66
|
): void {
|
|
76
67
|
const previous = state.directories.get(dirRel);
|
|
77
68
|
const previousSize = previous?.size ?? 0;
|
package/src/sessions/archive.ts
CHANGED
|
@@ -149,9 +149,16 @@ export function renderThread(options: {
|
|
|
149
149
|
unitLocator: string;
|
|
150
150
|
parser: string;
|
|
151
151
|
redaction: RedactionPolicy;
|
|
152
|
+
sanitizer?: ThreadSanitizer;
|
|
152
153
|
}): RenderedThread {
|
|
153
154
|
const { thread, sourceId, parser } = options;
|
|
154
|
-
|
|
155
|
+
let sanitizer: ThreadSanitizer;
|
|
156
|
+
if (options.sanitizer) {
|
|
157
|
+
sanitizer = options.sanitizer;
|
|
158
|
+
sanitizer.reset();
|
|
159
|
+
} else {
|
|
160
|
+
sanitizer = new ThreadSanitizer(options.redaction);
|
|
161
|
+
}
|
|
155
162
|
const project = projectIdentity(thread.cwd);
|
|
156
163
|
// Pass 1 detects secrets in every persisted field; pass 2 (`clean`)
|
|
157
164
|
// propagates values found anywhere in the thread into every field, so a
|
|
@@ -171,7 +178,9 @@ export function renderThread(options: {
|
|
|
171
178
|
turnId: sanitizer.sanitize(turn.turnId),
|
|
172
179
|
locator: sanitizer.sanitize(turn.locator),
|
|
173
180
|
}));
|
|
174
|
-
const
|
|
181
|
+
const needsPropagation = sanitizer.detectedCount > 0;
|
|
182
|
+
const clean = (value: string): string =>
|
|
183
|
+
needsPropagation ? sanitizer.propagate(value) : value;
|
|
175
184
|
const projectLabel = raw.project === null ? null : clean(raw.project);
|
|
176
185
|
const harnessLabel = SESSION_HARNESS_LABELS[thread.harness];
|
|
177
186
|
const sessionId = `${thread.harness}/${sourceId}/${clean(raw.sessionId)}`;
|
|
@@ -192,12 +201,15 @@ export function renderThread(options: {
|
|
|
192
201
|
categories.push(`project-id/${project.id}`);
|
|
193
202
|
}
|
|
194
203
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
204
|
+
// Skip pass-2 drafts allocation when no secrets were detected in pass 1.
|
|
205
|
+
const drafts = needsPropagation
|
|
206
|
+
? rawDrafts.map((draft) => ({
|
|
207
|
+
turn: draft.turn,
|
|
208
|
+
text: clean(draft.text),
|
|
209
|
+
turnId: clean(draft.turnId),
|
|
210
|
+
locator: clean(draft.locator),
|
|
211
|
+
}))
|
|
212
|
+
: rawDrafts;
|
|
201
213
|
|
|
202
214
|
const lines: string[] = [];
|
|
203
215
|
let bytes = 0;
|
package/src/sessions/sanitize.ts
CHANGED
|
@@ -90,6 +90,12 @@ const RULES: readonly Rule[] = [
|
|
|
90
90
|
},
|
|
91
91
|
];
|
|
92
92
|
|
|
93
|
+
// Single fast-reject prefilter covering the exact prefix/trigger of every rule
|
|
94
|
+
// in RULES. Clean turns (no trigger substring) skip all 10 per-rule regex scans
|
|
95
|
+
// with zero false negatives.
|
|
96
|
+
const RULES_PREFILTER =
|
|
97
|
+
/\b(?:AKIA|ASIA|gh[pousr]_|github_pat_|sk-|sk_live_|sk_test_|rk_live_|rk_test_|pk_live_|pk_test_|xox[abposr]-|AIza|eyJ|Bearer[ \t]|Token[ \t])|:\/\/[^\s@]{1,513}@|\b(?:password|passwd|pwd|secret|api[_-]?key|apikey|access[_-]?token|auth[_-]?token|refresh[_-]?token|client[_-]?secret|private[_-]?key|token)["']?[ \t]{0,4}[:=]/i;
|
|
98
|
+
|
|
93
99
|
const CONTROL_CHARS = new RegExp(
|
|
94
100
|
`[${String.fromCharCode(0)}-${String.fromCharCode(8)}${String.fromCharCode(11)}${String.fromCharCode(12)}${String.fromCharCode(14)}-${String.fromCharCode(31)}${String.fromCharCode(127)}]`,
|
|
95
101
|
"g"
|
|
@@ -117,7 +123,7 @@ export interface RedactionPolicy {
|
|
|
117
123
|
* the same thread redact them even out of their original shape.
|
|
118
124
|
*/
|
|
119
125
|
export class ThreadSanitizer {
|
|
120
|
-
private readonly literals: string[];
|
|
126
|
+
private readonly literals: readonly string[];
|
|
121
127
|
private readonly detected = new Set<string>();
|
|
122
128
|
redactions = 0;
|
|
123
129
|
|
|
@@ -127,6 +133,17 @@ export class ThreadSanitizer {
|
|
|
127
133
|
.sort((left, right) => right.length - left.length);
|
|
128
134
|
}
|
|
129
135
|
|
|
136
|
+
/** Reset per-thread state so one sanitizer instance can be reused across units. */
|
|
137
|
+
reset(): void {
|
|
138
|
+
this.detected.clear();
|
|
139
|
+
this.redactions = 0;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Number of detected secret values to propagate (O(1), zero allocation). */
|
|
143
|
+
get detectedCount(): number {
|
|
144
|
+
return this.detected.size;
|
|
145
|
+
}
|
|
146
|
+
|
|
130
147
|
/** Values detected so far (bounded); used for the propagation pass. */
|
|
131
148
|
get detectedValues(): readonly string[] {
|
|
132
149
|
return [...this.detected];
|
|
@@ -175,24 +192,26 @@ export class ThreadSanitizer {
|
|
|
175
192
|
sanitize(input: string): string {
|
|
176
193
|
let text = input.replace(CONTROL_CHARS, "");
|
|
177
194
|
text = this.redactPrivateKeys(text);
|
|
178
|
-
|
|
179
|
-
rule
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
195
|
+
if (RULES_PREFILTER.test(text)) {
|
|
196
|
+
for (const rule of RULES) {
|
|
197
|
+
rule.pattern.lastIndex = 0;
|
|
198
|
+
text = text.replace(
|
|
199
|
+
rule.pattern,
|
|
200
|
+
(match: string, ...groups: unknown[]) => {
|
|
201
|
+
const secret =
|
|
202
|
+
rule.group === 0 ? match : (groups[rule.group - 1] as string);
|
|
203
|
+
if (!secret || PLACEHOLDER_VALUES.has(secret.toLowerCase())) {
|
|
204
|
+
return match;
|
|
205
|
+
}
|
|
206
|
+
if (secret.startsWith("[REDACTED:")) return match;
|
|
207
|
+
this.remember(secret);
|
|
208
|
+
this.redactions += 1;
|
|
209
|
+
return rule.group === 0
|
|
210
|
+
? marker(rule.kind)
|
|
211
|
+
: match.replace(secret, marker(rule.kind));
|
|
187
212
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
this.redactions += 1;
|
|
191
|
-
return rule.group === 0
|
|
192
|
-
? marker(rule.kind)
|
|
193
|
-
: match.replace(secret, marker(rule.kind));
|
|
194
|
-
}
|
|
195
|
-
);
|
|
213
|
+
);
|
|
214
|
+
}
|
|
196
215
|
}
|
|
197
216
|
for (const literal of this.literals) {
|
|
198
217
|
text = this.replaceLiteral(text, literal, "configured");
|
|
@@ -205,6 +224,7 @@ export class ThreadSanitizer {
|
|
|
205
224
|
* whole thread after the first pass so earlier turns are covered too.
|
|
206
225
|
*/
|
|
207
226
|
propagate(text: string): string {
|
|
227
|
+
if (this.detected.size === 0) return text;
|
|
208
228
|
let output = text;
|
|
209
229
|
for (const value of this.detected) {
|
|
210
230
|
output = this.replaceLiteral(output, value, "propagated");
|