@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,55 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ import { type ChronicleMetricsRefreshResult } from './metrics-schema.js';
3
+ export declare class ChronicleMetricsIngester {
4
+ private readonly db;
5
+ private readonly directory;
6
+ private readonly dbPath;
7
+ constructor(db: DatabaseSync, directory: string, dbPath: string);
8
+ refresh(): Promise<ChronicleMetricsRefreshResult>;
9
+ private loadOffsets;
10
+ /** True once the legacy JSONL journal was imported into the SQLite journal
11
+ * (`importLegacyChronicleJournal` records the marker in `chronicle_meta`).
12
+ * After that point the SQLite `events` table already holds every JSONL
13
+ * event, so folding the leftover partition files again would double-count
14
+ * every migrated event in the aggregates. `source` is the already-opened
15
+ * read-only journal handle (null when no SQLite journal exists yet). */
16
+ private legacyJsonlConsumed;
17
+ /** Per-partition-file JSONL byte offsets recorded by
18
+ * `importLegacyChronicleJournal` at import time (keyed by the same relative
19
+ * path the fold uses). Files absent from the map were quarantined (or
20
+ * created after the migration) — their events live only in JSONL. */
21
+ private loadJsonlBoundary;
22
+ /** Persist the rebuild sentinel idempotently. Its presence makes
23
+ * `needsSqliteRebuild` return false, so post-migration jsonl-store offsets
24
+ * are never mistaken for pre-migration progress. */
25
+ private ensureRebuildMarker;
26
+ /** Upgrade path: `metrics.db` already aggregated the legacy JSONL, then the
27
+ * one-shot import copied those same events into the SQLite journal. There
28
+ * is no `sqlite:` cursor yet, so a plain incremental fold would replay the
29
+ * entire migrated history on top of the existing aggregates. The metrics
30
+ * projection is disposable (fully derived from the journal), so rebuild it
31
+ * from the SQLite source exactly once — the rebuild writes the cursors and
32
+ * subsequent refreshes go back to incremental folding. */
33
+ private needsSqliteRebuild;
34
+ private rebuildFromSqliteJournal;
35
+ private pruneOffsets;
36
+ private ingestSqliteJournal;
37
+ private ingestFile;
38
+ /** Fold one event into the aggregates atomically. `ingestEvent` runs several
39
+ * statements; when one throws mid-way (e.g. a malformed resource path), the
40
+ * statements before it already mutated the aggregates. The savepoint rolls
41
+ * those partial updates back: `ROLLBACK TO` rewinds, `RELEASE` (reached
42
+ * before the re-throw) pops the savepoint so the next event in the batch
43
+ * starts from a clean stack, and the batch commits only fully-succeeded
44
+ * events. Dropping the `RELEASE` would leak the savepoint into the next
45
+ * event's stack — the outer transaction ROLLBACK is never reached because
46
+ * the per-event catch swallows the error and continues the batch. */
47
+ private ingestEventAtomically;
48
+ private ingestEvent;
49
+ private ingestDailyCounters;
50
+ private ingestProvider;
51
+ private ingestTokenCost;
52
+ private ingestTask;
53
+ private ingestFileEvent;
54
+ }
55
+ //# sourceMappingURL=metrics-ingest.d.ts.map
@@ -0,0 +1,86 @@
1
+ import type { DatabaseSync } from 'node:sqlite';
2
+ import type { ChronicleSignalFamily } from './query.js';
3
+ import type { ChronicleEvent } from './types.js';
4
+ export declare const SCHEMA_VERSION = 3;
5
+ export declare const READ_CHUNK_BYTES: number;
6
+ export declare const SQLITE_SOURCE_PREFIX = "sqlite:";
7
+ export declare const SQLITE_INGEST_BATCH = 2000;
8
+ export declare const EMPTY_FAMILIES: Record<ChronicleSignalFamily, number>;
9
+ export interface ChronicleMetricsRefreshResult {
10
+ ingestedEvents: number;
11
+ ingestedBytes: number;
12
+ sourceFiles: number;
13
+ invalidLines: number;
14
+ }
15
+ export interface ChronicleProviderDailyRow {
16
+ day: string;
17
+ providerId: string;
18
+ modelId: string;
19
+ attempts: number;
20
+ completed: number;
21
+ failed: number;
22
+ retries: number;
23
+ fallbacks: number;
24
+ inputTokens: number;
25
+ outputTokens: number;
26
+ cacheReadTokens: number;
27
+ cacheWriteTokens: number;
28
+ avgDurationMs: number;
29
+ maxDurationMs: number;
30
+ }
31
+ export interface ChronicleTaskOutcomeRow {
32
+ taskId: string;
33
+ runId: string;
34
+ boardId: string;
35
+ sessionId: string;
36
+ agentId: string;
37
+ status: string;
38
+ startedAt: string | null;
39
+ endedAt: string | null;
40
+ durationMs: number | null;
41
+ retries: number;
42
+ verificationFailures: number;
43
+ filesTouched: number;
44
+ }
45
+ export interface ChronicleFileLineageRow {
46
+ path: string;
47
+ operation: string;
48
+ occurredAt: string;
49
+ sessionId: string;
50
+ agentId: string;
51
+ taskId: string;
52
+ boardId: string;
53
+ runId: string;
54
+ toolName: string;
55
+ providerId: string;
56
+ modelId: string;
57
+ source: string;
58
+ }
59
+ export interface ChronicleMetricsSummary {
60
+ providers: {
61
+ attempts: number;
62
+ completed: number;
63
+ failed: number;
64
+ successRate: number;
65
+ };
66
+ tasks: Record<string, number>;
67
+ files: {
68
+ mutations: number;
69
+ uniquePaths: number;
70
+ };
71
+ estimatedCostUsd: number;
72
+ }
73
+ export declare function loadDatabaseSync(): typeof DatabaseSync;
74
+ export declare function isChronicleMetricsAvailable(): boolean;
75
+ export declare function ensureMetricsSchema(db: DatabaseSync): void;
76
+ export declare function eventDay(event: ChronicleEvent): string;
77
+ export declare function durationMs(event: ChronicleEvent): number;
78
+ export declare function numberOrDuration(event: ChronicleEvent, attributes: Record<string, unknown>): number;
79
+ export declare function numberAt(event: ChronicleEvent, dotPath: string): number;
80
+ export declare function readPath(value: Record<string, unknown>, key: string): unknown;
81
+ export declare function stringAt(record: Record<string, unknown>, key: string): string | undefined;
82
+ export declare function asString(value: unknown): string | undefined;
83
+ export declare function clampLimit(limit: number | undefined, fallback: number): number;
84
+ export declare function normalizeKey(value: string): string;
85
+ export declare function normalizePathKey(value: string): string;
86
+ //# sourceMappingURL=metrics-schema.d.ts.map
@@ -6,98 +6,16 @@
6
6
  * projection kept in `<chronicleDir>/metrics.db` (node:sqlite, WAL). Each
7
7
  * `refresh()` incrementally consumes only the journal bytes appended since
8
8
  * the previous run (per-partition byte offsets in `ingest_state`), so the
9
- * raw JSONL partitions can be purged by retention without losing metrics:
10
- *
11
- * - `provider_daily` — provider×model×day attempt/success/failure/retry/
12
- * fallback counts, token totals, duration stats.
13
- * - `task_outcomes` — one row per task (kanban/SDD/subagent) with status,
14
- * timing, retry counts, and board/run/session lineage.
15
- * - `file_lineage` — one row per observed file mutation with full
16
- * session/agent/task/board/tool/model attribution.
17
- * - `token_cost` — latest cumulative token.accounted cost snapshot per
18
- * scope (same latest-wins semantics as the query
19
- * engine's summary).
20
- * - `daily_counters`, `family_daily`, `agent_daily`, `logical_request_daily`,
21
- * `file_seen_daily` — per-day scalar counters and dedup sets backing
22
- * `defaultSummary()`, a `ChronicleSummary` for the common unfiltered/
23
- * time-bounded dashboard view. Any genuinely ad hoc filter (free text,
24
- * path, session, provider, model) falls back to the raw-scan summary in
25
- * query.ts — fixed-dimension aggregation fundamentally can't answer those.
26
- *
27
- * The schema is a cache: on version mismatch it is dropped and re-ingested
28
- * from whatever journal partitions still exist.
9
+ * raw JSONL partitions can be purged by retention without losing metrics.
29
10
  */
30
11
  import type { ChronicleSummary } from './query.js';
31
- export interface ChronicleMetricsRefreshResult {
32
- ingestedEvents: number;
33
- ingestedBytes: number;
34
- sourceFiles: number;
35
- invalidLines: number;
36
- }
37
- export interface ChronicleProviderDailyRow {
38
- day: string;
39
- providerId: string;
40
- modelId: string;
41
- attempts: number;
42
- completed: number;
43
- failed: number;
44
- retries: number;
45
- fallbacks: number;
46
- inputTokens: number;
47
- outputTokens: number;
48
- cacheReadTokens: number;
49
- cacheWriteTokens: number;
50
- avgDurationMs: number;
51
- maxDurationMs: number;
52
- }
53
- export interface ChronicleTaskOutcomeRow {
54
- taskId: string;
55
- runId: string;
56
- boardId: string;
57
- sessionId: string;
58
- agentId: string;
59
- status: string;
60
- startedAt: string | null;
61
- endedAt: string | null;
62
- durationMs: number | null;
63
- retries: number;
64
- verificationFailures: number;
65
- filesTouched: number;
66
- }
67
- export interface ChronicleFileLineageRow {
68
- path: string;
69
- operation: string;
70
- occurredAt: string;
71
- sessionId: string;
72
- agentId: string;
73
- taskId: string;
74
- boardId: string;
75
- runId: string;
76
- toolName: string;
77
- providerId: string;
78
- modelId: string;
79
- source: string;
80
- }
81
- export interface ChronicleMetricsSummary {
82
- providers: {
83
- attempts: number;
84
- completed: number;
85
- failed: number;
86
- successRate: number;
87
- };
88
- tasks: Record<string, number>;
89
- files: {
90
- mutations: number;
91
- uniquePaths: number;
92
- };
93
- estimatedCostUsd: number;
94
- }
95
- /** Non-throwing availability probe for callers that degrade gracefully. */
96
- export declare function isChronicleMetricsAvailable(): boolean;
12
+ import { isChronicleMetricsAvailable, type ChronicleFileLineageRow, type ChronicleMetricsRefreshResult, type ChronicleMetricsSummary, type ChronicleProviderDailyRow, type ChronicleTaskOutcomeRow } from './metrics-schema.js';
13
+ export { isChronicleMetricsAvailable, type ChronicleFileLineageRow, type ChronicleMetricsRefreshResult, type ChronicleMetricsSummary, type ChronicleProviderDailyRow, type ChronicleTaskOutcomeRow, };
97
14
  export declare class ChronicleMetricsStore {
98
15
  private readonly db;
99
16
  private readonly directory;
100
17
  private readonly dbPath;
18
+ private readonly ingester;
101
19
  private constructor();
102
20
  static open(chronicleDirectory: string): ChronicleMetricsStore;
103
21
  close(): void;
@@ -127,44 +45,11 @@ export declare class ChronicleMetricsStore {
127
45
  summary(): ChronicleMetricsSummary;
128
46
  /**
129
47
  * A `ChronicleSummary` for the default/unfiltered dashboard view — only
130
- * `from`/`to` (day-precision) narrow it. Any other ad hoc filter (text,
131
- * path, provider, model, session) can't be answered from these
132
- * fixed-dimension aggregates; callers must fall back to query.ts's
133
- * raw-scan summary for those.
48
+ * `from`/`to` (day-precision) narrow it.
134
49
  */
135
50
  defaultSummary(options?: {
136
51
  from?: string;
137
52
  to?: string;
138
53
  }): ChronicleSummary;
139
- private ensureSchema;
140
- private loadOffsets;
141
- private pruneOffsets;
142
- /**
143
- * Fold everything the SQLite journal holds past this store's per-day cursor.
144
- *
145
- * Opened read-only on its own connection: the journal runs in WAL, so this
146
- * never blocks the daemon writing to it, and metrics are best-effort — a
147
- * journal that cannot be opened (mid-migration, absent, locked) leaves the
148
- * cursors untouched and the next refresh retries.
149
- *
150
- * Rows the journal has already evicted are simply not seen. That is the
151
- * intended split of responsibilities: the journal is a bounded ring, and this
152
- * store is where an aggregate outlives the raw event it came from — which
153
- * only holds if refresh runs more often than the ring turns over.
154
- */
155
- private ingestSqliteJournal;
156
- /** Read complete lines appended after `consumed` bytes. The trailing
157
- * partial line of an actively-written partition is left for the next
158
- * refresh — `ingest_state.bytes` only ever advances past full lines. */
159
- private ingestFile;
160
- private ingestEvent;
161
- /** Runs for every ingested event (not just the type-specific branches
162
- * below) — mirrors query.ts's updateSummary() closely enough that
163
- * defaultSummary() matches what a raw scan of the same window would say. */
164
- private ingestDailyCounters;
165
- private ingestProvider;
166
- private ingestTokenCost;
167
- private ingestTask;
168
- private ingestFileEvent;
169
54
  }
170
55
  //# sourceMappingURL=metrics-store.d.ts.map