@cleocode/contracts 2026.5.96 → 2026.5.97
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/dist/__tests__/enums.test.d.ts +14 -0
- package/dist/__tests__/enums.test.d.ts.map +1 -0
- package/dist/__tests__/enums.test.js +75 -0
- package/dist/__tests__/enums.test.js.map +1 -0
- package/dist/__tests__/jobs.test.d.ts +11 -0
- package/dist/__tests__/jobs.test.d.ts.map +1 -0
- package/dist/__tests__/jobs.test.js +48 -0
- package/dist/__tests__/jobs.test.js.map +1 -0
- package/dist/__tests__/memory-wire-shapes.test.d.ts +19 -0
- package/dist/__tests__/memory-wire-shapes.test.d.ts.map +1 -0
- package/dist/__tests__/memory-wire-shapes.test.js +119 -0
- package/dist/__tests__/memory-wire-shapes.test.js.map +1 -0
- package/dist/__tests__/operation-def.test.d.ts +20 -0
- package/dist/__tests__/operation-def.test.d.ts.map +1 -0
- package/dist/__tests__/operation-def.test.js +111 -0
- package/dist/__tests__/operation-def.test.js.map +1 -0
- package/dist/__tests__/provenance.test.d.ts +18 -0
- package/dist/__tests__/provenance.test.d.ts.map +1 -0
- package/dist/__tests__/provenance.test.js +142 -0
- package/dist/__tests__/provenance.test.js.map +1 -0
- package/dist/__tests__/scaffold-diagnostics.test.d.ts +19 -0
- package/dist/__tests__/scaffold-diagnostics.test.d.ts.map +1 -0
- package/dist/__tests__/scaffold-diagnostics.test.js +70 -0
- package/dist/__tests__/scaffold-diagnostics.test.js.map +1 -0
- package/dist/dispatch/identity.d.ts +72 -0
- package/dist/dispatch/identity.d.ts.map +1 -0
- package/dist/dispatch/identity.js +72 -0
- package/dist/dispatch/identity.js.map +1 -0
- package/dist/dispatch/operation-def.d.ts +92 -0
- package/dist/dispatch/operation-def.d.ts.map +1 -0
- package/dist/dispatch/operation-def.js +31 -0
- package/dist/dispatch/operation-def.js.map +1 -0
- package/dist/enums.d.ts +123 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +139 -0
- package/dist/enums.js.map +1 -0
- package/dist/index.d.ts +14 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +39 -0
- package/dist/jobs.d.ts.map +1 -0
- package/dist/jobs.js +19 -0
- package/dist/jobs.js.map +1 -0
- package/dist/memory/budgeted.d.ts +67 -0
- package/dist/memory/budgeted.d.ts.map +1 -0
- package/dist/memory/budgeted.js +17 -0
- package/dist/memory/budgeted.js.map +1 -0
- package/dist/memory/fetch.d.ts +58 -0
- package/dist/memory/fetch.d.ts.map +1 -0
- package/dist/memory/fetch.js +19 -0
- package/dist/memory/fetch.js.map +1 -0
- package/dist/memory/observe.d.ts +158 -0
- package/dist/memory/observe.d.ts.map +1 -0
- package/dist/memory/observe.js +46 -0
- package/dist/memory/observe.js.map +1 -0
- package/dist/memory/search.d.ts +137 -0
- package/dist/memory/search.d.ts.map +1 -0
- package/dist/memory/search.js +22 -0
- package/dist/memory/search.js.map +1 -0
- package/dist/memory/timeline.d.ts +89 -0
- package/dist/memory/timeline.d.ts.map +1 -0
- package/dist/memory/timeline.js +22 -0
- package/dist/memory/timeline.js.map +1 -0
- package/dist/operations/focus.d.ts +199 -0
- package/dist/operations/focus.d.ts.map +1 -0
- package/dist/operations/focus.js +15 -0
- package/dist/operations/focus.js.map +1 -0
- package/dist/operations/index.d.ts +1 -0
- package/dist/operations/index.d.ts.map +1 -1
- package/dist/operations/index.js +1 -0
- package/dist/operations/index.js.map +1 -1
- package/dist/operations/session.d.ts +54 -0
- package/dist/operations/session.d.ts.map +1 -1
- package/dist/operations/tasks.d.ts +38 -0
- package/dist/operations/tasks.d.ts.map +1 -1
- package/dist/provenance.d.ts +257 -0
- package/dist/provenance.d.ts.map +1 -0
- package/dist/provenance.js +42 -0
- package/dist/provenance.js.map +1 -0
- package/dist/release/plan.d.ts +7 -7
- package/dist/scaffold-diagnostics.d.ts +110 -0
- package/dist/scaffold-diagnostics.d.ts.map +1 -0
- package/dist/scaffold-diagnostics.js +28 -0
- package/dist/scaffold-diagnostics.js.map +1 -0
- package/dist/session.d.ts +37 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/session.js.map +1 -1
- package/dist/tasks/archive.d.ts +3 -3
- package/package.json +42 -2
- package/src/__tests__/enums.test.ts +114 -0
- package/src/__tests__/jobs.test.ts +76 -0
- package/src/__tests__/memory-wire-shapes.test.ts +371 -0
- package/src/__tests__/operation-def.test.ts +185 -0
- package/src/__tests__/provenance.test.ts +259 -0
- package/src/__tests__/scaffold-diagnostics.test.ts +137 -0
- package/src/dispatch/identity.ts +109 -0
- package/src/dispatch/operation-def.ts +102 -0
- package/src/enums.ts +144 -0
- package/src/index.ts +77 -0
- package/src/jobs.ts +45 -0
- package/src/memory/budgeted.ts +75 -0
- package/src/memory/fetch.ts +66 -0
- package/src/memory/observe.ts +176 -0
- package/src/memory/search.ts +145 -0
- package/src/memory/timeline.ts +100 -0
- package/src/operations/focus.ts +226 -0
- package/src/operations/index.ts +1 -0
- package/src/operations/session.ts +56 -0
- package/src/operations/tasks.ts +40 -0
- package/src/provenance.ts +335 -0
- package/src/scaffold-diagnostics.ts +119 -0
- package/src/session.ts +37 -0
package/src/enums.ts
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical task-axis enum constants.
|
|
3
|
+
*
|
|
4
|
+
* Single source of truth for the runtime const arrays that back the
|
|
5
|
+
* task-axis discriminators (kind, scope, severity, size, archive reason,
|
|
6
|
+
* relation type). Promoted from `packages/core/src/store/tasks-schema.ts`
|
|
7
|
+
* in Phase 0c of the SG-ARCH-SOLID Saga so that downstream packages can
|
|
8
|
+
* import the values without pulling in the Drizzle schema runtime.
|
|
9
|
+
*
|
|
10
|
+
* `tasks-schema.ts` imports these arrays back for Drizzle's
|
|
11
|
+
* `text({ enum: ... })` column declarations, which preserves byte-identical
|
|
12
|
+
* row-type narrowing and produces zero schema DDL change. `tasks-schema.ts`
|
|
13
|
+
* also re-exports each constant under its original name to preserve the
|
|
14
|
+
* existing public surface for every internal `import * as schema` consumer.
|
|
15
|
+
*
|
|
16
|
+
* The corresponding union types (`TaskKind`, `TaskScope`, `TaskSeverity`,
|
|
17
|
+
* `TaskSize`, `ArchiveReasonValue`, etc.) already live in their respective
|
|
18
|
+
* domain modules (`./task.ts`, `./tasks/archive.ts`) and are re-exported
|
|
19
|
+
* from the package root.
|
|
20
|
+
*
|
|
21
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9955 (Phase 0c)
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Task kind axis — describes the intent of the work rather than its
|
|
26
|
+
* position in the hierarchy. Defaults to `'work'` to preserve semantics
|
|
27
|
+
* for tasks created before T944.
|
|
28
|
+
*
|
|
29
|
+
* Note: the DB column is named `role`; the TypeScript field is `kind`
|
|
30
|
+
* (T9067 deferral).
|
|
31
|
+
*
|
|
32
|
+
* @task T944
|
|
33
|
+
* @task T9072
|
|
34
|
+
*/
|
|
35
|
+
export const TASK_KINDS = ['work', 'research', 'experiment', 'bug', 'spike', 'release'] as const;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Task scope axis — describes the granularity of the work (project-wide
|
|
39
|
+
* vs. feature-scoped vs. unit-scoped). Orthogonal to type and kind.
|
|
40
|
+
*
|
|
41
|
+
* Backfill mapping from legacy `type` during migration:
|
|
42
|
+
* - `type='epic'` → `scope='project'`
|
|
43
|
+
* - `type='task'` → `scope='feature'` (also used for NULL legacy rows)
|
|
44
|
+
* - `type='subtask'` → `scope='unit'`
|
|
45
|
+
*
|
|
46
|
+
* @task T944
|
|
47
|
+
*/
|
|
48
|
+
export const TASK_SCOPES = ['project', 'feature', 'unit'] as const;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Task severity axis — applies to ANY task kind (not just `kind='bug'`).
|
|
52
|
+
*
|
|
53
|
+
* Enforced by a CHECK constraint:
|
|
54
|
+
* `severity IS NULL OR severity IN ('P0','P1','P2','P3')`
|
|
55
|
+
*
|
|
56
|
+
* The original T944 constraint coupled severity to `role='bug'`. T9073
|
|
57
|
+
* widened the constraint so that spikes, incidents, research tasks, and
|
|
58
|
+
* any other kind can carry a severity level. Priority and severity are
|
|
59
|
+
* fully orthogonal axes — setting severity does NOT auto-map to priority
|
|
60
|
+
* (no SEVERITY_MAP on add/update).
|
|
61
|
+
*
|
|
62
|
+
* OWNER-WRITE-ONLY (T944 / T9073 / owner mandate): severity is set
|
|
63
|
+
* through owner-authenticated paths only (signed attestation via
|
|
64
|
+
* `appendSignedSeverityAttestation`). This prevents a prompt-injection
|
|
65
|
+
* exploit where a compromised agent could mark a P0 task as P3 to
|
|
66
|
+
* force-ship.
|
|
67
|
+
*
|
|
68
|
+
* @task T944
|
|
69
|
+
* @task T9073
|
|
70
|
+
*/
|
|
71
|
+
export const TASK_SEVERITIES = ['P0', 'P1', 'P2', 'P3'] as const;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Task size sentinel values matching the DB CHECK constraint on
|
|
75
|
+
* `tasks.size`. CLEO favors qualitative sizing over time estimates
|
|
76
|
+
* (see `cleo memory` rule "No time estimates").
|
|
77
|
+
*
|
|
78
|
+
* @task T944
|
|
79
|
+
*/
|
|
80
|
+
export const TASK_SIZES = ['small', 'medium', 'large'] as const;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Truth-grade archive reason values enforced by a SQLite CHECK
|
|
84
|
+
* constraint on `tasks.archive_reason` (see migration
|
|
85
|
+
* `20260424000000_t1408-archive-reason-enum`).
|
|
86
|
+
*
|
|
87
|
+
* Council 2026-04-24 (FINDING #28 + T1407 follow-through) replaced the
|
|
88
|
+
* legacy unconstrained TEXT column with this 6-value enum. Rows that
|
|
89
|
+
* pre-dated the migration with non-conforming values (`completed`,
|
|
90
|
+
* `deleted`, etc.) were normalized to `'completed-unverified'` before
|
|
91
|
+
* the CHECK was applied, so EVERY existing row satisfies one of these
|
|
92
|
+
* literals (or is `NULL`).
|
|
93
|
+
*
|
|
94
|
+
* Semantics:
|
|
95
|
+
* - `verified` — closure passed all gates with audit-grade evidence.
|
|
96
|
+
* - `reconciled` — closure derived by reconciliation against an
|
|
97
|
+
* external source of truth (e.g. external task tracker).
|
|
98
|
+
* - `superseded` — closure because another task subsumes the work.
|
|
99
|
+
* - `shadowed` — closure because the task was experiment- or
|
|
100
|
+
* proposal-shadowed by a newer plan.
|
|
101
|
+
* - `cancelled` — closure via explicit cancellation
|
|
102
|
+
* (`status='cancelled'`).
|
|
103
|
+
* - `completed-unverified` — closure happened but verification was skipped,
|
|
104
|
+
* incomplete, or failed; metrics MUST NOT count
|
|
105
|
+
* these as quality completions without opt-in.
|
|
106
|
+
*
|
|
107
|
+
* @task T1408
|
|
108
|
+
* @epic T1407
|
|
109
|
+
*/
|
|
110
|
+
export const ARCHIVE_REASONS = [
|
|
111
|
+
'verified',
|
|
112
|
+
'reconciled',
|
|
113
|
+
'superseded',
|
|
114
|
+
'shadowed',
|
|
115
|
+
'cancelled',
|
|
116
|
+
'completed-unverified',
|
|
117
|
+
] as const;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Task relation types matching the DB CHECK constraint on
|
|
121
|
+
* `task_relations.relation_type`.
|
|
122
|
+
*
|
|
123
|
+
* - `related` — generic non-blocking association
|
|
124
|
+
* - `blocks` — source MUST complete before target can proceed
|
|
125
|
+
* - `duplicates` — source is a duplicate of target (target is canonical)
|
|
126
|
+
* - `absorbs` — source's work was absorbed into target
|
|
127
|
+
* - `fixes` — source fixes target (bug→fix linkage)
|
|
128
|
+
* - `extends` — source extends or refines target
|
|
129
|
+
* - `supersedes` — source replaces target (target is retired)
|
|
130
|
+
* - `groups` — source groups target (Saga→Epic per ADR-073)
|
|
131
|
+
*
|
|
132
|
+
* @task T944
|
|
133
|
+
* @task ADR-073 (`groups` relation for Saga membership)
|
|
134
|
+
*/
|
|
135
|
+
export const TASK_RELATION_TYPES = [
|
|
136
|
+
'related',
|
|
137
|
+
'blocks',
|
|
138
|
+
'duplicates',
|
|
139
|
+
'absorbs',
|
|
140
|
+
'fixes',
|
|
141
|
+
'extends',
|
|
142
|
+
'supersedes',
|
|
143
|
+
'groups',
|
|
144
|
+
] as const;
|
package/src/index.ts
CHANGED
|
@@ -269,6 +269,11 @@ export type {
|
|
|
269
269
|
DependencySpec,
|
|
270
270
|
} from './dependency.js';
|
|
271
271
|
export type { AdapterManifest, DetectionPattern } from './discovery.js';
|
|
272
|
+
// === Dispatch Identity Contracts (T9954 — Phase 0b of SG-ARCH-SOLID / E-CONTRACTS-FOUNDATION) ===
|
|
273
|
+
export type { CanonicalDomain, Gateway, Tier } from './dispatch/identity.js';
|
|
274
|
+
export { CANONICAL_DOMAINS } from './dispatch/identity.js';
|
|
275
|
+
// === Dispatch OperationDef + Resolution (T9954 — Phase 0b of SG-ARCH-SOLID / E-CONTRACTS-FOUNDATION) ===
|
|
276
|
+
export type { OperationDef, Resolution } from './dispatch/operation-def.js';
|
|
272
277
|
// === DocsAccessor Contracts (T9063) ===
|
|
273
278
|
export type {
|
|
274
279
|
DocExportFormat,
|
|
@@ -317,6 +322,15 @@ export {
|
|
|
317
322
|
engineSuccess,
|
|
318
323
|
unwrap,
|
|
319
324
|
} from './engine-result.js';
|
|
325
|
+
// === Task-Axis Enum Constants (T9955 — promoted from core/store/tasks-schema.ts) ===
|
|
326
|
+
export {
|
|
327
|
+
ARCHIVE_REASONS,
|
|
328
|
+
TASK_KINDS,
|
|
329
|
+
TASK_RELATION_TYPES,
|
|
330
|
+
TASK_SCOPES,
|
|
331
|
+
TASK_SEVERITIES,
|
|
332
|
+
TASK_SIZES,
|
|
333
|
+
} from './enums.js';
|
|
320
334
|
// === Error Utilities ===
|
|
321
335
|
export {
|
|
322
336
|
ClassifierUnregisteredAgentError,
|
|
@@ -444,6 +458,8 @@ export {
|
|
|
444
458
|
} from './graph.js';
|
|
445
459
|
export type { AdapterHookProvider } from './hooks.js';
|
|
446
460
|
export type { AdapterInstallProvider, InstallOptions, InstallResult } from './install.js';
|
|
461
|
+
// === Background Job Status (T9955 — promoted from core/store/tasks-schema.ts) ===
|
|
462
|
+
export type { BackgroundJobStatus } from './jobs.js';
|
|
447
463
|
export type {
|
|
448
464
|
CleoResponse,
|
|
449
465
|
ConformanceReport,
|
|
@@ -530,8 +546,37 @@ export type {
|
|
|
530
546
|
export type { ResolvedCredential } from './llm/resolved-credential.js';
|
|
531
547
|
// === Logger contract (T9766 — centralized from @cleocode/core) ===
|
|
532
548
|
export type { LoggerConfig } from './logger.js';
|
|
549
|
+
// === BRAIN memory wire-shape contracts (T9956 — promoted from @cleocode/core) ===
|
|
550
|
+
export type {
|
|
551
|
+
BudgetedEntry,
|
|
552
|
+
BudgetedResult,
|
|
553
|
+
BudgetedRetrievalOptions,
|
|
554
|
+
} from './memory/budgeted.js';
|
|
533
555
|
// === ContextEngine contract (canonical home — T9304) ===
|
|
534
556
|
export type { CompressedContext, ContextEngine } from './memory/context-engine.js';
|
|
557
|
+
export type {
|
|
558
|
+
FetchBrainEntriesParams,
|
|
559
|
+
FetchBrainEntriesResult,
|
|
560
|
+
FetchedBrainEntry,
|
|
561
|
+
} from './memory/fetch.js';
|
|
562
|
+
export type {
|
|
563
|
+
BrainObservationSourceType,
|
|
564
|
+
DocAttachmentObservationPayload,
|
|
565
|
+
ObserveBrainParams,
|
|
566
|
+
ObserveBrainResult,
|
|
567
|
+
} from './memory/observe.js';
|
|
568
|
+
export { BRAIN_OBSERVATION_SOURCE_TYPES } from './memory/observe.js';
|
|
569
|
+
export type {
|
|
570
|
+
BrainCompactHit,
|
|
571
|
+
SearchBrainCompactParams,
|
|
572
|
+
SearchBrainCompactResult,
|
|
573
|
+
} from './memory/search.js';
|
|
574
|
+
export type {
|
|
575
|
+
BrainAnchor,
|
|
576
|
+
TimelineBrainParams,
|
|
577
|
+
TimelineBrainResult,
|
|
578
|
+
TimelineNeighbor,
|
|
579
|
+
} from './memory/timeline.js';
|
|
535
580
|
export type {
|
|
536
581
|
BridgeDecision,
|
|
537
582
|
BridgeLearning,
|
|
@@ -1047,6 +1092,7 @@ export type {
|
|
|
1047
1092
|
DepGraphIssue,
|
|
1048
1093
|
DepsTreeEdge,
|
|
1049
1094
|
DepsTreeNode,
|
|
1095
|
+
TaskShowAttachmentEntry,
|
|
1050
1096
|
TasksAddBatchParams,
|
|
1051
1097
|
TasksAddBatchResult,
|
|
1052
1098
|
TasksAddParams,
|
|
@@ -1283,6 +1329,30 @@ export type {
|
|
|
1283
1329
|
ProjectType,
|
|
1284
1330
|
TestFramework,
|
|
1285
1331
|
} from './project-context.js';
|
|
1332
|
+
// === Provenance Graph Unions (T9955 — promoted from core/store/tasks-schema.ts) ===
|
|
1333
|
+
// Note: ReleaseChannel/ReleaseKind/ReleaseScheme/ReleaseStatus collide with the
|
|
1334
|
+
// existing `./release/channel.js` + `./release/plan.js` + `./task.js` exports
|
|
1335
|
+
// (different domains, different value sets). The colliding 4 are re-exported
|
|
1336
|
+
// here under `Provenance…`-qualified aliases. The other 12 keep their natural
|
|
1337
|
+
// names — they are unique across the package.
|
|
1338
|
+
export type {
|
|
1339
|
+
BrainReleaseLinkType,
|
|
1340
|
+
CommitConventionalType,
|
|
1341
|
+
CommitFileChangeType,
|
|
1342
|
+
CommitLinkKind,
|
|
1343
|
+
CommitLinkSource,
|
|
1344
|
+
PrLinkKind,
|
|
1345
|
+
PrLinkSource,
|
|
1346
|
+
PrState,
|
|
1347
|
+
ReleaseArtifactType,
|
|
1348
|
+
ReleaseChangeType,
|
|
1349
|
+
ReleaseChannel as ProvenanceReleaseChannel,
|
|
1350
|
+
ReleaseClassifiedBy,
|
|
1351
|
+
ReleaseImpact,
|
|
1352
|
+
ReleaseKind as ProvenanceReleaseKind,
|
|
1353
|
+
ReleaseScheme as ProvenanceReleaseScheme,
|
|
1354
|
+
ReleaseStatus as ProvenanceReleaseStatus,
|
|
1355
|
+
} from './provenance.js';
|
|
1286
1356
|
export type { AdapterPathProvider } from './provider-paths.js';
|
|
1287
1357
|
// === Release Channel ===
|
|
1288
1358
|
export type { ChannelValidationResult, ReleaseChannel } from './release/channel.js';
|
|
@@ -1409,6 +1479,13 @@ export type {
|
|
|
1409
1479
|
TaskRefPriority,
|
|
1410
1480
|
TaskSummary,
|
|
1411
1481
|
} from './results.js';
|
|
1482
|
+
// === Scaffold + Diagnostic Result Types (SG-ARCH-SOLID T9831 / E-CONTRACTS-FOUNDATION T9832) ===
|
|
1483
|
+
export type {
|
|
1484
|
+
CheckResult,
|
|
1485
|
+
CheckStatus,
|
|
1486
|
+
HookCheckResult,
|
|
1487
|
+
ScaffoldResult,
|
|
1488
|
+
} from './scaffold-diagnostics.js';
|
|
1412
1489
|
// === SDK Tool Contract (Category B harness-agnostic SDK utilities — T1768 / ADR-064) ===
|
|
1413
1490
|
export type { SdkTool, SdkToolIdentity } from './sdk-tool.js';
|
|
1414
1491
|
// === Sentient Tier-2 Types (T1008) ===
|
package/src/jobs.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background job contracts.
|
|
3
|
+
*
|
|
4
|
+
* Canonical home for the durable-job lifecycle types. Promoted from
|
|
5
|
+
* `packages/core/src/store/tasks-schema.ts` in Phase 0c of the
|
|
6
|
+
* SG-ARCH-SOLID Saga so that the cleo dispatch layer
|
|
7
|
+
* (`@cleocode/cleo/dispatch/lib/background-jobs.ts`) can import the
|
|
8
|
+
* status union without pulling in the Drizzle schema runtime.
|
|
9
|
+
*
|
|
10
|
+
* The `BACKGROUND_JOB_STATUSES` const array remains in `tasks-schema.ts`
|
|
11
|
+
* because Drizzle's `text({ enum: ... })` column declaration narrows the
|
|
12
|
+
* runtime row type directly from that `as const` literal. `tasks-schema.ts`
|
|
13
|
+
* re-exports {@link BackgroundJobStatus} from this module to preserve the
|
|
14
|
+
* existing public surface.
|
|
15
|
+
*
|
|
16
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9955 (Phase 0c)
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Lifecycle status of a durable background job persisted in `tasks.db`.
|
|
21
|
+
*
|
|
22
|
+
* - `pending` — created but not yet picked up by a worker
|
|
23
|
+
* - `running` — actively executing; emits heartbeats
|
|
24
|
+
* - `complete` — finished successfully (`result` populated, `error` NULL)
|
|
25
|
+
* - `failed` — finished with an error (`error` populated, `result` NULL)
|
|
26
|
+
* - `cancelled` — explicitly cancelled by a caller
|
|
27
|
+
* - `orphaned` — was `running` when the process exited; requires human/agent review
|
|
28
|
+
*
|
|
29
|
+
* Jobs survive process restart; any row with `status='running'` at startup
|
|
30
|
+
* is transitioned to `status='orphaned'` so humans/agents can triage them.
|
|
31
|
+
*
|
|
32
|
+
* @task T641
|
|
33
|
+
* @remarks
|
|
34
|
+
* The values here MUST stay aligned with `BACKGROUND_JOB_STATUSES` in
|
|
35
|
+
* `tasks-schema.ts`; that const array drives the Drizzle row type. A
|
|
36
|
+
* compile-time structural assertion in
|
|
37
|
+
* `packages/contracts/src/__tests__/jobs.test.ts` pins both sides.
|
|
38
|
+
*/
|
|
39
|
+
export type BackgroundJobStatus =
|
|
40
|
+
| 'pending'
|
|
41
|
+
| 'running'
|
|
42
|
+
| 'complete'
|
|
43
|
+
| 'failed'
|
|
44
|
+
| 'cancelled'
|
|
45
|
+
| 'orphaned';
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Budget-aware BRAIN retrieval wire shapes.
|
|
3
|
+
*
|
|
4
|
+
* Canonical home for the parameters and result types of the public
|
|
5
|
+
* `retrieveWithBudget` operation — hybrid (FTS5 + vector KNN + graph) BRAIN
|
|
6
|
+
* search with token-bounded result accounting. Used by the session-briefing
|
|
7
|
+
* pipeline (`buildRetrievalBundle`) to assemble cross-table context within
|
|
8
|
+
* a caller-specified token budget.
|
|
9
|
+
*
|
|
10
|
+
* Promoted from `packages/core/src/memory/brain-retrieval.ts` (T549
|
|
11
|
+
* Wave 3-A region, lines 1305-1340) to `@cleocode/contracts` in Phase 0e
|
|
12
|
+
* of SG-ARCH-SOLID (E-CONTRACTS-FOUNDATION).
|
|
13
|
+
*
|
|
14
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// ── BudgetedRetrievalOptions ────────────────────────────────────────
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Optional filters for `retrieveWithBudget`.
|
|
21
|
+
*
|
|
22
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
23
|
+
*/
|
|
24
|
+
export interface BudgetedRetrievalOptions {
|
|
25
|
+
/** Filter by cognitive types (semantic / episodic / procedural). */
|
|
26
|
+
types?: Array<'semantic' | 'episodic' | 'procedural'>;
|
|
27
|
+
/** Filter by memory tiers (short / medium / long). */
|
|
28
|
+
tiers?: Array<'short' | 'medium' | 'long'>;
|
|
29
|
+
/** When true, only return verified entries. Default: false. */
|
|
30
|
+
verified?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// ── BudgetedEntry ───────────────────────────────────────────────────
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* A single entry returned by `retrieveWithBudget`.
|
|
37
|
+
*
|
|
38
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
39
|
+
*/
|
|
40
|
+
export interface BudgetedEntry {
|
|
41
|
+
/** Entry identifier. */
|
|
42
|
+
id: string;
|
|
43
|
+
/** Source BRAIN table (e.g. `observation`, `decision`, `pattern`, `learning`). */
|
|
44
|
+
type: string;
|
|
45
|
+
/** Display title for the entry. */
|
|
46
|
+
title: string;
|
|
47
|
+
/** Full text payload (narrative / decision text / pattern body / learning insight). */
|
|
48
|
+
text: string;
|
|
49
|
+
/** Fused relevance score: FTS50% + vector40% + graph10% × qualityScore. */
|
|
50
|
+
score: number;
|
|
51
|
+
/** Estimated token cost for this entry (~chars/4). */
|
|
52
|
+
tokensEstimated: number;
|
|
53
|
+
/** Memory tier for this entry. */
|
|
54
|
+
memoryTier?: string;
|
|
55
|
+
/** Cognitive type for this entry. */
|
|
56
|
+
memoryType?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ── BudgetedResult ──────────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Result envelope returned by `retrieveWithBudget`.
|
|
63
|
+
*
|
|
64
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
65
|
+
*/
|
|
66
|
+
export interface BudgetedResult {
|
|
67
|
+
/** Entries selected within the requested token budget, ranked by fused score. */
|
|
68
|
+
entries: BudgetedEntry[];
|
|
69
|
+
/** Total tokens consumed by returned entries. */
|
|
70
|
+
tokensUsed: number;
|
|
71
|
+
/** Tokens remaining from the original budget. */
|
|
72
|
+
tokensRemaining: number;
|
|
73
|
+
/** Number of entries excluded due to budget constraints. */
|
|
74
|
+
excluded: number;
|
|
75
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BRAIN entry-fetch wire shapes.
|
|
3
|
+
*
|
|
4
|
+
* Canonical home for the parameters and result types of the public
|
|
5
|
+
* `fetchBrainEntries` operation — Layer 3 of CLEO's 3-layer BRAIN retrieval
|
|
6
|
+
* pattern (search → timeline → fetch). Returns the full row payload for a
|
|
7
|
+
* caller-supplied list of IDs, typically derived from a prior `searchBrainCompact`
|
|
8
|
+
* or `timelineBrain` call.
|
|
9
|
+
*
|
|
10
|
+
* Promoted from `packages/core/src/memory/brain-retrieval.ts` to
|
|
11
|
+
* `@cleocode/contracts` in Phase 0e of SG-ARCH-SOLID
|
|
12
|
+
* (E-CONTRACTS-FOUNDATION).
|
|
13
|
+
*
|
|
14
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
15
|
+
* @see Layer 1: {@link ./search.ts}
|
|
16
|
+
* @see Layer 2: {@link ./timeline.ts}
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// ── FetchBrainEntriesParams ─────────────────────────────────────────
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Parameters for `fetchBrainEntries`.
|
|
23
|
+
*
|
|
24
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
25
|
+
*/
|
|
26
|
+
export interface FetchBrainEntriesParams {
|
|
27
|
+
/** Entry identifiers to fetch in a single batch. */
|
|
28
|
+
ids: string[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// ── FetchedBrainEntry ───────────────────────────────────────────────
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A single fetched entry with its full row payload.
|
|
35
|
+
*
|
|
36
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
37
|
+
*/
|
|
38
|
+
export interface FetchedBrainEntry {
|
|
39
|
+
/** Entry identifier. */
|
|
40
|
+
id: string;
|
|
41
|
+
/** Source BRAIN table (e.g. `observation`, `decision`, `pattern`, `learning`). */
|
|
42
|
+
type: string;
|
|
43
|
+
/**
|
|
44
|
+
* Raw row payload as returned by the underlying SQL query.
|
|
45
|
+
*
|
|
46
|
+
* Typed as `unknown` because the shape varies by `type`. Callers narrow
|
|
47
|
+
* via a discriminated read or pass the value through to a renderer.
|
|
48
|
+
*/
|
|
49
|
+
data: unknown;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ── FetchBrainEntriesResult ─────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Result envelope returned by `fetchBrainEntries`.
|
|
56
|
+
*
|
|
57
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
58
|
+
*/
|
|
59
|
+
export interface FetchBrainEntriesResult {
|
|
60
|
+
/** Resolved entries, in the order they were found (not necessarily input order). */
|
|
61
|
+
results: FetchedBrainEntry[];
|
|
62
|
+
/** Entry identifiers that could not be resolved against any BRAIN table. */
|
|
63
|
+
notFound: string[];
|
|
64
|
+
/** Approximate token cost of the returned payload (~chars/4). */
|
|
65
|
+
tokensEstimated: number;
|
|
66
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BRAIN observation-write wire shapes.
|
|
3
|
+
*
|
|
4
|
+
* Canonical home for the parameters and result types of the public
|
|
5
|
+
* `observeBrain` operation — the unified BRAIN write path that persists
|
|
6
|
+
* agent observations into `brain_observations`. Companion to the
|
|
7
|
+
* read-side trio in {@link ./search.ts}, {@link ./timeline.ts}, and
|
|
8
|
+
* {@link ./fetch.ts}.
|
|
9
|
+
*
|
|
10
|
+
* The `BRAIN_OBSERVATION_SOURCE_TYPES` const is co-located here so the
|
|
11
|
+
* derived `BrainObservationSourceType` union has a single source of truth.
|
|
12
|
+
* `packages/core/src/store/memory-schema.ts` re-exports the const for
|
|
13
|
+
* Drizzle's `enum: [...]` column constraint, which requires the runtime
|
|
14
|
+
* tuple literal.
|
|
15
|
+
*
|
|
16
|
+
* Promoted from `packages/core/src/memory/brain-retrieval.ts` to
|
|
17
|
+
* `@cleocode/contracts` in Phase 0e of SG-ARCH-SOLID
|
|
18
|
+
* (E-CONTRACTS-FOUNDATION).
|
|
19
|
+
*
|
|
20
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import type { BrainSourceConfidence } from '../brain.js';
|
|
24
|
+
import type { BrainObservationType } from '../facade.js';
|
|
25
|
+
|
|
26
|
+
// ── BRAIN_OBSERVATION_SOURCE_TYPES + BrainObservationSourceType ─────
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Source-type tuple for `brain_observations.source_type` — how the
|
|
30
|
+
* observation was created.
|
|
31
|
+
*
|
|
32
|
+
* Originally defined in `packages/core/src/store/memory-schema.ts:134`.
|
|
33
|
+
* Promoted here so the derived {@link BrainObservationSourceType} union
|
|
34
|
+
* lives alongside its source. `memory-schema.ts` re-exports the const
|
|
35
|
+
* because Drizzle's `{ enum: ... }` column constraint requires the runtime
|
|
36
|
+
* tuple literal.
|
|
37
|
+
*
|
|
38
|
+
* - `agent` — produced by a spawned agent at task time.
|
|
39
|
+
* - `session-debrief` — synthesized at session end by the debrief pipeline.
|
|
40
|
+
* - `claude-mem` — imported from a claude-mem migration batch.
|
|
41
|
+
* - `manual` — typed directly by the owner via `cleo memory observe`.
|
|
42
|
+
*
|
|
43
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
44
|
+
*/
|
|
45
|
+
export const BRAIN_OBSERVATION_SOURCE_TYPES = [
|
|
46
|
+
'agent',
|
|
47
|
+
'session-debrief',
|
|
48
|
+
'claude-mem',
|
|
49
|
+
'manual',
|
|
50
|
+
] as const;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Derived string-literal union of valid `source_type` values.
|
|
54
|
+
*
|
|
55
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
56
|
+
*/
|
|
57
|
+
export type BrainObservationSourceType = (typeof BRAIN_OBSERVATION_SOURCE_TYPES)[number];
|
|
58
|
+
|
|
59
|
+
// ── ObserveBrainParams ──────────────────────────────────────────────
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Parameters for `observeBrain`.
|
|
63
|
+
*
|
|
64
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
65
|
+
*/
|
|
66
|
+
export interface ObserveBrainParams {
|
|
67
|
+
/** Observation narrative — the free-form text persisted to `brain_observations.narrative`. */
|
|
68
|
+
text: string;
|
|
69
|
+
/** Optional display title; auto-derived from `text` when omitted. */
|
|
70
|
+
title?: string;
|
|
71
|
+
/** Optional cognitive observation type (`feature`, `bugfix`, `decision`, …). */
|
|
72
|
+
type?: BrainObservationType;
|
|
73
|
+
/** Optional project scope ID; defaults to the current project root. */
|
|
74
|
+
project?: string;
|
|
75
|
+
/** Session ID that produced the observation (provenance). */
|
|
76
|
+
sourceSessionId?: string;
|
|
77
|
+
/** How the observation was created (default `agent`). */
|
|
78
|
+
sourceType?: BrainObservationSourceType;
|
|
79
|
+
/** T417: agent provenance — the name of the spawned agent producing this observation. */
|
|
80
|
+
agent?: string;
|
|
81
|
+
/**
|
|
82
|
+
* T549 Wave 1-A: source reliability level.
|
|
83
|
+
* Overrides the default routing. If omitted, routing is determined automatically:
|
|
84
|
+
* - sourceType 'manual' → 'owner'
|
|
85
|
+
* - sourceType 'session-debrief' → 'task-outcome'
|
|
86
|
+
* - otherwise → 'agent'
|
|
87
|
+
*/
|
|
88
|
+
sourceConfidence?: BrainSourceConfidence;
|
|
89
|
+
/**
|
|
90
|
+
* T794 BRAIN-05: cross-references to other memory entries or external IDs.
|
|
91
|
+
* When this array has ≥1 entry, the observation is auto-promoted from
|
|
92
|
+
* 'short' to 'medium' tier at write time to protect it from soft-eviction.
|
|
93
|
+
*/
|
|
94
|
+
crossRef?: string[];
|
|
95
|
+
/**
|
|
96
|
+
* T799: SHA-256 refs of attachments to link to this observation.
|
|
97
|
+
*
|
|
98
|
+
* Stored as a JSON-encoded string in the `attachments_json` column.
|
|
99
|
+
* Each entry must be a 64-char hex SHA-256 from the tasks.db attachment store.
|
|
100
|
+
*/
|
|
101
|
+
attachmentRefs?: string[];
|
|
102
|
+
/**
|
|
103
|
+
* T1897: Producer pipeline that created this observation.
|
|
104
|
+
* - `manual` — typed directly by owner
|
|
105
|
+
* - `auto-extract` — from fulfillPromotionLog / LLM extraction
|
|
106
|
+
* - `transcript-ingest`— imported from raw session transcript
|
|
107
|
+
* - `session-debrief` — synthesized at session end
|
|
108
|
+
* - `test` — inserted by test code
|
|
109
|
+
*
|
|
110
|
+
* Null on legacy rows and when not specified.
|
|
111
|
+
*/
|
|
112
|
+
origin?: string | null;
|
|
113
|
+
/**
|
|
114
|
+
* T1897: JSON array of source brain_observations.id values this row was derived from.
|
|
115
|
+
* Null for directly-observed rows.
|
|
116
|
+
*/
|
|
117
|
+
provenanceChain?: string[] | null;
|
|
118
|
+
/**
|
|
119
|
+
* T992: Internal flag — when true, bypasses the verifyAndStore gate.
|
|
120
|
+
* Set only by storeVerifiedCandidate in extraction-gate.ts to avoid
|
|
121
|
+
* infinite recursion (gate → storeVerifiedCandidate → observeBrain → gate).
|
|
122
|
+
* External callers MUST NOT set this flag.
|
|
123
|
+
*/
|
|
124
|
+
_skipGate?: boolean;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ── ObserveBrainResult ──────────────────────────────────────────────
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Result envelope returned by `observeBrain`.
|
|
131
|
+
*
|
|
132
|
+
* @since SG-ARCH-SOLID Saga T9831 · E-CONTRACTS-FOUNDATION T9832 · T9956 (Phase 0e)
|
|
133
|
+
*/
|
|
134
|
+
export interface ObserveBrainResult {
|
|
135
|
+
/** Identifier of the newly-persisted observation row. */
|
|
136
|
+
id: string;
|
|
137
|
+
/** Resolved BRAIN table name (always `observation` for `observeBrain`). */
|
|
138
|
+
type: string;
|
|
139
|
+
/** ISO 8601 creation timestamp. */
|
|
140
|
+
createdAt: string;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// ── DocAttachmentObservationPayload ─────────────────────────────────
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Structured payload stored in the `narrative` of a doc-attachment memory
|
|
147
|
+
* observation emitted by `cleo docs add` (T9976).
|
|
148
|
+
*
|
|
149
|
+
* The observation title is `"Doc attached: <slug>"` (or
|
|
150
|
+
* `"Doc attached: <attachmentId>"` when no slug is set) so
|
|
151
|
+
* `cleo memory find '<slug>'` reliably surfaces the entry via FTS.
|
|
152
|
+
*
|
|
153
|
+
* The payload is serialised as JSON and embedded in the observation
|
|
154
|
+
* `narrative` field so it can be recovered by `cleo memory verify`
|
|
155
|
+
* for round-trip attachment-existence checks.
|
|
156
|
+
*
|
|
157
|
+
* @task T9976
|
|
158
|
+
*/
|
|
159
|
+
export interface DocAttachmentObservationPayload {
|
|
160
|
+
/** Slug recorded for this attachment (optional — omitted when none set). */
|
|
161
|
+
slug?: string;
|
|
162
|
+
/** Owner entity ID (task, session, observation, …). */
|
|
163
|
+
ownerId: string;
|
|
164
|
+
/** Taxonomy type classification (optional). */
|
|
165
|
+
type?: string;
|
|
166
|
+
/** Attachment ID assigned by the store. */
|
|
167
|
+
attachmentId: string;
|
|
168
|
+
/** ISO 8601 timestamp when the attachment was added. */
|
|
169
|
+
addedAt: string;
|
|
170
|
+
/**
|
|
171
|
+
* Observation kind discriminator — always `"doc-attachment"`.
|
|
172
|
+
* Used by `cleo memory verify` to identify doc-attachment observations
|
|
173
|
+
* and perform round-trip checks against the docs store.
|
|
174
|
+
*/
|
|
175
|
+
kind: 'doc-attachment';
|
|
176
|
+
}
|