@wrongstack/core 0.309.1 → 0.310.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.
Files changed (120) hide show
  1. package/dist/chronicle/index.js +113 -41
  2. package/dist/chronicle/metrics-ingest.d.ts +7 -0
  3. package/dist/chronicle/metrics-schema.d.ts +4 -1
  4. package/dist/chronicle/project-server.js +94 -38
  5. package/dist/chronicle/query.d.ts +1 -0
  6. package/dist/chronicle/sqlite-journal-schema.d.ts +2 -1
  7. package/dist/chronicle/types.d.ts +2 -0
  8. package/dist/{agent-status-helpers.d.ts → coordination/agent-status-helpers.d.ts} +1 -1
  9. package/dist/{agent-status-tracker.d.ts → coordination/agent-status-tracker.d.ts} +2 -2
  10. package/dist/{middleware → coordination}/collab-pause.d.ts +1 -1
  11. package/dist/coordination/director-kanban-queue-helpers.d.ts +1 -1
  12. package/dist/coordination/fleet-status-tool.d.ts +1 -1
  13. package/dist/coordination/index.d.ts +5 -1
  14. package/dist/coordination/index.js +2061 -346
  15. package/dist/coordination/kanban-dispatch-port.d.ts +30 -0
  16. package/dist/coordination/kanban-ops-port.d.ts +21 -0
  17. package/dist/coordination/mailbox-hooks.d.ts +1 -1
  18. package/dist/coordination/mailbox-project-server.js +14 -9
  19. package/dist/core/context.d.ts +35 -44
  20. package/dist/core/conversation-state.d.ts +16 -52
  21. package/dist/core/index.js +53 -16
  22. package/dist/core/provider-runner.d.ts +2 -2
  23. package/dist/core/run-env.d.ts +7 -28
  24. package/dist/core/streaming-response-builder.d.ts +2 -2
  25. package/dist/execution/index.js +111 -153
  26. package/dist/goal/index.js +100 -22
  27. package/dist/hq/auth-store.d.ts +9 -0
  28. package/dist/hq/cost-bridge.d.ts +1 -1
  29. package/dist/hq/index.js +24 -2
  30. package/dist/index.d.ts +12 -5
  31. package/dist/index.js +27808 -33937
  32. package/dist/infrastructure/index.js +210 -132
  33. package/dist/infrastructure/provider-cache-ledger.d.ts +1 -1
  34. package/dist/infrastructure/token-counter.d.ts +5 -1
  35. package/dist/kernel/events/file-events.d.ts +6 -0
  36. package/dist/kernel/events/provider-events.d.ts +10 -7
  37. package/dist/kernel/events/session-events.d.ts +4 -4
  38. package/dist/kernel/events/tool-events.d.ts +12 -2
  39. package/dist/plugin/index.js +105 -35
  40. package/dist/security/index.d.ts +1 -0
  41. package/dist/security/index.js +47 -18
  42. package/dist/security/kanban-boundary.d.ts +1 -1
  43. package/dist/security/kanban-governance-port.d.ts +28 -0
  44. package/dist/session-catalog/index.js +2 -3
  45. package/dist/session-catalog/project-server.js +2 -3
  46. package/dist/session-catalog/protocol.d.ts +1 -1
  47. package/dist/session-catalog/registry.d.ts +1 -1
  48. package/dist/session-catalog/store-schema.d.ts +1 -1
  49. package/dist/session-catalog/store.d.ts +1 -1
  50. package/dist/storage/annotations-store.d.ts +1 -1
  51. package/dist/storage/board-store-port.d.ts +45 -0
  52. package/dist/storage/completed-work-checkpoint.d.ts +1 -1
  53. package/dist/storage/config-loader/types.d.ts +1 -1
  54. package/dist/storage/event-bus-port.d.ts +27 -0
  55. package/dist/storage/file-session-writer.d.ts +47 -5
  56. package/dist/storage/goal-coordination.d.ts +1 -1
  57. package/dist/storage/goal-store.d.ts +1 -1
  58. package/dist/storage/index.d.ts +3 -4
  59. package/dist/storage/index.js +1063 -1459
  60. package/dist/storage/plan-store.d.ts +1 -1
  61. package/dist/storage/queue-store.d.ts +1 -1
  62. package/dist/storage/replay-log-store.d.ts +1 -1
  63. package/dist/storage/session-recovery.d.ts +10 -0
  64. package/dist/storage/session-resume-validation.d.ts +13 -1
  65. package/dist/storage/session-store/events.d.ts +1 -1
  66. package/dist/storage/session-store/load-session-data.d.ts +1 -1
  67. package/dist/storage/session-store/rename-session.d.ts +1 -1
  68. package/dist/storage/session-store/resume-session.d.ts +3 -1
  69. package/dist/storage/session-store/session-store-index.d.ts +2 -1
  70. package/dist/storage/session-store/types.d.ts +1 -1
  71. package/dist/storage/session-store.d.ts +70 -0
  72. package/dist/storage/session-summary-tracker.d.ts +8 -0
  73. package/dist/storage/session-write-buffer.d.ts +31 -2
  74. package/dist/storage/task-store.d.ts +1 -1
  75. package/dist/storage/todos-checkpoint.d.ts +1 -1
  76. package/dist/storage/tool-audit-log.d.ts +1 -1
  77. package/dist/tasking/index.js +100 -22
  78. package/dist/tasking/task-tracker.d.ts +24 -1
  79. package/dist/types/compactor.d.ts +2 -2
  80. package/dist/types/config/runtime.d.ts +7 -0
  81. package/dist/types/config/tools.d.ts +30 -0
  82. package/dist/types/context.d.ts +212 -0
  83. package/dist/types/conversation-state.d.ts +109 -0
  84. package/dist/types/error-handler.d.ts +2 -2
  85. package/dist/types/file-event-record.d.ts +6 -0
  86. package/dist/types/index.d.ts +4 -4
  87. package/dist/types/index.js +19 -1
  88. package/dist/types/permission.d.ts +3 -3
  89. package/dist/types/plugin.d.ts +3 -3
  90. package/dist/types/provider-runner.d.ts +2 -2
  91. package/dist/types/provider.d.ts +10 -0
  92. package/dist/types/run-env.d.ts +32 -0
  93. package/dist/types/session.d.ts +3 -0
  94. package/dist/types/slash-command.d.ts +2 -2
  95. package/dist/types/token-counter.d.ts +30 -1
  96. package/dist/types/tool-executor.d.ts +2 -2
  97. package/dist/types/tool.d.ts +5 -5
  98. package/dist/utils/context-breakdown.d.ts +2 -2
  99. package/dist/utils/context-evidence.d.ts +12 -12
  100. package/dist/utils/crash-shield.d.ts +9 -0
  101. package/dist/utils/heap-watchdog.js +11 -3
  102. package/dist/utils/index.d.ts +1 -1
  103. package/dist/utils/index.js +72 -156
  104. package/dist/utils/regex-guard.d.ts +7 -30
  105. package/dist/utils/todos-format.d.ts +1 -1
  106. package/dist/utils/tree-kill.d.ts +2 -0
  107. package/dist/utils/tree-kill.js +1 -0
  108. package/dist/wiring/proxy-rewrite.d.ts +76 -0
  109. package/dist/wiring/proxy-rewrite.js +70 -0
  110. package/instructions/coordination/subagent-baseline.md +10 -0
  111. package/instructions/system-lite.md +2 -0
  112. package/instructions/system-pro.md +40 -0
  113. package/instructions/system.md +15 -0
  114. package/package.json +10 -9
  115. package/dist/defaults/index.d.ts +0 -69
  116. package/dist/defaults/index.js +0 -38133
  117. /package/dist/{fleet-notifier.d.ts → coordination/fleet-notifier.d.ts} +0 -0
  118. /package/dist/{session-registry-atomic-file.d.ts → session-catalog/session-registry-atomic-file.d.ts} +0 -0
  119. /package/dist/{session-registry-types.d.ts → session-catalog/session-registry-types.d.ts} +0 -0
  120. /package/dist/{session-registry.d.ts → session-catalog/session-registry.d.ts} +0 -0
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Kanban board-store port for the storage area (goal coordination).
3
+ *
4
+ * `goal-kanban.ts` and `goal-coordination.ts` previously imported the
5
+ * concrete functions from `@wrongstack/kanban` directly, keeping a
6
+ * core → kanban runtime edge (the layering inversion catalogued as
7
+ * roadmap #11 / report §2.1). This port is the leaf contract the storage
8
+ * area codes against; the CLI composition root registers the real
9
+ * implementation at boot (TOKENS-style dependency injection).
10
+ *
11
+ * Type-only imports of kanban's data shapes remain permitted — they erase
12
+ * at compile time and do not create a runtime edge. Only *callable*
13
+ * surface is ported.
14
+ *
15
+ * Un-registered default: goal features fail soft (board sync disabled)
16
+ * exactly as before the extraction, so embedding contexts without kanban
17
+ * keep working.
18
+ */
19
+ import type { CreateKanbanBoardInput, CreateKanbanTaskInput, KanbanBoard, KanbanBoardSummary, KanbanEventContext, KanbanTask, UpdateKanbanTaskInput } from '@wrongstack/kanban';
20
+ export interface BoardStorePort {
21
+ createBoard(projectRoot: string, input: CreateKanbanBoardInput): Promise<KanbanBoard>;
22
+ listBoards(projectRoot: string): Promise<KanbanBoardSummary[]>;
23
+ getBoard(projectRoot: string, boardId: string): Promise<KanbanBoard | null>;
24
+ removeBoard(projectRoot: string, boardId: string): Promise<boolean>;
25
+ addTask(projectRoot: string, boardId: string, input: CreateKanbanTaskInput, eventContext?: KanbanEventContext): Promise<{
26
+ board: KanbanBoard;
27
+ task: KanbanTask;
28
+ } | null>;
29
+ updateTask(projectRoot: string, boardId: string, taskId: string, input: UpdateKanbanTaskInput, eventContext?: KanbanEventContext): Promise<KanbanBoard | null>;
30
+ }
31
+ /** Composition-root hook: register the real kanban-backed implementation. */
32
+ export declare function setBoardStorePort(impl: BoardStorePort): void;
33
+ /**
34
+ * Resolve the board-store port. Callers that must fail soft should catch
35
+ * the not-wired error, same semantics as kanban being absent.
36
+ */
37
+ export declare function boardStore(): BoardStorePort;
38
+ /**
39
+ * Fail-soft resolver: the port when wired, otherwise `null`. For code paths
40
+ * whose documented behavior when kanban is absent is a no-op or empty
41
+ * result (goal sync, previews) — avoids the synchronous throw breaking
42
+ * `.catch()` fail-soft chains in non-CLI embeddings.
43
+ */
44
+ export declare function tryBoardStore(): BoardStorePort | null;
45
+ //# sourceMappingURL=board-store-port.d.ts.map
@@ -1,4 +1,4 @@
1
- import type { EventBus } from '../kernel/events.js';
1
+ import type { EventBus } from './event-bus-port.js';
2
2
  import type { CompletedWorkEvidence } from '../types/context-evidence.js';
3
3
  export interface CompletedWorkCheckpointFile {
4
4
  version: 1;
@@ -1,4 +1,4 @@
1
- import type { EventBus } from '../../kernel/events.js';
1
+ import type { EventBus } from '../event-bus-port.js';
2
2
  import type { Config } from '../../types/config.js';
3
3
  import type { Logger } from '../../types/logger.js';
4
4
  import type { SecretVault } from '../../types/secret-vault.js';
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Event-bus port for the storage area.
3
+ *
4
+ * Storage modules receive a bus instance from the composition root and use
5
+ * it only to *emit* `storage.*` events (verified: zero subscribe/logger/
6
+ * constructor calls across packages/core/src/storage). Importing the concrete
7
+ * `EventBus` class from `../kernel/events.js` kept a storage → kernel edge in
8
+ * the dependency graph; this port severs it.
9
+ *
10
+ * Structurally satisfied by the kernel `EventBus` class (its typed-generic
11
+ * `emit` is compatible with this loose signature via method-bivariance), so
12
+ * composition-root wiring needs no adapter.
13
+ *
14
+ * Surface policy: emit-only. If a storage consumer ever needs to subscribe,
15
+ * widen this port deliberately instead of re-importing the kernel type.
16
+ */
17
+ export interface EventBus {
18
+ /**
19
+ * Emit a storage-domain event onto the bus.
20
+ *
21
+ * Loose parameter typing is deliberate: the concrete kernel bus carries the
22
+ * full `EventMap` typing; storage call sites pass literal `'storage.*'`
23
+ * names whose payloads the kernel map validates at the wiring boundary.
24
+ */
25
+ emit(event: string, payload?: unknown): void;
26
+ }
27
+ //# sourceMappingURL=event-bus-port.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import * as fsp from 'node:fs/promises';
2
- import type { EventBus } from '../kernel/events.js';
2
+ import type { EventBus } from './event-bus-port.js';
3
3
  import type { SecretScrubber } from '../types/secret-scrubber.js';
4
4
  import type { FileSnapshot, SessionEvent, SessionMetadata, SessionSummary, SessionWriter } from '../types/session.js';
5
5
  import type { SessionCheckpointCas } from './session-checkpoint-cas.js';
@@ -46,6 +46,15 @@ export declare class FileSessionWriter implements SessionWriter {
46
46
  get onAppendBatch(): ((events: SessionEvent[]) => void) | undefined;
47
47
  set onAppendBatch(cb: ((events: SessionEvent[]) => void) | undefined);
48
48
  private readonly onCloseCb?;
49
+ /** Mid-session metadata checkpoint throttle. 0 disables checkpointing. */
50
+ private readonly metadataCheckpointMs;
51
+ /** One-shot guard for the "interval set but no sink" warning below. */
52
+ private _checkpointNoSinkWarned;
53
+ private readonly onMetadataCheckpointCb?;
54
+ /** Set whenever summary counters changed since the last metadata checkpoint. */
55
+ private metadataDirty;
56
+ private metadataTimer;
57
+ private metadataCheckpointInFlight;
49
58
  /** Implements SessionWriter.traceId — propagated from ContextInit.traceId. */
50
59
  traceId: string | undefined;
51
60
  /**
@@ -104,15 +113,47 @@ export declare class FileSessionWriter implements SessionWriter {
104
113
  onClose?: ((summary: SessionSummary) => void | Promise<void>) | undefined;
105
114
  /** Reconcile an explicit name changed while this writer remained open. */
106
115
  resolveName?: (() => Promise<Pick<SessionSummary, 'name'> | null>) | undefined;
116
+ /**
117
+ * Mid-session metadata checkpoint throttle (ms). While the session is
118
+ * live and dirty, the summary sidecar + index row are refreshed at most
119
+ * this often, so a SIGKILLed process still leaves accurate listing
120
+ * metadata instead of its create-time stub. 0 disables checkpointing —
121
+ * killed sessions then stay visible through the store's list()-union
122
+ * scan, but only with analyzer-derived metadata rather than tracked
123
+ * counters. Default 10_000.
124
+ */
125
+ metadataCheckpointMs?: number | undefined;
126
+ /**
127
+ * Persists a mid-session summary snapshot (store-level index row /
128
+ * catalog upsert). The sidecar file itself is written by the writer
129
+ * under its manifest lock; this callback covers the index side.
130
+ */
131
+ onMetadataCheckpoint?: ((summary: SessionSummary) => void | Promise<void>) | undefined;
107
132
  }, traceId?: string | undefined);
108
133
  get pendingToolUses(): string[];
109
134
  private writeSessionStartLazy;
135
+ /**
136
+ * Arm the mid-session metadata checkpoint timer if it is not already armed.
137
+ * Called after every observed event; the timer itself is unref'd so an idle
138
+ * session never keeps the process alive for a cosmetic sidecar refresh.
139
+ */
140
+ private scheduleMetadataCheckpoint;
141
+ /**
142
+ * Persist a mid-session summary snapshot: the `.summary.json` sidecar under
143
+ * the manifest lock, then the store-level index row / catalog upsert via
144
+ * `onMetadataCheckpoint`. Runs at most once per throttle interval and only
145
+ * when summary counters changed since the last checkpoint; a failed
146
+ * checkpoint stays dirty and retries on the next armed tick.
147
+ */
148
+ private runMetadataCheckpoint;
110
149
  append(event: SessionEvent): Promise<void>;
111
150
  appendBatch(events: SessionEvent[]): Promise<void>;
112
151
  /**
113
152
  * Flush buffered events to disk immediately. Critical events
114
- * (user_input, llm_response) call this so they survive SIGKILL/crash
115
- * instead of sitting in the in-memory buffer for up to 500ms.
153
+ * (user_input, llm_response, checkpoint, in_flight_*) already flush
154
+ * themselves inside append()/appendBatch(), so calling this matters for
155
+ * non-critical tails that would otherwise sit in the in-memory buffer
156
+ * for up to 500ms.
116
157
  *
117
158
  * Idempotent — cancels any pending timer, writes whatever has accumulated,
118
159
  * then asks the OS to synchronize the file data before resolving. Even an
@@ -123,8 +164,9 @@ export declare class FileSessionWriter implements SessionWriter {
123
164
  * Last-gasp synchronous drain for hard-exit paths (process.exit after
124
165
  * rapid Ctrl+C). The async write chain cannot be awaited when the process
125
166
  * is about to die, but whatever still sits in the in-memory buffer CAN be
126
- * saved with a blocking append. Best-effort: an in-flight async write may
127
- * be cut off by the exit regardless; errors here are swallowed.
167
+ * saved with a blocking append. A failed sync append leaves the buffer
168
+ * intact so a subsequent close()/flush() can retry. An in-flight async
169
+ * write may still be cut off by a hard exit.
128
170
  */
129
171
  flushSync(): void;
130
172
  close(): Promise<void>;
@@ -1,5 +1,5 @@
1
1
  import type { BrainArbiter } from '../coordination/brain.js';
2
- import type { EventBus } from '../kernel/events.js';
2
+ import type { EventBus } from './event-bus-port.js';
3
3
  import { type GoalFile } from './goal-store.js';
4
4
  export interface CompletedGoalDeliverable {
5
5
  index: number;
@@ -1,4 +1,4 @@
1
- import type { EventBus } from '../kernel/events.js';
1
+ import type { EventBus } from './event-bus-port.js';
2
2
  /**
3
3
  * Long-running autonomous mission. A goal survives across sessions and
4
4
  * drives the EternalAutonomyEngine — every iteration of the engine
@@ -1,10 +1,9 @@
1
- export { AgentStatusTracker, type AgentStatusTrackerOptions, } from '../agent-status-tracker.js';
2
- export { FleetNotifier, type FleetNotifierOptions, } from '../fleet-notifier.js';
1
+ export { type BoardStorePort, boardStore, setBoardStorePort, } from './board-store-port.js';
3
2
  export { type CatalogSessionRecord, type MaintenanceLease, type ResumeReservation, type SessionCatalogHealth, SessionCatalogProjectClient, type SessionCatalogProjectClientOptions, type SessionLeaseCredential, type SessionResumeClaim, } from '../session-catalog/index.js';
4
3
  export { getProjectSessionRegistry as getSessionRegistry, hasProjectSessionRegistry as hasSessionRegistry, ProjectSessionRegistry as SessionRegistry, } from '../session-catalog/registry.js';
5
- export type { AgentEntry, AgentLiveStatus, SessionLiveStatus, SessionRegistryEntry, SessionWebUIEndpointHint, } from '../session-registry.js';
4
+ export type { AgentEntry, AgentLiveStatus, SessionLiveStatus, SessionRegistryEntry, SessionWebUIEndpointHint, } from '../session-catalog/session-registry.js';
6
5
  /** @deprecated Test/migration adapter; production ownership uses SessionRegistry above. */
7
- export { SessionRegistry as LegacySessionRegistry } from '../session-registry.js';
6
+ export { SessionRegistry as LegacySessionRegistry } from '../session-catalog/session-registry.js';
8
7
  export type { SyncCategory, SyncConfig } from '../types/config.js';
9
8
  export type { DefaultSessionReaderOptions, SessionReader } from '../types/session-reader.js';
10
9
  export { type Annotation, AnnotationsStore, type AnnotationsStoreOptions, } from './annotations-store.js';