@wrongstack/core 0.306.3 → 0.307.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.
Files changed (114) hide show
  1. package/dist/chronicle/index.js +957 -953
  2. package/dist/chronicle/metrics-ingest.d.ts +55 -0
  3. package/dist/chronicle/metrics-schema.d.ts +86 -0
  4. package/dist/chronicle/metrics-store.d.ts +5 -120
  5. package/dist/chronicle/project-server.js +1083 -1084
  6. package/dist/chronicle/sqlite-journal-quota.d.ts +39 -0
  7. package/dist/chronicle/sqlite-journal-schema.d.ts +25 -0
  8. package/dist/chronicle/sqlite-journal.d.ts +12 -177
  9. package/dist/coordination/agents/index.js +1738 -1690
  10. package/dist/coordination/agents/project-agent-capture.d.ts +48 -0
  11. package/dist/coordination/agents/project-agent-identity.d.ts +3 -129
  12. package/dist/coordination/agents/project-agent-roster.d.ts +17 -0
  13. package/dist/coordination/index.js +6103 -5890
  14. package/dist/coordination/mailbox-http-actor-query.d.ts +16 -0
  15. package/dist/coordination/mailbox-http-router.d.ts +0 -48
  16. package/dist/coordination/mailbox-http-sse.d.ts +12 -0
  17. package/dist/coordination/mailbox-message-types.d.ts +71 -0
  18. package/dist/coordination/mailbox-predicates.d.ts +13 -0
  19. package/dist/coordination/mailbox-project-server.js +1 -1
  20. package/dist/coordination/mailbox-session-sync.d.ts +8 -0
  21. package/dist/coordination/mailbox-types.d.ts +6 -793
  22. package/dist/core/agent-loop-context.d.ts +28 -0
  23. package/dist/core/agent-loop-detector.d.ts +25 -0
  24. package/dist/core/conversation-state.d.ts +1 -2
  25. package/dist/core/fallback-doctor.d.ts +72 -0
  26. package/dist/core/fallback-model.d.ts +19 -1
  27. package/dist/core/fallback-profile-manager.d.ts +21 -3
  28. package/dist/core/index.d.ts +2 -1
  29. package/dist/core/index.js +1143 -766
  30. package/dist/defaults/index.js +3833 -3595
  31. package/dist/execution/auto-compaction-middleware.d.ts +64 -0
  32. package/dist/execution/autonomy-brain-llm.d.ts +55 -0
  33. package/dist/execution/autonomy-brain.d.ts +3 -156
  34. package/dist/execution/compaction-budget.d.ts +38 -0
  35. package/dist/execution/compaction-core.d.ts +3 -166
  36. package/dist/execution/compaction-elision.d.ts +58 -0
  37. package/dist/execution/council-orchestrator-helpers.d.ts +39 -0
  38. package/dist/execution/council-orchestrator.d.ts +3 -42
  39. package/dist/execution/council-response-parser.d.ts +56 -0
  40. package/dist/execution/index.d.ts +1 -1
  41. package/dist/execution/index.js +10016 -9903
  42. package/dist/execution/prompt-enhancer.js +11 -3
  43. package/dist/execution/retry-policy.d.ts +27 -0
  44. package/dist/execution/tool-executor-guard.d.ts +18 -0
  45. package/dist/execution/tool-executor-runner.d.ts +12 -0
  46. package/dist/execution/tool-executor.d.ts +0 -75
  47. package/dist/goal/index.js +19 -6
  48. package/dist/hq/index.js +58 -17
  49. package/dist/index.d.ts +2 -1
  50. package/dist/index.js +8731 -7756
  51. package/dist/infrastructure/index.js +24 -1
  52. package/dist/kernel/events/agent-events.d.ts +2 -0
  53. package/dist/kernel/events/provider-events.d.ts +13 -0
  54. package/dist/plugin/index.js +2123 -1918
  55. package/dist/plugins/auto-review-config.d.ts +53 -0
  56. package/dist/plugins/auto-review-git.d.ts +19 -0
  57. package/dist/plugins/auto-review-plugin.d.ts +2 -140
  58. package/dist/plugins/review-finding-verification.d.ts +7 -0
  59. package/dist/prompts/index.d.ts +1 -0
  60. package/dist/prompts/prompt-journal.d.ts +94 -0
  61. package/dist/security/index.js +677 -667
  62. package/dist/security/permission-explain.d.ts +19 -0
  63. package/dist/security/permission-policy.d.ts +0 -101
  64. package/dist/security/yolo-risk.d.ts +5 -4
  65. package/dist/session-catalog/index.js +270 -227
  66. package/dist/session-catalog/project-server.js +277 -234
  67. package/dist/session-catalog/store-rebuild.d.ts +9 -0
  68. package/dist/session-catalog/store-schema.d.ts +48 -0
  69. package/dist/session-catalog/store.d.ts +0 -17
  70. package/dist/storage/cloud-config-sync/sanitize.d.ts +18 -0
  71. package/dist/storage/cloud-config-sync.d.ts +1 -1
  72. package/dist/storage/director-state.d.ts +6 -0
  73. package/dist/storage/file-session-writer.d.ts +2 -58
  74. package/dist/storage/index.d.ts +2 -1
  75. package/dist/storage/index.js +2121 -1736
  76. package/dist/storage/orphan-lock-cleaner.d.ts +15 -0
  77. package/dist/storage/provider-config-watcher.d.ts +9 -0
  78. package/dist/storage/session-recovery.d.ts +9 -0
  79. package/dist/storage/session-store/rename-session.d.ts +16 -0
  80. package/dist/storage/session-store/resume-session.d.ts +26 -0
  81. package/dist/storage/session-store/session-store-clear.d.ts +11 -0
  82. package/dist/storage/session-store/session-store-index.d.ts +13 -0
  83. package/dist/storage/session-store/strict-empty-check.d.ts +7 -0
  84. package/dist/storage/session-store.d.ts +2 -129
  85. package/dist/storage/session-summary-tracker.d.ts +39 -0
  86. package/dist/storage/session-write-buffer.d.ts +43 -0
  87. package/dist/storage/session-writer/session-writer-flush.d.ts +4 -0
  88. package/dist/storage/session-writer/session-writer-summary-tracker.d.ts +28 -0
  89. package/dist/tools/fallback-agent-model-assign-tool.d.ts +18 -0
  90. package/dist/tools/fallback-leader-model-set-tool.d.ts +18 -0
  91. package/dist/tools/fallback-manage-tools.d.ts +8 -45
  92. package/dist/tools/fallback-profile-manage-tool.d.ts +16 -0
  93. package/dist/tools/fallback-provider-key-set-tool.d.ts +17 -0
  94. package/dist/tools/fallback-provider-manage-tool.d.ts +26 -0
  95. package/dist/tools/index.d.ts +1 -1
  96. package/dist/tools/index.js +5150 -5090
  97. package/dist/types/config/root.d.ts +21 -2
  98. package/dist/types/default-config.d.ts +1 -1
  99. package/dist/types/index.d.ts +54 -55
  100. package/dist/types/index.js +953 -932
  101. package/dist/types/runtime-capability-manifest.d.ts +5 -5
  102. package/dist/types/session-markers.d.ts +12 -0
  103. package/dist/types/session-markers.js +19 -0
  104. package/dist/types/session.d.ts +7 -0
  105. package/dist/worktree/worktree-manager.d.ts +1 -1
  106. package/instructions/coordination/subagent-baseline.md +2 -2
  107. package/instructions/llm/prompt-enhancer.md +2 -1
  108. package/instructions/sections/tool/common-patterns.md +21 -0
  109. package/instructions/sections/tool/delegation-compact.md +3 -1
  110. package/instructions/sections/tool/delegation-full.md +5 -1
  111. package/instructions/system-lite.md +28 -3
  112. package/instructions/system-pro.md +37 -8
  113. package/instructions/system.md +4 -2
  114. package/package.json +5 -5
@@ -0,0 +1,9 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ import type { SessionSummary } from '../types/session.js';
3
+ export declare function walkSessionFiles(root: string, suffix: string): string[];
4
+ export declare function summarizeTranscriptFile(transcriptFilePath: string, id: string): SessionSummary;
5
+ export declare function rebuildCatalogIndex(db: DatabaseSync, sessionsDir: string, containedPathFn: (relative: string) => string, transactionFn: <T>(run: () => T) => T, bumpGenerationFn: () => number): {
6
+ indexed: number;
7
+ damaged: number;
8
+ };
9
+ //# sourceMappingURL=store-rebuild.d.ts.map
@@ -0,0 +1,48 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ import type { SessionRegistryEntry } from '../session-registry-types.js';
3
+ export declare const SCHEMA_VERSION = 1;
4
+ export declare const MAX_LEASE_MS = 120000;
5
+ export declare const MAX_RESERVATION_MS = 60000;
6
+ export declare const MAX_MAINTENANCE_MS: number;
7
+ export declare const MAX_PAGE = 1000;
8
+ export interface LeaseRow {
9
+ session_id: string;
10
+ lease_id: string;
11
+ lease_secret_hash: string;
12
+ owner_instance_id: string;
13
+ owner_pid: number;
14
+ owner_started_at: string;
15
+ entry_json: string;
16
+ agent_revision: number;
17
+ status: SessionRegistryEntry['status'];
18
+ last_heartbeat_at: number;
19
+ lease_expires_at: number;
20
+ }
21
+ export interface ReservationRow {
22
+ reservation_id: string;
23
+ target_session_id: string;
24
+ requester_instance_id: string;
25
+ current_session_id: string | null;
26
+ expires_at: number;
27
+ }
28
+ export interface CatalogRow {
29
+ session_id: string;
30
+ transcript_relative_path: string;
31
+ summary_relative_path: string;
32
+ summary_json: string;
33
+ transcript_size: number;
34
+ transcript_mtime_ms: number;
35
+ summary_revision: number;
36
+ indexed_at: string;
37
+ damaged: number;
38
+ }
39
+ export declare function hashSecret(secret: string): string;
40
+ export declare function secretMatches(secret: string, expectedHex: string): boolean;
41
+ export declare function boundedMs(value: number | undefined, fallback: number, max: number): number;
42
+ export declare function parseJson<T>(value: string): T;
43
+ export declare function conflict(message: string): Error;
44
+ export declare function assertId(value: string, label?: string): void;
45
+ export declare function boundPresenceValue(value: unknown, depth: number): unknown;
46
+ export declare function configureCatalogDatabase(db: DatabaseSync): void;
47
+ export declare function initializeCatalogSchema(db: DatabaseSync): void;
48
+ //# sourceMappingURL=store-schema.d.ts.map
@@ -17,21 +17,6 @@ export declare class SessionCatalogStore {
17
17
  private reapExpired;
18
18
  private maintenanceExists;
19
19
  private leaseRow;
20
- /**
21
- * True when `sessionId` has a live `session_leases` row owned by a
22
- * different OS process than the *caller*. Used by
23
- * `acquireMaintenance` to distinguish "another running wstack" (which
24
- * must be fenced off) from "this very TUI owning its own session"
25
- * (which is allowed to claim a non-destructive maintenance lease on
26
- * its own transcript).
27
- *
28
- * `callerPid` must be the pid of the process that asked for the lease,
29
- * NOT `process.pid`. In the built runtime this store lives inside the
30
- * detached project-catalog daemon, so `process.pid` is the daemon's and
31
- * would mark every lease — including the caller's own session — foreign,
32
- * making `/clear` and `/rewind` fail with "Session … is live". Callers
33
- * that run the store in-process may omit it.
34
- */
35
20
  private foreignLiveLease;
36
21
  private verifyCredential;
37
22
  private createLease;
@@ -64,8 +49,6 @@ export declare class SessionCatalogStore {
64
49
  indexed: number;
65
50
  damaged: number;
66
51
  };
67
- private walkFiles;
68
- private summarizeTranscript;
69
52
  health(base: Omit<SessionCatalogHealth, 'catalogRows' | 'damagedRows' | 'liveLeases' | 'reservations' | 'maintenanceLeases' | 'generation' | 'lastReconciliation'>): SessionCatalogHealth;
70
53
  }
71
54
  //# sourceMappingURL=store.d.ts.map
@@ -15,6 +15,13 @@
15
15
  *
16
16
  * Stripping is therefore structural (projection), with `stripSecretMaterial` as a final
17
17
  * defense-in-depth pass mirroring the server's own scan.
18
+ *
19
+ * The two directions do NOT share one gate. "What may leave this machine" and "what may
20
+ * a remote peer write into the trusted profile config" are different questions, and the
21
+ * outbound tree is a wrong — dangerously permissive — answer to the second: it names
22
+ * `mcpServers.*.command`, `plugins`, `providers.*.baseUrl` and `yolo` as contract-owned,
23
+ * because pushing them is harmless. Pulls are therefore gated on `INBOUND_CONTRACT`, the
24
+ * outbound tree minus `INBOUND_DENIED_PATHS`.
18
25
  */
19
26
  /** `true` = the whole value is contract-owned; an object = recurse per key; `'*'` = record wildcard. */
20
27
  export type ContractNode = true | {
@@ -23,6 +30,17 @@ export type ContractNode = true | {
23
30
  /** Namespace → the contract tree over the `config.json` top-level keys it owns. */
24
31
  export declare const CLOUD_SYNC_CONTRACT: Readonly<Record<string, ContractNode>>;
25
32
  export declare const CLOUD_SYNC_NAMESPACES: string[];
33
+ /**
34
+ * Every inbound-denied path must still resolve against the outbound contract.
35
+ *
36
+ * A denylist that silently stops matching is worse than no denylist: it reads
37
+ * as protection while granting the field. Renaming `mcpServers.*.command` in
38
+ * the contract without updating the entry here must break the build, not
39
+ * quietly re-open remote code execution.
40
+ */
41
+ export declare function assertInboundDenyListResolves(): void;
42
+ /** Exposed for tests and diagnostics — the effective pull-side allow tree. */
43
+ export declare function inboundContractFor(namespace: string): ContractNode | undefined;
26
44
  /** Server-side schema versions, sent in every push envelope. */
27
45
  export declare const NAMESPACE_SCHEMA_VERSIONS: Readonly<Record<string, number>>;
28
46
  /**
@@ -1,4 +1,4 @@
1
- export { applyNamespacePayload, buildNamespacePayloads, CLOUD_SYNC_CONTRACT, CLOUD_SYNC_NAMESPACES, LOCAL_ONLY_TOP_LEVEL, NAMESPACE_SCHEMA_VERSIONS, stripSecretMaterial, } from './cloud-config-sync/sanitize.js';
1
+ export { applyNamespacePayload, assertInboundDenyListResolves, buildNamespacePayloads, CLOUD_SYNC_CONTRACT, CLOUD_SYNC_NAMESPACES, inboundContractFor, LOCAL_ONLY_TOP_LEVEL, NAMESPACE_SCHEMA_VERSIONS, stripSecretMaterial, } from './cloud-config-sync/sanitize.js';
2
2
  /**
3
3
  * CloudConfigSync — synchronizes the profile config with my.wrongstack.com over the
4
4
  * namespaced sync API v1 (server repo: docs/CLIENT_SYNC_CONTRACT.md).
@@ -127,6 +127,12 @@ export declare class DirectorStateCheckpoint {
127
127
  * checkpoint continues from there.
128
128
  */
129
129
  resume(snapshot: DirectorStateSnapshot): void;
130
+ /**
131
+ * Reconciles tasks and worktrees that were left in 'running' or 'allocated'
132
+ * state when the previous director crashed. Transitions abandoned tasks to
133
+ * 'failed' with a descriptive error and returns the list of repaired task IDs.
134
+ */
135
+ reconcileCrashedState(reason?: string): string[];
130
136
  /**
131
137
  * After resume, pin the live spawn ceiling from the current profile/flag
132
138
  * while preserving `spawnCount` (cumulative used budget). Checkpoint
@@ -20,10 +20,8 @@ export declare class FileSessionWriter implements SessionWriter {
20
20
  private closed;
21
21
  private closePromise;
22
22
  private manifestFile;
23
- private summary;
24
- private tokenIn;
25
- private tokenOut;
26
- private baseTokenTotal;
23
+ private readonly summaryTracker;
24
+ private readonly buffer;
27
25
  private readonly filePath;
28
26
  get transcriptPath(): string | undefined;
29
27
  /**
@@ -35,8 +33,6 @@ export declare class FileSessionWriter implements SessionWriter {
35
33
  private initPromise;
36
34
  private ensureInit;
37
35
  private readonly resumed;
38
- private appendFailCount;
39
- private lastAppendWarnAt;
40
36
  private readonly secretScrubber?;
41
37
  private readonly checkpointCas?;
42
38
  /** Mutable slot for onAppend callback — constructor opts seed it, setOnAppend replaces it. */
@@ -50,7 +46,6 @@ export declare class FileSessionWriter implements SessionWriter {
50
46
  get onAppendBatch(): ((events: SessionEvent[]) => void) | undefined;
51
47
  set onAppendBatch(cb: ((events: SessionEvent[]) => void) | undefined);
52
48
  private readonly onCloseCb?;
53
- private readonly resolveNameCb?;
54
49
  /** Implements SessionWriter.traceId — propagated from ContextInit.traceId. */
55
50
  traceId: string | undefined;
56
51
  /**
@@ -62,39 +57,12 @@ export declare class FileSessionWriter implements SessionWriter {
62
57
  * Set or replace the onAppendBatch callback.
63
58
  */
64
59
  setOnAppendBatch(cb: ((events: SessionEvent[]) => void) | undefined): void;
65
- private writeBuffer;
66
- private writeBufferBytes;
67
- private flushTimer;
68
- private static readonly FLUSH_INTERVAL_MS;
69
- private static readonly FLUSH_SIZE;
70
- private static readonly WRITE_BUFFER_MAX_EVENTS;
71
- private static readonly WRITE_BUFFER_MAX_BYTES;
72
- private bufferOverflowCount;
73
- private lastBufferOverflowWarnAt;
74
- private eventBytes;
75
- private pushWriteBuffer;
76
- private writeChain;
77
- private flushPromise;
78
- /** Enqueue a write on the FIFO chain. Resolves/rejects with that write. */
79
- private enqueueWrite;
80
- private iterationCount;
81
- private toolCallCount;
82
- private toolErrorCount;
83
- private toolBreakdown;
84
- private fileChangeCount;
85
- private compactionCount;
86
- private messageCount;
87
- private lastUserMessage;
88
- private lastActivityAt;
89
- private outcome;
90
60
  private pendingFileSnapshots;
91
61
  private pendingFileSnapshotBytes;
92
62
  private static readonly PENDING_FILE_SNAPSHOT_MAX_ENTRIES;
93
63
  private static readonly PENDING_FILE_SNAPSHOT_MAX_BYTES;
94
64
  /** Prompt whose tool work is currently executing. Set by writeCheckpoint. */
95
65
  private activePromptIndex;
96
- /** Tracks open tool_use IDs during the current run to serialize on close for resume. */
97
- private openToolUses;
98
66
  /**
99
67
  * Buffer an event from a synchronous Context callback. ensureInit() starts
100
68
  * by pushing the lifecycle preamble synchronously, so session_start always
@@ -159,30 +127,6 @@ export declare class FileSessionWriter implements SessionWriter {
159
127
  * be cut off by the exit regardless; errors here are swallowed.
160
128
  */
161
129
  flushSync(): void;
162
- /** Schedule a deferred flush. No-op if a timer is already pending. */
163
- private scheduleFlush;
164
- /**
165
- * Flush all buffered events to disk as a single appendFile call.
166
- * Concurrent callers join one coalesced drain. On failure the drained batch
167
- * is prepended to the live buffer, preserving chronology and allowing the
168
- * next timer/boundary flush to retry it. Warnings retain the existing
169
- * throttled behavior.
170
- */
171
- private flushBuffer;
172
- private flushBufferOnce;
173
- /**
174
- * Rebuild every accumulated summary counter by replaying the JSONL as it now
175
- * stands on disk.
176
- *
177
- * Only truncation needs this: the counters are fed by `observeForSummary` as
178
- * events go by and cannot un-count. Stream the JSONL so a very long session
179
- * does not need a second file-sized allocation during rewind.
180
- *
181
- * `title` is deliberately re-derived too: the first surviving user_input may
182
- * differ once earlier prompts are gone.
183
- */
184
- private recomputeSummaryFromDisk;
185
- private observeForSummary;
186
130
  close(): Promise<void>;
187
131
  private doClose;
188
132
  writeCheckpoint(promptIndex: number, promptPreview: string): Promise<void>;
@@ -30,6 +30,7 @@ export { type PromptUsage, PromptUsageStore } from './prompt-usage-store.js';
30
30
  export { type ProviderConfigSnapshot, readProviderSnapshot, type WatchProviderConfigOptions, watchProviderConfig, } from './provider-config-watcher.js';
31
31
  export { type PersistedQueueItem, QUEUE_MAX_BYTES, QUEUE_MAX_ITEM_BYTES, QUEUE_MAX_ITEMS, QueueStore, retainPersistedQueueItems, } from './queue-store.js';
32
32
  export { type AbandonedSession, RecoveryLock, type RecoveryLockOptions, } from './recovery-lock.js';
33
+ export { cleanOrphanLocks, type OrphanLockCleanResult, } from './orphan-lock-cleaner.js';
33
34
  export { type ReplayEntry, ReplayLogStore, type ReplayLogStoreOptions, } from './replay-log-store.js';
34
35
  export { SessionAnalyzer } from './session-analyzer.js';
35
36
  export { type CheckpointGitResult, SessionCheckpointCas, type SessionCheckpointCasOptions, } from './session-checkpoint-cas.js';
@@ -38,7 +39,7 @@ export { generateSessionId, sanitizeModel } from './session-id.js';
38
39
  export { resolveSessionId, type SessionIdResolution, sessionIdResolutionError, } from './session-id-resolver.js';
39
40
  export { scrubPersistedSessionData, scrubPersistedSessionEvent, scrubPersistedSessionSummary, } from './session-read-scrubber.js';
40
41
  export { DefaultSessionReader } from './session-reader.js';
41
- export { type RecoveryPlan, SessionRecovery, type StaleSession, } from './session-recovery.js';
42
+ export { extractInterruptedTools, type InterruptedToolDetail, type RecoveryPlan, SessionRecovery, type StaleSession, } from './session-recovery.js';
42
43
  export { type ApplyRewindOptions, type ApplyRewindResult, applyRewindToConversation, type RewindableConversation, } from './session-rewind-apply.js';
43
44
  export { DefaultSessionRewinder, type SessionRewinderOptions, } from './session-rewinder.js';
44
45
  export { DefaultSessionStore, type SessionStoreOptions, } from './session-store.js';