@wrongstack/core 0.306.4 → 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 (103) 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 +6011 -5894
  14. package/dist/coordination/mail-tools.d.ts +1 -1
  15. package/dist/coordination/mailbox-http-actor-query.d.ts +16 -0
  16. package/dist/coordination/mailbox-http-router.d.ts +0 -48
  17. package/dist/coordination/mailbox-http-sse.d.ts +12 -0
  18. package/dist/coordination/mailbox-message-types.d.ts +71 -0
  19. package/dist/coordination/mailbox-predicates.d.ts +13 -0
  20. package/dist/coordination/mailbox-project-server.js +1 -1
  21. package/dist/coordination/mailbox-session-sync.d.ts +8 -0
  22. package/dist/coordination/mailbox-types.d.ts +6 -793
  23. package/dist/core/agent-loop-context.d.ts +28 -0
  24. package/dist/core/agent-loop-detector.d.ts +25 -0
  25. package/dist/core/fallback-doctor.d.ts +72 -0
  26. package/dist/core/index.d.ts +1 -0
  27. package/dist/core/index.js +1159 -888
  28. package/dist/defaults/index.js +3579 -3545
  29. package/dist/execution/autonomy-brain-llm.d.ts +55 -0
  30. package/dist/execution/autonomy-brain.d.ts +3 -156
  31. package/dist/execution/compaction-budget.d.ts +38 -0
  32. package/dist/execution/compaction-core.d.ts +3 -170
  33. package/dist/execution/compaction-elision.d.ts +58 -0
  34. package/dist/execution/council-orchestrator-helpers.d.ts +39 -0
  35. package/dist/execution/council-orchestrator.d.ts +3 -42
  36. package/dist/execution/council-response-parser.d.ts +56 -0
  37. package/dist/execution/index.js +2415 -2443
  38. package/dist/execution/prompt-enhancer.js +11 -3
  39. package/dist/execution/tool-executor-guard.d.ts +18 -0
  40. package/dist/execution/tool-executor-runner.d.ts +12 -0
  41. package/dist/execution/tool-executor.d.ts +0 -75
  42. package/dist/goal/index.js +19 -6
  43. package/dist/hq/index.js +8 -2
  44. package/dist/index.d.ts +1 -0
  45. package/dist/index.js +7813 -7292
  46. package/dist/infrastructure/index.js +3 -1
  47. package/dist/kernel/events/agent-events.d.ts +2 -0
  48. package/dist/kernel/events/provider-events.d.ts +13 -0
  49. package/dist/plugin/index.js +2590 -2561
  50. package/dist/plugins/auto-review-config.d.ts +53 -0
  51. package/dist/plugins/auto-review-git.d.ts +19 -0
  52. package/dist/plugins/auto-review-plugin.d.ts +2 -140
  53. package/dist/plugins/review-finding-verification.d.ts +7 -0
  54. package/dist/prompts/index.d.ts +1 -0
  55. package/dist/prompts/prompt-journal.d.ts +94 -0
  56. package/dist/security/index.js +627 -652
  57. package/dist/security/permission-explain.d.ts +19 -0
  58. package/dist/security/permission-policy.d.ts +0 -101
  59. package/dist/security/yolo-risk.d.ts +5 -4
  60. package/dist/session-catalog/index.js +220 -212
  61. package/dist/session-catalog/project-server.js +227 -219
  62. package/dist/session-catalog/store-rebuild.d.ts +9 -0
  63. package/dist/session-catalog/store-schema.d.ts +48 -0
  64. package/dist/session-catalog/store.d.ts +0 -17
  65. package/dist/storage/director-state.d.ts +6 -0
  66. package/dist/storage/file-session-writer.d.ts +2 -58
  67. package/dist/storage/index.d.ts +2 -1
  68. package/dist/storage/index.js +2057 -1925
  69. package/dist/storage/orphan-lock-cleaner.d.ts +15 -0
  70. package/dist/storage/session-recovery.d.ts +9 -0
  71. package/dist/storage/session-store/rename-session.d.ts +16 -0
  72. package/dist/storage/session-store/resume-session.d.ts +26 -0
  73. package/dist/storage/session-store/session-store-clear.d.ts +11 -0
  74. package/dist/storage/session-store/session-store-index.d.ts +13 -0
  75. package/dist/storage/session-store.d.ts +1 -129
  76. package/dist/storage/session-summary-tracker.d.ts +39 -0
  77. package/dist/storage/session-write-buffer.d.ts +43 -0
  78. package/dist/storage/session-writer/session-writer-flush.d.ts +4 -0
  79. package/dist/storage/session-writer/session-writer-summary-tracker.d.ts +28 -0
  80. package/dist/tools/fallback-agent-model-assign-tool.d.ts +18 -0
  81. package/dist/tools/fallback-leader-model-set-tool.d.ts +18 -0
  82. package/dist/tools/fallback-manage-tools.d.ts +8 -45
  83. package/dist/tools/fallback-profile-manage-tool.d.ts +16 -0
  84. package/dist/tools/fallback-provider-key-set-tool.d.ts +17 -0
  85. package/dist/tools/fallback-provider-manage-tool.d.ts +26 -0
  86. package/dist/tools/index.js +5070 -5071
  87. package/dist/types/config/root.d.ts +7 -2
  88. package/dist/types/default-config.d.ts +1 -1
  89. package/dist/types/index.d.ts +54 -55
  90. package/dist/types/index.js +953 -932
  91. package/dist/types/runtime-capability-manifest.d.ts +5 -5
  92. package/dist/types/session-markers.d.ts +12 -0
  93. package/dist/types/session-markers.js +19 -0
  94. package/dist/worktree/worktree-manager.d.ts +1 -1
  95. package/instructions/coordination/subagent-baseline.md +2 -2
  96. package/instructions/llm/prompt-enhancer.md +2 -1
  97. package/instructions/sections/tool/common-patterns.md +21 -0
  98. package/instructions/sections/tool/delegation-compact.md +3 -1
  99. package/instructions/sections/tool/delegation-full.md +5 -1
  100. package/instructions/system-lite.md +28 -3
  101. package/instructions/system-pro.md +37 -8
  102. package/instructions/system.md +4 -2
  103. package/package.json +5 -5
@@ -0,0 +1,39 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ export declare const SQLITE_FIXED_OVERHEAD_BYTES: number;
3
+ export declare const MIN_SQLITE_PAGE_BUDGET_BYTES: number;
4
+ export declare const MAX_WAL_RESERVE_BYTES: number;
5
+ export declare const WAL_AUTOCHECKPOINT_PAGES = 2000;
6
+ export declare const WAL_SIZE_LIMIT_BYTES: number;
7
+ export declare class ChronicleStorageQuotaError extends Error {
8
+ readonly currentBytes: number;
9
+ readonly batchBytes: number;
10
+ readonly maxBytes: number;
11
+ readonly path: string;
12
+ constructor(details: {
13
+ currentBytes: number;
14
+ batchBytes: number;
15
+ maxBytes: number;
16
+ path: string;
17
+ });
18
+ }
19
+ export declare class ChronicleQuotaManager {
20
+ private readonly db;
21
+ private readonly dbPath;
22
+ private readonly maxBytes;
23
+ private cachedPageSize;
24
+ private quotaHeadroomBytes;
25
+ private bytesSinceQuotaCheck;
26
+ constructor(db: DatabaseSync, dbPath: string, maxBytes: number | undefined);
27
+ configure(): void;
28
+ pageSizeBytes(): number;
29
+ aggregateLiveBytes(): number;
30
+ mainDatabaseLiveBytes(): number;
31
+ invalidateEstimate(): void;
32
+ recordAppendedBytes(bytes: number): void;
33
+ assertWithinByteQuota(batchBytes: number): void;
34
+ assertActualAllocationWithinQuota(): void;
35
+ normalizeQuotaError(error: unknown): unknown;
36
+ private shouldMeasureQuota;
37
+ private recordQuotaHeadroom;
38
+ }
39
+ //# sourceMappingURL=sqlite-journal-quota.d.ts.map
@@ -0,0 +1,25 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ import type { ChronicleEvent } from './types.js';
3
+ export declare const CHRONICLE_SQLITE_FILE = "chronicle.sqlite";
4
+ export declare const LEGACY_JSONL_MIGRATION_KEY = "legacy-jsonl-v1";
5
+ export declare const LEGACY_JSONL_QUARANTINE_KEY = "legacy-jsonl-v1:quarantine";
6
+ export declare const LEGACY_JSONL_BOUNDARY_KEY = "legacy-jsonl-v1:boundary";
7
+ export declare const SCHEMA_VERSION = 2;
8
+ export declare function loadDatabaseSync(): typeof DatabaseSync;
9
+ export interface ProjectedRow {
10
+ occurredAt: string;
11
+ outcome: string | null;
12
+ projectId: string | null;
13
+ sessionId: string | null;
14
+ agentId: string | null;
15
+ taskId: string | null;
16
+ traceId: string | null;
17
+ logicalRequestId: string | null;
18
+ resourceKind: string | null;
19
+ resourceId: string | null;
20
+ resourcePath: string | null;
21
+ durationNs: string | null;
22
+ }
23
+ export declare function projectEvent(event: ChronicleEvent): ProjectedRow;
24
+ export declare function ensureChronicleSchema(db: DatabaseSync): void;
25
+ //# sourceMappingURL=sqlite-journal-schema.d.ts.map
@@ -1,23 +1,9 @@
1
1
  import type { ChronicleJournalStats, ChroniclePurgeResult } from './journal.js';
2
+ import { ChronicleStorageQuotaError } from './sqlite-journal-quota.js';
3
+ import { CHRONICLE_SQLITE_FILE, LEGACY_JSONL_BOUNDARY_KEY, LEGACY_JSONL_MIGRATION_KEY, LEGACY_JSONL_QUARANTINE_KEY } from './sqlite-journal-schema.js';
2
4
  import { ChronicleSqliteQueryEngine, type ChronicleSqliteQueryEngineOptions } from './sqlite-query.js';
3
5
  import { type ChronicleEvent, type ChronicleEventInput, type ChronicleVerifyResult } from './types.js';
4
- export declare const CHRONICLE_SQLITE_FILE = "chronicle.sqlite";
5
- /** Marker written once the legacy JSONL partitions have been imported. */
6
- export declare const LEGACY_JSONL_MIGRATION_KEY = "legacy-jsonl-v1";
7
- /** Day families the import refused to move, recorded so they are never retried silently. */
8
- export declare const LEGACY_JSONL_QUARANTINE_KEY = "legacy-jsonl-v1:quarantine";
9
- export declare class ChronicleStorageQuotaError extends Error {
10
- readonly currentBytes: number;
11
- readonly batchBytes: number;
12
- readonly maxBytes: number;
13
- readonly path: string;
14
- constructor(details: {
15
- currentBytes: number;
16
- batchBytes: number;
17
- maxBytes: number;
18
- path: string;
19
- });
20
- }
6
+ export { CHRONICLE_SQLITE_FILE, ChronicleStorageQuotaError, LEGACY_JSONL_BOUNDARY_KEY, LEGACY_JSONL_MIGRATION_KEY, LEGACY_JSONL_QUARANTINE_KEY, };
21
7
  export interface ChronicleSqliteJournalOptions {
22
8
  /** Directory holding the journal, i.e. `<projectDir>/chronicle`. */
23
9
  directory: string;
@@ -64,21 +50,12 @@ export declare class ChronicleSqliteJournal {
64
50
  private readonly idFactory;
65
51
  private readonly retentionDays;
66
52
  private readonly maxEvents;
67
- private readonly maxBytes;
68
53
  private readonly retentionCheckIntervalMs;
69
54
  /** Overshoot allowed above `maxEvents` before eviction runs; see TRIM_SLACK_RATIO. */
70
55
  private readonly trimSlack;
56
+ private readonly quotaManager;
71
57
  private nextRetentionCheckAt;
72
58
  private retainedEventCount;
73
- /** Resolved lazily by `pageSizeBytes()`; constant for an open database. */
74
- private cachedPageSize;
75
- /**
76
- * Bytes the quota is known to have had spare at the last real measurement,
77
- * and the bytes appended since. `assertWithinByteQuota` re-measures only once
78
- * the second could plausibly have consumed the first — see its comment.
79
- */
80
- private quotaHeadroomBytes;
81
- private bytesSinceQuotaCheck;
82
59
  /**
83
60
  * Statements reused across appends.
84
61
  *
@@ -98,177 +75,35 @@ export declare class ChronicleSqliteJournal {
98
75
  constructor(options: ChronicleSqliteJournalOptions);
99
76
  close(): void;
100
77
  stats(): ChronicleJournalStats;
101
- /**
102
- * Writes are synchronous and transactional, so there is nothing buffered to
103
- * flush. Kept to satisfy `ChronicleEventSink`.
104
- */
105
78
  flush(): Promise<void>;
106
79
  append(input: ChronicleEventInput): Promise<ChronicleEvent>;
107
- /**
108
- * Append a batch as one transaction.
109
- *
110
- * The chain is computed in memory from a single anchor, so a partially
111
- * applied batch would leave a hole in `sequence` that verification can never
112
- * reconcile. Rollback plus anchor invalidation is what prevents that.
113
- */
114
80
  appendBatch(inputs: readonly ChronicleEventInput[]): Promise<ChronicleEvent[]>;
115
81
  readAll(): Promise<ChronicleEvent[]>;
116
- /**
117
- * Walk every chain and prove none has been edited.
118
- *
119
- * Chronicle chains are scoped to a day, not to the journal: the JSONL writer
120
- * anchors each `<day>.events.jsonl` family at `GENESIS_HASH` independently,
121
- * so `sequence` restarts at 1 every day. Verification mirrors that — each day
122
- * is validated on its own, and a break in one does not implicate the others.
123
- *
124
- * Three independent properties per day, because each catches a different
125
- * failure: a dense `sequence` catches deletions from the middle, the
126
- * `previousHash` link catches reordering, and re-hashing the payload catches
127
- * an in-place edit that left the links intact.
128
- */
129
82
  verify(): Promise<ChronicleVerifyResult>;
130
83
  private enforceRetentionIfDue;
131
- private configureByteQuota;
132
- /**
133
- * Bytes the journal actually occupies: live pages in the main database plus
134
- * whatever the rollback/WAL sidecars currently hold.
135
- *
136
- * The quota MUST be measured this way rather than by `statSync` on the main
137
- * database file. SQLite never returns freed pages to the filesystem — it
138
- * parks them on the freelist and reuses them — so a database that once grew
139
- * large keeps that size forever, even after retention and `maxEvents` have
140
- * evicted almost everything. Measuring the file instead wedged the journal
141
- * permanently: a 3.9 GB file whose live data was 243 MB failed a 512 MB
142
- * quota on EVERY append, and the only escape (`chronicle compact`) refuses
143
- * to run while the daemon is up — and the daemon respawns on demand. Live
144
- * pages shrink when retention deletes rows, so the quota can recover on its
145
- * own; allocated size cannot.
146
- *
147
- * The sidecars keep their on-disk size: they are transient and genuinely
148
- * bounded by `configureByteQuota`'s half-of-budget split.
149
- */
150
- private aggregateLiveBytes;
151
- /** Live (non-freelist) pages of the main database, in bytes. */
152
- private mainDatabaseLiveBytes;
153
- /** Page size never changes for an open database; resolve it once. */
154
- private pageSizeBytes;
155
- private normalizeQuotaError;
156
- /** Drop the cached headroom so the next quota check measures for real. */
157
- private invalidateQuotaEstimate;
158
- private assertActualAllocationWithinQuota;
159
- /**
160
- * Refuse a batch that would take the journal past its byte quota.
161
- *
162
- * This is the *courteous* bound, not the enforced one: `max_page_count` makes
163
- * SQLite itself fail the write with `SQLITE_FULL`, which `normalizeQuotaError`
164
- * turns into the same {@link ChronicleStorageQuotaError}. Its only job is to
165
- * produce that error before a doomed batch has been written, so it does not
166
- * have to run on every append — and it should not, because measuring costs two
167
- * PRAGMA round trips and three `statSync` calls, twice per transaction.
168
- *
169
- * So it measures adaptively instead of on a fixed cadence: after a real
170
- * measurement it knows the spare bytes, and it may skip until the bytes
171
- * appended since then could plausibly have consumed half of them. Far from the
172
- * ceiling that is thousands of appends; close to it, every one. The bound
173
- * tightens exactly where being wrong would matter.
174
- */
175
- private assertWithinByteQuota;
176
- /**
177
- * Is the cached headroom still large enough to vouch for this batch?
178
- *
179
- * Half the headroom is the budget deliberately: rows carry index and page
180
- * overhead beyond their payload bytes, so `bytesSinceQuotaCheck` understates
181
- * real growth, and the factor absorbs that without needing to model it.
182
- */
183
- private shouldMeasureQuota;
184
- private recordQuotaHeadroom;
185
- /**
186
- * Evict the oldest events once the row ceiling has been overshot by `trimSlack`.
187
- *
188
- * @param count Rows now in the table. The caller tracks this rather than the
189
- * method querying it: `SELECT COUNT(*)` walks the whole table, and at the
190
- * ceiling — where every long-lived journal lives — that was a full scan of
191
- * `maxEvents` rows on every append, to learn a number the append path already
192
- * knew. The count is re-derived from the database whenever it could have
193
- * drifted (open, import, purge), never accumulated blindly across those.
194
- * @param slack Overshoot tolerated before evicting; callers that run once,
195
- * rather than per append, pass 0 to land on the exact ceiling.
196
- */
197
84
  private enforceEventLimitWithinTransaction;
198
85
  private enforceEventLimitAtStartup;
199
- /**
200
- * Drop events older than the retention window.
201
- *
202
- * Retention is day-granular and chains are day-scoped, so a purge removes
203
- * whole chains rather than truncating one. That is why nothing needs to be
204
- * checkpointed here: there is no surviving suffix left dangling without an
205
- * anchor. Any checkpoint imported from a partially-purged legacy day family
206
- * is dropped alongside its events.
207
- */
208
86
  purge(options: ChronicleSqlitePurgeOptions): Promise<ChroniclePurgeResult>;
209
- /**
210
- * Run one day family's legacy import inside its own transaction.
211
- *
212
- * Deliberately separate from `appendBatch`: the append path *computes*
213
- * `sequence`, `previousHash` and `hash`, while an import must carry them over
214
- * untouched. Fusing the two would put a code path one refactor away from
215
- * re-hashing historical events, which is the one change that silently
216
- * destroys their tamper evidence.
217
- *
218
- * The transaction is scoped to a single family because chains are: `sequence`
219
- * restarts at 1 each day, so one day's break says nothing about the next
220
- * day's integrity. A whole-journal transaction made every future day hostage
221
- * to the worst day on disk — one corrupt family and the daemon could never
222
- * open its store again. The family is still all-or-nothing: a break rolls
223
- * back that day entirely, so no partial chain is ever visible.
224
- */
225
87
  runFamilyImport(load: (sink: ChronicleImportSink) => Promise<void>): Promise<void>;
226
- /**
227
- * A read engine over this journal's own connection.
228
- *
229
- * Sharing the connection rather than opening a second one keeps the
230
- * single-writer guarantee intact and means a reader can never observe a
231
- * half-applied batch: SQLite serialises statements on one handle.
232
- */
233
88
  queryEngine(options?: ChronicleSqliteQueryEngineOptions): ChronicleSqliteQueryEngine;
234
- /** Has the legacy JSONL import already run? */
235
89
  hasImportedLegacyJournal(): boolean;
236
90
  markLegacyJournalImported(): void;
237
- /**
238
- * Record the day families the import refused to move.
239
- *
240
- * Persisted rather than merely logged because the import runs once: after the
241
- * marker is set nothing re-reads the JSONL, so this row is the only surviving
242
- * evidence that a day was dropped. Health reports read it back to say
243
- * "degraded, and here is exactly what is missing" instead of quietly serving
244
- * a journal with a hole in it.
245
- */
246
91
  recordQuarantinedFamilies(families: readonly ChronicleQuarantinedFamily[]): void;
247
- /**
248
- * Does this day already hold rows?
249
- *
250
- * Each family commits on its own, so an import interrupted between families
251
- * leaves a database that is complete for the days it reached. `(day,
252
- * sequence)` is the primary key, so re-inserting one of those days would
253
- * abort on a constraint violation rather than start over — this is what lets
254
- * the next run resume at the first day it never got to.
255
- */
92
+ /** Record per-partition-file JSONL byte offsets at import time (merged — the
93
+ * import persists per family, so a crash mid-run keeps earlier boundaries).
94
+ * The metrics ingester folds only bytes beyond these boundaries after the
95
+ * migration, so post-migration appends (the jsonl-store fallback) are
96
+ * ingested while the migrated bytes are never re-counted. Files absent from
97
+ * the map were quarantined (or created post-migration) their events live
98
+ * only in JSONL. */
99
+ recordLegacyJsonlBoundary(boundary: Record<string, number>): void;
256
100
  hasImportedDay(day: string): boolean;
257
- /** Day families the legacy import refused to move, oldest first. */
258
101
  quarantinedFamilies(): ChronicleQuarantinedFamily[];
259
102
  private preparedStatements;
260
- /** Rows currently in the table, straight from the database. */
261
103
  private countRows;
262
104
  private readMeta;
263
105
  private readCheckpoint;
264
- /** Days that currently hold at least one event, oldest first. */
265
106
  private days;
266
- /**
267
- * Resolve the chain head, in the same precedence the JSONL journal uses: the
268
- * newest event, else the retention checkpoint (every event before it was
269
- * purged), else genesis.
270
- */
271
107
  private readAnchor;
272
- private ensureSchema;
273
108
  }
274
109
  //# sourceMappingURL=sqlite-journal.d.ts.map