@cleocode/contracts 2026.5.129 → 2026.5.131

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 (175) hide show
  1. package/dist/__tests__/atomic-tools-contract.test.d.ts +14 -0
  2. package/dist/__tests__/atomic-tools-contract.test.d.ts.map +1 -0
  3. package/dist/__tests__/atomic-tools-contract.test.js +55 -0
  4. package/dist/__tests__/atomic-tools-contract.test.js.map +1 -0
  5. package/dist/__tests__/gateway-contract.test.d.ts +18 -0
  6. package/dist/__tests__/gateway-contract.test.d.ts.map +1 -0
  7. package/dist/__tests__/gateway-contract.test.js +187 -0
  8. package/dist/__tests__/gateway-contract.test.js.map +1 -0
  9. package/dist/__tests__/mvi.test.d.ts +17 -0
  10. package/dist/__tests__/mvi.test.d.ts.map +1 -0
  11. package/dist/__tests__/mvi.test.js +147 -0
  12. package/dist/__tests__/mvi.test.js.map +1 -0
  13. package/dist/__tests__/operation-def.test.js +1 -1
  14. package/dist/__tests__/operation-def.test.js.map +1 -1
  15. package/dist/boundary.d.ts +26 -0
  16. package/dist/boundary.d.ts.map +1 -1
  17. package/dist/boundary.js +42 -4
  18. package/dist/boundary.js.map +1 -1
  19. package/dist/branch-lock.d.ts +35 -1
  20. package/dist/branch-lock.d.ts.map +1 -1
  21. package/dist/branch-lock.js +23 -2
  22. package/dist/branch-lock.js.map +1 -1
  23. package/dist/daemon/__tests__/health-roundtrip.test.d.ts +13 -0
  24. package/dist/daemon/__tests__/health-roundtrip.test.d.ts.map +1 -0
  25. package/dist/daemon/__tests__/health-roundtrip.test.js +69 -0
  26. package/dist/daemon/__tests__/health-roundtrip.test.js.map +1 -0
  27. package/dist/daemon/health.d.ts +108 -0
  28. package/dist/daemon/health.d.ts.map +1 -0
  29. package/dist/daemon/health.js +95 -0
  30. package/dist/daemon/health.js.map +1 -0
  31. package/dist/daemon/index.d.ts +24 -0
  32. package/dist/daemon/index.d.ts.map +1 -0
  33. package/dist/daemon/index.js +22 -0
  34. package/dist/daemon/index.js.map +1 -0
  35. package/dist/daemon/subsystem.d.ts +121 -0
  36. package/dist/daemon/subsystem.d.ts.map +1 -0
  37. package/dist/daemon/subsystem.js +28 -0
  38. package/dist/daemon/subsystem.js.map +1 -0
  39. package/dist/daemon-ipc/__tests__/daemon-ipc-freeze.test.d.ts +15 -0
  40. package/dist/daemon-ipc/__tests__/daemon-ipc-freeze.test.d.ts.map +1 -0
  41. package/dist/daemon-ipc/__tests__/daemon-ipc-freeze.test.js +40 -0
  42. package/dist/daemon-ipc/__tests__/daemon-ipc-freeze.test.js.map +1 -0
  43. package/dist/daemon-ipc/index.d.ts +44 -0
  44. package/dist/daemon-ipc/index.d.ts.map +1 -0
  45. package/dist/daemon-ipc/index.js +43 -0
  46. package/dist/daemon-ipc/index.js.map +1 -0
  47. package/dist/db-inventory.json +8 -8
  48. package/dist/dispatch/identity.d.ts +1 -1
  49. package/dist/dispatch/identity.d.ts.map +1 -1
  50. package/dist/dispatch/identity.js +3 -0
  51. package/dist/dispatch/identity.js.map +1 -1
  52. package/dist/dispatch/operation-def.d.ts +16 -0
  53. package/dist/dispatch/operation-def.d.ts.map +1 -1
  54. package/dist/dispatch/operations-registry.d.ts.map +1 -1
  55. package/dist/dispatch/operations-registry.js +133 -0
  56. package/dist/dispatch/operations-registry.js.map +1 -1
  57. package/dist/exit-codes.d.ts +1 -1
  58. package/dist/exit-codes.js +1 -1
  59. package/dist/gateway/rpc/__tests__/freeze.test.d.ts +20 -0
  60. package/dist/gateway/rpc/__tests__/freeze.test.d.ts.map +1 -0
  61. package/dist/gateway/rpc/__tests__/freeze.test.js +122 -0
  62. package/dist/gateway/rpc/__tests__/freeze.test.js.map +1 -0
  63. package/dist/gateway/rpc/index.d.ts +23 -0
  64. package/dist/gateway/rpc/index.d.ts.map +1 -0
  65. package/dist/gateway/rpc/index.js +22 -0
  66. package/dist/gateway/rpc/index.js.map +1 -0
  67. package/dist/gateway/rpc/messages.d.ts +263 -0
  68. package/dist/gateway/rpc/messages.d.ts.map +1 -0
  69. package/dist/gateway/rpc/messages.js +152 -0
  70. package/dist/gateway/rpc/messages.js.map +1 -0
  71. package/dist/gateway/rpc/version.d.ts +39 -0
  72. package/dist/gateway/rpc/version.d.ts.map +1 -0
  73. package/dist/gateway/rpc/version.js +39 -0
  74. package/dist/gateway/rpc/version.js.map +1 -0
  75. package/dist/gateway.d.ts +239 -0
  76. package/dist/gateway.d.ts.map +1 -0
  77. package/dist/gateway.js +171 -0
  78. package/dist/gateway.js.map +1 -0
  79. package/dist/goal.d.ts +314 -0
  80. package/dist/goal.d.ts.map +1 -0
  81. package/dist/goal.js +118 -0
  82. package/dist/goal.js.map +1 -0
  83. package/dist/index.d.ts +9 -0
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +10 -0
  86. package/dist/index.js.map +1 -1
  87. package/dist/mvi.d.ts +209 -0
  88. package/dist/mvi.d.ts.map +1 -0
  89. package/dist/mvi.js +99 -0
  90. package/dist/mvi.js.map +1 -0
  91. package/dist/operations/attention.d.ts +114 -0
  92. package/dist/operations/attention.d.ts.map +1 -0
  93. package/dist/operations/attention.js +22 -0
  94. package/dist/operations/attention.js.map +1 -0
  95. package/dist/operations/docs.d.ts +7 -1
  96. package/dist/operations/docs.d.ts.map +1 -1
  97. package/dist/operations/docs.js.map +1 -1
  98. package/dist/operations/focus.d.ts +25 -0
  99. package/dist/operations/focus.d.ts.map +1 -1
  100. package/dist/operations/index.d.ts +1 -0
  101. package/dist/operations/index.d.ts.map +1 -1
  102. package/dist/operations/index.js +1 -0
  103. package/dist/operations/index.js.map +1 -1
  104. package/dist/operations/session.d.ts +11 -0
  105. package/dist/operations/session.d.ts.map +1 -1
  106. package/dist/sdk-tool.d.ts +1 -1
  107. package/dist/sdk-tool.js +1 -1
  108. package/dist/supervisor-ipc/__tests__/freeze.test.d.ts +15 -0
  109. package/dist/supervisor-ipc/__tests__/freeze.test.d.ts.map +1 -0
  110. package/dist/supervisor-ipc/__tests__/freeze.test.js +159 -0
  111. package/dist/supervisor-ipc/__tests__/freeze.test.js.map +1 -0
  112. package/dist/supervisor-ipc/index.d.ts +15 -0
  113. package/dist/supervisor-ipc/index.d.ts.map +1 -0
  114. package/dist/supervisor-ipc/index.js +14 -0
  115. package/dist/supervisor-ipc/index.js.map +1 -0
  116. package/dist/supervisor-ipc/messages.d.ts +457 -0
  117. package/dist/supervisor-ipc/messages.d.ts.map +1 -0
  118. package/dist/supervisor-ipc/messages.js +312 -0
  119. package/dist/supervisor-ipc/messages.js.map +1 -0
  120. package/dist/supervisor-ipc/version.d.ts +29 -0
  121. package/dist/supervisor-ipc/version.d.ts.map +1 -0
  122. package/dist/supervisor-ipc/version.js +29 -0
  123. package/dist/supervisor-ipc/version.js.map +1 -0
  124. package/dist/tools/__tests__/composite.test.d.ts +14 -0
  125. package/dist/tools/__tests__/composite.test.d.ts.map +1 -0
  126. package/dist/tools/__tests__/composite.test.js +75 -0
  127. package/dist/tools/__tests__/composite.test.js.map +1 -0
  128. package/dist/tools/atomic.d.ts +195 -0
  129. package/dist/tools/atomic.d.ts.map +1 -0
  130. package/dist/tools/atomic.js +82 -0
  131. package/dist/tools/atomic.js.map +1 -0
  132. package/dist/tools/composite.d.ts +128 -0
  133. package/dist/tools/composite.d.ts.map +1 -0
  134. package/dist/tools/composite.js +88 -0
  135. package/dist/tools/composite.js.map +1 -0
  136. package/package.json +35 -3
  137. package/src/__tests__/__snapshots__/operations-registry.test.ts.snap +1 -1
  138. package/src/__tests__/atomic-tools-contract.test.ts +67 -0
  139. package/src/__tests__/gateway-contract.test.ts +219 -0
  140. package/src/__tests__/mvi.test.ts +175 -0
  141. package/src/__tests__/operation-def.test.ts +2 -1
  142. package/src/boundary.ts +74 -4
  143. package/src/branch-lock.ts +49 -2
  144. package/src/daemon/__tests__/health-roundtrip.test.ts +84 -0
  145. package/src/daemon/health.ts +121 -0
  146. package/src/daemon/index.ts +35 -0
  147. package/src/daemon/subsystem.ts +126 -0
  148. package/src/daemon-ipc/__tests__/daemon-ipc-freeze.test.ts +53 -0
  149. package/src/daemon-ipc/index.ts +90 -0
  150. package/src/db-inventory.json +8 -8
  151. package/src/dispatch/identity.ts +3 -0
  152. package/src/dispatch/operation-def.ts +16 -0
  153. package/src/dispatch/operations-registry.ts +140 -0
  154. package/src/exit-codes.ts +1 -1
  155. package/src/gateway/rpc/__tests__/freeze.test.ts +139 -0
  156. package/src/gateway/rpc/index.ts +43 -0
  157. package/src/gateway/rpc/messages.ts +187 -0
  158. package/src/gateway/rpc/version.ts +40 -0
  159. package/src/gateway.ts +252 -0
  160. package/src/goal.ts +348 -0
  161. package/src/index.ts +109 -0
  162. package/src/mvi.ts +236 -0
  163. package/src/operations/attention.ts +117 -0
  164. package/src/operations/docs.ts +7 -1
  165. package/src/operations/focus.ts +26 -0
  166. package/src/operations/index.ts +1 -0
  167. package/src/operations/session.ts +11 -0
  168. package/src/sdk-tool.ts +1 -1
  169. package/src/supervisor-ipc/__tests__/freeze.test.ts +180 -0
  170. package/src/supervisor-ipc/index.ts +62 -0
  171. package/src/supervisor-ipc/messages.ts +396 -0
  172. package/src/supervisor-ipc/version.ts +30 -0
  173. package/src/tools/__tests__/composite.test.ts +88 -0
  174. package/src/tools/atomic.ts +274 -0
  175. package/src/tools/composite.ts +173 -0
package/src/index.ts CHANGED
@@ -288,6 +288,29 @@ export type {
288
288
  ParsedClaudeCodeCredential,
289
289
  } from './credentials.js';
290
290
  export { parseClaudeCodeCredentials } from './credentials.js';
291
+ // === Daemon lifecycle + subsystem contracts (T11366 · SG-RUNTIME-UNIFICATION R2) ===
292
+ export type {
293
+ DaemonLifecycleHooks,
294
+ HealthStatus,
295
+ Subsystem,
296
+ SubsystemDefinition,
297
+ SubsystemHealth,
298
+ SubsystemLifecyclePhase,
299
+ SubsystemState,
300
+ } from './daemon/index.js';
301
+ export {
302
+ HealthStatusSchema,
303
+ SUBSYSTEM_LIFECYCLE_PHASES,
304
+ SubsystemHealthSchema,
305
+ SubsystemStateSchema,
306
+ summarizeHealth,
307
+ toMonitorChildren,
308
+ } from './daemon/index.js';
309
+ // === Daemon-IPC v1.0 (AC8 alias of supervisor-ipc — T11369 · R2 gates R4-R7) ===
310
+ // `daemon-ipc` is the AC8-named re-export barrel over the FROZEN supervisor-ipc
311
+ // v1.0 contract — one contract, two names. The subpath
312
+ // `@cleocode/contracts/daemon-ipc` resolves via the package `./*` export.
313
+ export { DAEMON_IPC_PROTOCOL_VERSION } from './daemon-ipc/index.js';
291
314
  // === DataAccessor Interface ===
292
315
  export type {
293
316
  AcBindingRow,
@@ -610,6 +633,28 @@ export {
610
633
  AGENT_TYPES,
611
634
  BRAIN_OBSERVATION_TYPES,
612
635
  } from './facade.js';
636
+ // === CLEO-native Goal System (T11376 · Epic T11290 · Saga T11283) ===
637
+ export type {
638
+ FuzzyGoal,
639
+ GoalAdvanceResult,
640
+ GoalContinuation,
641
+ GoalJudge,
642
+ GoalJudgeVerdict,
643
+ GoalKind,
644
+ GoalKindTag,
645
+ GoalRecord,
646
+ GoalStatus,
647
+ TaskCompletionGoal,
648
+ } from './goal.js';
649
+ export {
650
+ GOAL_STATUSES,
651
+ GOAL_TARGET_TASK_ID_REGEX,
652
+ GOAL_TERMINAL_STATUSES,
653
+ isFuzzyGoal,
654
+ isTaskCompletionGoal,
655
+ isTerminalGoalStatus,
656
+ isValidGoalTargetTaskId,
657
+ } from './goal.js';
613
658
  // === Graph Intelligence Types (T512, T529, T1862, T9145) ===
614
659
  export type {
615
660
  AmbiguousProvenance,
@@ -784,6 +829,22 @@ export type {
784
829
  PatternRecord,
785
830
  SessionSummary,
786
831
  } from './memory.js';
832
+ // === MVI progressive-disclosure primitive (T11349 · Epic T11285 · Saga T11283) ===
833
+ export type {
834
+ ExpansionHint,
835
+ MviDigest,
836
+ NextDirectivesHint,
837
+ StructuredOpsHint,
838
+ SuggestedCommandsHint,
839
+ } from './mvi.js';
840
+ export {
841
+ expansionFromNextDirectives,
842
+ expansionFromStructuredOps,
843
+ expansionFromSuggestedCommands,
844
+ isNextDirectivesHint,
845
+ isStructuredOpsHint,
846
+ isSuggestedCommandsHint,
847
+ } from './mvi.js';
787
848
  export type {
788
849
  Contract,
789
850
  ContractCompatibilityMatrix,
@@ -1886,6 +1947,54 @@ export type {
1886
1947
  SignaldockAccessor,
1887
1948
  TelemetryAccessor,
1888
1949
  } from './sub-accessors.js';
1950
+ export type {
1951
+ ChildState,
1952
+ ChildStatus,
1953
+ EnvPair,
1954
+ ErrorResponse,
1955
+ HealthRequest,
1956
+ HealthResponse,
1957
+ LifecycleEventKind,
1958
+ LifecycleEventResponse,
1959
+ MonitorRequest,
1960
+ MonitorResponse,
1961
+ RestartedResponse,
1962
+ RestartRequest,
1963
+ SpawnedResponse,
1964
+ SpawnRequest,
1965
+ SupervisorIpcEnvelope,
1966
+ SupervisorIpcRequest,
1967
+ SupervisorIpcRequestEnvelope,
1968
+ SupervisorIpcResponse,
1969
+ SupervisorIpcResponseEnvelope,
1970
+ } from './supervisor-ipc/index.js';
1971
+ // === Supervisor IPC v1.0 (FROZEN — T11339 · SG-RUNTIME-UNIFICATION R1) ===
1972
+ export {
1973
+ ChildStateSchema,
1974
+ ChildStatusSchema,
1975
+ EnvPairSchema,
1976
+ ErrorResponseSchema,
1977
+ HealthRequestSchema,
1978
+ HealthResponseSchema,
1979
+ LifecycleEventKindSchema,
1980
+ LifecycleEventResponseSchema,
1981
+ MonitorRequestSchema,
1982
+ MonitorResponseSchema,
1983
+ RestartedResponseSchema,
1984
+ RestartRequestSchema,
1985
+ SpawnedResponseSchema,
1986
+ SpawnRequestSchema,
1987
+ SUPERVISOR_IPC_CHANNEL_BASENAME,
1988
+ SUPERVISOR_IPC_MESSAGE_KINDS,
1989
+ SUPERVISOR_IPC_PROTOCOL_VERSION,
1990
+ SUPERVISOR_IPC_REQUEST_KINDS,
1991
+ SUPERVISOR_IPC_RESPONSE_KINDS,
1992
+ SupervisorIpcEnvelopeSchema,
1993
+ SupervisorIpcRequestEnvelopeSchema,
1994
+ SupervisorIpcRequestSchema,
1995
+ SupervisorIpcResponseEnvelopeSchema,
1996
+ SupervisorIpcResponseSchema,
1997
+ } from './supervisor-ipc/index.js';
1889
1998
  // === Task Types ===
1890
1999
  export type {
1891
2000
  AcceptanceItem,
package/src/mvi.ts ADDED
@@ -0,0 +1,236 @@
1
+ /**
2
+ * MVI (Minimum-Viable-Information) progressive-disclosure primitive.
3
+ *
4
+ * CLEO historically grew three *separate* "expansion-hint" conventions, each
5
+ * answering the same question — *"the agent got a lean result; how does it
6
+ * drill deeper?"* — in a different wire shape:
7
+ *
8
+ * 1. **`_next`** (`core/src/mvi-helpers.ts`) — `Record<string, string>`: a map
9
+ * of follow-up *name* → copy-pasteable CLI command
10
+ * (`{ full: "cleo show T1", children: "cleo find --parent T1" }`).
11
+ * 2. **`meta.suggestedNext`** (`core/src/dispatch/suggested-next.ts`, T9920) — a
12
+ * flat `ReadonlyArray<string>` of copy-pasteable CLI commands.
13
+ * 3. **`_nexus.suggestedNext`** (`contracts/operations/nexus-scope.ts`) — a
14
+ * `ReadonlyArray<SuggestedNextOp>` of machine-readable, structured operations.
15
+ *
16
+ * {@link MviDigest} is the single primitive that unifies them. A digest
17
+ * describes a *collapsed* collection: a one-line `summary`, the total `count`,
18
+ * an optional bounded `preview` sample, and exactly one {@link ExpansionHint}
19
+ * describing how to fetch the rest. The hint is a discriminated union whose
20
+ * variants are the three legacy conventions — so existing producers can emit a
21
+ * digest and existing consumers can read one *without any `any` casts*.
22
+ *
23
+ * @packageDocumentation
24
+ * @module @cleocode/contracts/mvi
25
+ *
26
+ * @epic T11285 EP-MVI-PRIMITIVE
27
+ * @task T11349
28
+ * @saga T11283 SG-COGNITIVE-SUBSTRATE
29
+ */
30
+
31
+ import type { SuggestedNextOp } from './operations/nexus-scope.js';
32
+
33
+ /**
34
+ * `_next`-style expansion hint: a map of follow-up *name* → CLI command string.
35
+ *
36
+ * The `kind` discriminant lets a single {@link MviDigest} carry any of the
37
+ * three legacy conventions without ambiguity. This variant corresponds to the
38
+ * `_next` directives built by `core/src/mvi-helpers.ts`.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * const hint: NextDirectivesHint = {
43
+ * kind: 'next-directives',
44
+ * directives: { full: 'cleo show T1', children: 'cleo find --parent T1' },
45
+ * };
46
+ * ```
47
+ *
48
+ * @public
49
+ */
50
+ export interface NextDirectivesHint {
51
+ /** Discriminant: this hint carries `_next`-style named CLI directives. */
52
+ readonly kind: 'next-directives';
53
+ /** Map of follow-up operation name → copy-pasteable CLI command string. */
54
+ readonly directives: Readonly<Record<string, string>>;
55
+ }
56
+
57
+ /**
58
+ * `meta.suggestedNext`-style expansion hint: a flat list of CLI commands.
59
+ *
60
+ * Corresponds to the `ReadonlyArray<string>` promoted to
61
+ * `meta.suggestedNext` in T9920 (`core/src/dispatch/suggested-next.ts`).
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * const hint: SuggestedCommandsHint = {
66
+ * kind: 'suggested-commands',
67
+ * commands: ['cleo show T1', 'cleo focus T1'],
68
+ * };
69
+ * ```
70
+ *
71
+ * @public
72
+ */
73
+ export interface SuggestedCommandsHint {
74
+ /** Discriminant: this hint carries a flat list of CLI command strings. */
75
+ readonly kind: 'suggested-commands';
76
+ /** Copy-pasteable CLI command strings the agent may run next. */
77
+ readonly commands: ReadonlyArray<string>;
78
+ }
79
+
80
+ /**
81
+ * `_nexus.suggestedNext`-style expansion hint: structured machine-readable ops.
82
+ *
83
+ * Corresponds to the `ReadonlyArray<SuggestedNextOp>` carried under
84
+ * `meta._nexus.suggestedNext` (`contracts/operations/nexus-scope.ts`). Display
85
+ * strings are *derived* from these structured fields, never the reverse.
86
+ *
87
+ * @example
88
+ * ```ts
89
+ * const hint: StructuredOpsHint = {
90
+ * kind: 'structured-ops',
91
+ * ops: [{ op: 'nexus.context', args: { name: 'foo' }, scope: 'project',
92
+ * effect: 'read', requiresConfirmation: false, reason: 'see callers' }],
93
+ * };
94
+ * ```
95
+ *
96
+ * @public
97
+ */
98
+ export interface StructuredOpsHint {
99
+ /** Discriminant: this hint carries structured, machine-readable operations. */
100
+ readonly kind: 'structured-ops';
101
+ /** Structured next-operations. Every `.op` resolves to a known op key. */
102
+ readonly ops: ReadonlyArray<SuggestedNextOp>;
103
+ }
104
+
105
+ /**
106
+ * Unified expansion hint — the discriminated union reconciling CLEO's three
107
+ * historical progressive-disclosure conventions (`_next`,
108
+ * `meta.suggestedNext`, `_nexus.suggestedNext`) under one type.
109
+ *
110
+ * Narrow on {@link ExpansionHint | the `.kind` discriminant} to access the
111
+ * variant payload without casts.
112
+ *
113
+ * @public
114
+ */
115
+ export type ExpansionHint = NextDirectivesHint | SuggestedCommandsHint | StructuredOpsHint;
116
+
117
+ /**
118
+ * The Minimum-Viable-Information digest: the formalized progressive-disclosure
119
+ * primitive for any *collapsed* collection in a LAFS envelope.
120
+ *
121
+ * Instead of streaming a full collection (and blowing the agent's token
122
+ * budget), a producer emits a digest: a one-line {@link MviDigest.summary}, the
123
+ * total {@link MviDigest.count}, an optional bounded {@link MviDigest.preview}
124
+ * sample, and exactly one {@link MviDigest.expand} hint describing how to fetch
125
+ * the remainder.
126
+ *
127
+ * @typeParam T - Element type of the underlying collection. The optional
128
+ * `preview` is a `ReadonlyArray<T>`; the rest of the digest is element-shape
129
+ * agnostic, so a producer can describe any collection with one primitive.
130
+ *
131
+ * @example
132
+ * ```ts
133
+ * const digest: MviDigest<{ id: string }> = {
134
+ * summary: '12 child tasks (3 done, 9 pending)',
135
+ * count: 12,
136
+ * preview: [{ id: 'T1' }, { id: 'T2' }],
137
+ * expand: { kind: 'next-directives', directives: { all: 'cleo list --parent T0' } },
138
+ * };
139
+ * ```
140
+ *
141
+ * @public
142
+ */
143
+ export interface MviDigest<T = unknown> {
144
+ /** One-line human/agent-readable summary of the collapsed collection. */
145
+ readonly summary: string;
146
+ /** Total number of elements the collection contains (not the preview size). */
147
+ readonly count: number;
148
+ /**
149
+ * A bounded sample of elements for at-a-glance context. Omitted when no
150
+ * preview is carried (the agent must {@link MviDigest.expand} to see any).
151
+ *
152
+ * @defaultValue undefined
153
+ */
154
+ readonly preview?: ReadonlyArray<T>;
155
+ /** Exactly one {@link ExpansionHint} describing how to fetch the remainder. */
156
+ readonly expand: ExpansionHint;
157
+ }
158
+
159
+ /**
160
+ * Adapt a legacy `_next` directives map into the unified {@link ExpansionHint}.
161
+ *
162
+ * Lets existing `core/src/mvi-helpers.ts` producers feed a digest without
163
+ * re-shaping their output by hand.
164
+ *
165
+ * @param directives - The `_next`-style name → CLI command map.
166
+ * @returns A {@link NextDirectivesHint} wrapping the directives verbatim.
167
+ *
168
+ * @public
169
+ */
170
+ export function expansionFromNextDirectives(
171
+ directives: Readonly<Record<string, string>>,
172
+ ): NextDirectivesHint {
173
+ return { kind: 'next-directives', directives };
174
+ }
175
+
176
+ /**
177
+ * Adapt a legacy `meta.suggestedNext` command list into an {@link ExpansionHint}.
178
+ *
179
+ * @param commands - The flat `ReadonlyArray<string>` of CLI commands.
180
+ * @returns A {@link SuggestedCommandsHint} wrapping the commands verbatim.
181
+ *
182
+ * @public
183
+ */
184
+ export function expansionFromSuggestedCommands(
185
+ commands: ReadonlyArray<string>,
186
+ ): SuggestedCommandsHint {
187
+ return { kind: 'suggested-commands', commands };
188
+ }
189
+
190
+ /**
191
+ * Adapt a legacy `_nexus.suggestedNext` op list into an {@link ExpansionHint}.
192
+ *
193
+ * @param ops - The structured `ReadonlyArray<SuggestedNextOp>`.
194
+ * @returns A {@link StructuredOpsHint} wrapping the ops verbatim.
195
+ *
196
+ * @public
197
+ */
198
+ export function expansionFromStructuredOps(ops: ReadonlyArray<SuggestedNextOp>): StructuredOpsHint {
199
+ return { kind: 'structured-ops', ops };
200
+ }
201
+
202
+ /**
203
+ * Type guard: narrow an {@link ExpansionHint} to its `_next`-directives variant.
204
+ *
205
+ * @param hint - The hint to test.
206
+ * @returns `true` when `hint.kind === 'next-directives'`.
207
+ *
208
+ * @public
209
+ */
210
+ export function isNextDirectivesHint(hint: ExpansionHint): hint is NextDirectivesHint {
211
+ return hint.kind === 'next-directives';
212
+ }
213
+
214
+ /**
215
+ * Type guard: narrow an {@link ExpansionHint} to its suggested-commands variant.
216
+ *
217
+ * @param hint - The hint to test.
218
+ * @returns `true` when `hint.kind === 'suggested-commands'`.
219
+ *
220
+ * @public
221
+ */
222
+ export function isSuggestedCommandsHint(hint: ExpansionHint): hint is SuggestedCommandsHint {
223
+ return hint.kind === 'suggested-commands';
224
+ }
225
+
226
+ /**
227
+ * Type guard: narrow an {@link ExpansionHint} to its structured-ops variant.
228
+ *
229
+ * @param hint - The hint to test.
230
+ * @returns `true` when `hint.kind === 'structured-ops'`.
231
+ *
232
+ * @public
233
+ */
234
+ export function isStructuredOpsHint(hint: ExpansionHint): hint is StructuredOpsHint {
235
+ return hint.kind === 'structured-ops';
236
+ }
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Attention Domain Operations Contract (Tier-2 working memory).
3
+ *
4
+ * The attention buffer is a per-agent, scope-keyed, decaying working-memory
5
+ * layer. `cleo attention add` (alias `jot`) writes ONE item, auto-keyed to the
6
+ * narrowest scope the writing agent resolves (agent > task > epic > saga >
7
+ * session > global) via the E0 env-first identity resolvers. Because visibility
8
+ * is the scope key itself, an agent working task `T-A` can never read the
9
+ * agent/task-scoped items written by an agent working `T-B` — cross-agent
10
+ * leakage is structurally impossible (Epic T11288).
11
+ *
12
+ * CLI identifiers start with `attention.*` and route through the `attention`
13
+ * domain handler. These operation types are the wire-format API contract.
14
+ *
15
+ * @task T11373 — Attention CLI + dispatch op
16
+ * @epic T11288 EP-TIER2-ATTENTION
17
+ * @saga T11283 SG-COGNITIVE-SUBSTRATE
18
+ * @see packages/core/src/memory/attention.ts
19
+ * @see packages/cleo/src/dispatch/domains/attention.ts
20
+ */
21
+
22
+ /**
23
+ * Scope-kind taxonomy for attention items, ordered NARROWEST → BROADEST.
24
+ *
25
+ * Mirrors `BRAIN_ATTENTION_SCOPE_KINDS` in the brain schema; declared here so
26
+ * the wire contract does not depend on the core schema module.
27
+ */
28
+ export type AttentionScopeKind = 'agent' | 'task' | 'epic' | 'saga' | 'session' | 'global';
29
+
30
+ /** Lifecycle status of an attention item. */
31
+ export type AttentionStatus = 'open' | 'consolidated' | 'discarded';
32
+
33
+ /**
34
+ * One attention item in wire format.
35
+ *
36
+ * Returned by `add`, `show`, and `list`. `tags` is always a parsed string
37
+ * array (decoded from the JSONB column via `json(col)`), never the raw BLOB.
38
+ */
39
+ export interface AttentionItem {
40
+ /** Stable item id (`att_<ts>_<hex>`). */
41
+ id: string;
42
+ /** The jot content. */
43
+ content: string;
44
+ /** Resolved session id of the writer, if any. */
45
+ sessionId: string | null;
46
+ /** Resolved agent identity of the writer, if any. */
47
+ agentId: string | null;
48
+ /** Narrowest scope kind the item was keyed to. */
49
+ scopeKind: AttentionScopeKind;
50
+ /** Id of the bound scope (task/epic/saga id, agent id, session id, or `global`). */
51
+ scopeId: string;
52
+ /** Parsed tag list (decoded from the JSONB column). */
53
+ tags: string[];
54
+ /** Creation time, unix epoch milliseconds. */
55
+ createdAt: number;
56
+ /** Optional hard TTL, unix epoch milliseconds. */
57
+ expiresAt: number | null;
58
+ /** Optional decay score in `[0, 1]`. */
59
+ decayScore: number | null;
60
+ /** Lifecycle status. */
61
+ status: AttentionStatus;
62
+ }
63
+
64
+ /**
65
+ * Parameters for `attention.add` (alias `jot`).
66
+ *
67
+ * Identity (`sessionId`/`agentId`) and the current task are resolved server-
68
+ * side from the environment (E0) — callers do NOT pass them by default. The
69
+ * optional `scope` override escalates the auto-resolved narrowest scope.
70
+ */
71
+ export interface AttentionAddParams {
72
+ /** The jot content. Required, non-empty. */
73
+ content: string;
74
+ /** Optional tags to attach. */
75
+ tags?: string[];
76
+ /**
77
+ * Optional explicit scope override. When omitted the narrowest resolvable
78
+ * scope is used. Accepts a scope kind to escalate to (e.g. `epic`, `saga`).
79
+ */
80
+ scope?: AttentionScopeKind;
81
+ /** Optional TTL in seconds from now (sets `expiresAt`). */
82
+ ttlSeconds?: number;
83
+ }
84
+
85
+ /**
86
+ * Parameters for `attention.list` / `attention.show`.
87
+ *
88
+ * With no flags the resolved scope chain (narrowest + visible ancestors) of the
89
+ * calling agent is used. `--scope` restricts to one kind; `--tag` filters by
90
+ * "contains ALL" membership.
91
+ */
92
+ export interface AttentionListParams {
93
+ /** Restrict to one scope kind. */
94
+ scope?: AttentionScopeKind;
95
+ /** "Contains ALL" tag filter. */
96
+ tags?: string[];
97
+ /** Include non-open items too (default: open only). */
98
+ includeAll?: boolean;
99
+ /** Max rows. */
100
+ limit?: number;
101
+ }
102
+
103
+ /** Result of `attention.add`. */
104
+ export interface AttentionAddResult {
105
+ /** The persisted item. */
106
+ item: AttentionItem;
107
+ }
108
+
109
+ /** Result of `attention.list` / `attention.show`. */
110
+ export interface AttentionListResult {
111
+ /** Matching items, newest first. */
112
+ items: AttentionItem[];
113
+ /** Total returned (== items.length; the digest carries the live count). */
114
+ total: number;
115
+ /** The scope chain the items were resolved against (for transparency). */
116
+ resolvedScopes: Array<{ kind: AttentionScopeKind; id: string }>;
117
+ }
@@ -102,7 +102,13 @@ export type DocsType = BuiltinDocKind;
102
102
  export interface DocsAttachmentRow {
103
103
  /** Attachment identifier (UUID-like string). */
104
104
  id: string;
105
- /** SHA-256 hash of content; truncated to 8 chars in list views. */
105
+ /**
106
+ * Full SHA-256 hex digest of the content (64 chars). The machine envelope
107
+ * always carries the complete hash so consumers can do exact content-equality
108
+ * checks; human/table rendering may abbreviate it for display. (T11294 —
109
+ * truncating it here previously forced the Manual-Write-Sweep into O(docs)
110
+ * `docs fetch` spawns to recover the real digest.)
111
+ */
106
112
  sha256: string;
107
113
  /** Attachment kind / storage mode. */
108
114
  kind: AttachmentKind;
@@ -12,8 +12,25 @@
12
12
  * @epic T9964 E-ORIENT-V2
13
13
  */
14
14
 
15
+ import type { MviDigest } from '../mvi.js';
16
+ import type { AttentionScopeKind } from './attention.js';
15
17
  import type { MemoryCompactHit } from './memory.js';
16
18
 
19
+ /**
20
+ * A minimal preview element for the attention digest (T11374 · Epic T11288).
21
+ *
22
+ * The MVI digest preview carries only the few fields an agent needs to glance
23
+ * at a jot — the full item is one `cleo attention show` away (the expand hint).
24
+ */
25
+ export interface AttentionDigestPreviewItem {
26
+ /** Item id. */
27
+ id: string;
28
+ /** Truncated jot content. */
29
+ content: string;
30
+ /** Scope kind the jot is keyed to. */
31
+ scopeKind: AttentionScopeKind;
32
+ }
33
+
17
34
  // ---------------------------------------------------------------------------
18
35
  // Params
19
36
  // ---------------------------------------------------------------------------
@@ -205,6 +222,15 @@ export interface FocusShowResult {
205
222
  * Omitted when the BRAIN store is unavailable.
206
223
  */
207
224
  brainContext?: FocusBrainContext;
225
+ /**
226
+ * Tier-2 attention digest — a budget-bounded MVI summary of the open
227
+ * working-memory jots visible to the calling agent in this scope (T11374 ·
228
+ * Epic T11288). Carries a one-line summary, the live count, a tiny preview,
229
+ * and the `cleo attention show` expand hint — never a full dump. Omitted when
230
+ * there are zero open items (the empty-attention contract) or the buffer is
231
+ * unavailable.
232
+ */
233
+ attentionDigest?: MviDigest<AttentionDigestPreviewItem>;
208
234
  /** Estimated token weight of this envelope. */
209
235
  tokensEstimated: number;
210
236
  }
@@ -7,6 +7,7 @@
7
7
 
8
8
  export * from './admin.js';
9
9
  export * from './agent-operation-contract.js';
10
+ export * from './attention.js';
10
11
  export * from './brain.js';
11
12
  export * from './conduit.js';
12
13
  export * from './dialectic.js';
@@ -581,6 +581,17 @@ export interface SessionEndParams {
581
581
  * @task T140 @epic T134
582
582
  */
583
583
  sessionSummary?: import('../config.js').SessionSummaryInput;
584
+ /**
585
+ * Explicit session id to end (T11346 · Epic T11284).
586
+ *
587
+ * When omitted, session-end targets the CALLER's session resolved env-first
588
+ * (`CLEO_SESSION_ID` → … → most-recent active). When provided, this id
589
+ * overrides env/active resolution. Either way, one agent can no longer end a
590
+ * different concurrently-active agent's session implicitly.
591
+ *
592
+ * @task T11346
593
+ */
594
+ sessionId?: string;
584
595
  }
585
596
  /** Result of `session.end`. */
586
597
  export interface SessionEndResult {
package/src/sdk-tool.ts CHANGED
@@ -10,7 +10,7 @@
10
10
  * - MUST be pure or side-effect-isolated (testable without running an agent).
11
11
  * - SHOULD be deterministic given identical inputs.
12
12
  *
13
- * Canonical location: `packages/core/src/tools/sdk/`
13
+ * Canonical location: `packages/core/src/sdk/`
14
14
  *
15
15
  * Distinct from Category A (Agent Tool — LLM-callable primitive registered in
16
16
  * AgentToolRegistry) and Category C (Domain Utility — internal to a specific