@cleocode/contracts 2026.4.0 → 2026.4.3

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 (55) hide show
  1. package/dist/adapter.d.ts +60 -0
  2. package/dist/adapter.d.ts.map +1 -1
  3. package/dist/brain.d.ts +19 -0
  4. package/dist/brain.d.ts.map +1 -1
  5. package/dist/capabilities.d.ts +1 -0
  6. package/dist/capabilities.d.ts.map +1 -1
  7. package/dist/conduit.d.ts +5 -0
  8. package/dist/conduit.d.ts.map +1 -1
  9. package/dist/config.d.ts +38 -3
  10. package/dist/config.d.ts.map +1 -1
  11. package/dist/errors.d.ts +30 -0
  12. package/dist/errors.d.ts.map +1 -1
  13. package/dist/errors.js +30 -0
  14. package/dist/errors.js.map +1 -1
  15. package/dist/install.d.ts +1 -1
  16. package/dist/install.d.ts.map +1 -1
  17. package/dist/lafs.d.ts +167 -11
  18. package/dist/lafs.d.ts.map +1 -1
  19. package/dist/lafs.js +57 -3
  20. package/dist/lafs.js.map +1 -1
  21. package/dist/memory.d.ts +77 -0
  22. package/dist/memory.d.ts.map +1 -1
  23. package/dist/operations/issues.d.ts +1 -1
  24. package/dist/operations/issues.d.ts.map +1 -1
  25. package/dist/operations/session.d.ts +1 -1
  26. package/dist/operations/session.js +1 -1
  27. package/dist/operations/tasks.d.ts +1 -1
  28. package/dist/operations/tasks.js +1 -1
  29. package/dist/results.d.ts +89 -0
  30. package/dist/results.d.ts.map +1 -1
  31. package/dist/session.d.ts +78 -0
  32. package/dist/session.d.ts.map +1 -1
  33. package/dist/session.js +5 -0
  34. package/dist/session.js.map +1 -1
  35. package/dist/status-registry.d.ts +1 -1
  36. package/dist/status-registry.js +1 -1
  37. package/dist/task.d.ts +106 -33
  38. package/dist/task.d.ts.map +1 -1
  39. package/package.json +1 -1
  40. package/src/adapter.ts +60 -0
  41. package/src/brain.ts +19 -0
  42. package/src/capabilities.ts +1 -0
  43. package/src/conduit.ts +3 -0
  44. package/src/config.ts +38 -3
  45. package/src/errors.ts +30 -0
  46. package/src/install.ts +1 -1
  47. package/src/lafs.ts +169 -13
  48. package/src/memory.ts +77 -0
  49. package/src/operations/issues.ts +1 -1
  50. package/src/operations/session.ts +1 -1
  51. package/src/operations/tasks.ts +1 -1
  52. package/src/results.ts +89 -0
  53. package/src/session.ts +78 -0
  54. package/src/status-registry.ts +1 -1
  55. package/src/task.ts +106 -33
package/src/results.ts CHANGED
@@ -11,107 +11,158 @@ import type { TaskRecord } from './task-record.js';
11
11
 
12
12
  /** Task summary counts used in dashboard and stats views. */
13
13
  export interface TaskSummary {
14
+ /** Number of tasks in `pending` status. */
14
15
  pending: number;
16
+ /** Number of tasks in `active` status. */
15
17
  active: number;
18
+ /** Number of tasks in `blocked` status. */
16
19
  blocked: number;
20
+ /** Number of tasks in `done` status. */
17
21
  done: number;
22
+ /** Number of tasks in `cancelled` status. */
18
23
  cancelled: number;
24
+ /** Total non-archived tasks (pending + active + blocked + done + cancelled). */
19
25
  total: number;
26
+ /** Number of archived tasks. */
20
27
  archived: number;
28
+ /** Grand total including archived tasks. */
21
29
  grandTotal: number;
22
30
  }
23
31
 
24
32
  /** Label frequency entry. */
25
33
  export interface LabelCount {
34
+ /** Label string value. */
26
35
  label: string;
36
+ /** Number of tasks tagged with this label. */
27
37
  count: number;
28
38
  }
29
39
 
30
40
  /** Dashboard result from system.dash query. */
31
41
  export interface DashboardResult {
42
+ /** Project name. */
32
43
  project: string;
44
+ /** Currently active phase slug, or `null` if no phase is active. */
33
45
  currentPhase: string | null;
46
+ /** Aggregate task status counts. */
34
47
  summary: TaskSummary;
48
+ /** Current task work focus state. */
35
49
  taskWork: {
36
50
  currentTask: string | null;
37
51
  task: TaskRecord | null;
38
52
  };
53
+ /** Currently active session ID, or `null`. */
39
54
  activeSession: string | null;
55
+ /** High-priority tasks requiring attention. */
40
56
  highPriority: {
41
57
  count: number;
42
58
  tasks: TaskRecord[];
43
59
  };
60
+ /** Blocked tasks that need unblocking. */
44
61
  blockedTasks: {
45
62
  count: number;
46
63
  limit: number;
47
64
  tasks: TaskRecord[];
48
65
  };
66
+ /** Recently completed tasks. */
49
67
  recentCompletions: TaskRecord[];
68
+ /** Most frequently used labels with counts. */
50
69
  topLabels: LabelCount[];
51
70
  }
52
71
 
53
72
  /** Current state counts used in stats results. */
54
73
  export interface StatsCurrentState {
74
+ /** Number of tasks in `pending` status. */
55
75
  pending: number;
76
+ /** Number of tasks in `active` status. */
56
77
  active: number;
78
+ /** Number of tasks in `done` status. */
57
79
  done: number;
80
+ /** Number of tasks in `blocked` status. */
58
81
  blocked: number;
82
+ /** Number of tasks in `cancelled` status. */
59
83
  cancelled: number;
84
+ /** Total active (non-done, non-cancelled) tasks. */
60
85
  totalActive: number;
86
+ /** Number of archived tasks. */
61
87
  archived: number;
88
+ /** Grand total including archived tasks. */
62
89
  grandTotal: number;
63
90
  }
64
91
 
65
92
  /** Completion metrics for a given time period. */
66
93
  export interface StatsCompletionMetrics {
94
+ /** Number of days in the measurement period. */
67
95
  periodDays: number;
96
+ /** Tasks completed within the period. */
68
97
  completedInPeriod: number;
98
+ /** Tasks created within the period. */
69
99
  createdInPeriod: number;
100
+ /** Completion rate as a ratio (0.0 to 1.0). */
70
101
  completionRate: number;
71
102
  }
72
103
 
73
104
  /** Activity metrics for a given time period. */
74
105
  export interface StatsActivityMetrics {
106
+ /** Tasks created within the period. */
75
107
  createdInPeriod: number;
108
+ /** Tasks completed within the period. */
76
109
  completedInPeriod: number;
110
+ /** Tasks archived within the period. */
77
111
  archivedInPeriod: number;
78
112
  }
79
113
 
80
114
  /** All-time cumulative statistics. */
81
115
  export interface StatsAllTime {
116
+ /** Total tasks ever created. */
82
117
  totalCreated: number;
118
+ /** Total tasks ever completed. */
83
119
  totalCompleted: number;
120
+ /** Total tasks ever cancelled. */
84
121
  totalCancelled: number;
122
+ /** Total tasks ever archived. */
85
123
  totalArchived: number;
124
+ /** Archived tasks that were in `done` status when archived. */
86
125
  archivedCompleted: number;
87
126
  }
88
127
 
89
128
  /** Cycle time statistics. */
90
129
  export interface StatsCycleTimes {
130
+ /** Average days from creation to completion, or `null` if no samples. */
91
131
  averageDays: number | null;
132
+ /** Number of completed tasks used to compute the average. */
92
133
  samples: number;
93
134
  }
94
135
 
95
136
  /** Stats result from system.stats query. */
96
137
  export interface StatsResult {
138
+ /** Current task status distribution. */
97
139
  currentState: StatsCurrentState;
140
+ /** Task count grouped by priority level. */
98
141
  byPriority: Record<string, number>;
142
+ /** Task count grouped by task type. */
99
143
  byType: Record<string, number>;
144
+ /** Task count grouped by phase slug. */
100
145
  byPhase: Record<string, number>;
146
+ /** Completion throughput for the measurement period. */
101
147
  completionMetrics: StatsCompletionMetrics;
148
+ /** Creation/completion/archive activity for the period. */
102
149
  activityMetrics: StatsActivityMetrics;
150
+ /** Cumulative all-time statistics. */
103
151
  allTime: StatsAllTime;
152
+ /** Average time from task creation to completion. */
104
153
  cycleTimes: StatsCycleTimes;
105
154
  }
106
155
 
107
156
  /** Log query result from system.log query. */
108
157
  export interface LogQueryResult {
158
+ /** Audit log entries matching the query. */
109
159
  entries: Array<{
110
160
  operation: string;
111
161
  taskId?: string;
112
162
  timestamp: string;
113
163
  [key: string]: unknown;
114
164
  }>;
165
+ /** Pagination metadata for the query result. */
115
166
  pagination: {
116
167
  total: number;
117
168
  offset: number;
@@ -122,13 +173,21 @@ export interface LogQueryResult {
122
173
 
123
174
  /** Context monitoring data from system.context query. */
124
175
  export interface ContextResult {
176
+ /** Whether context monitoring is available for the current provider. */
125
177
  available: boolean;
178
+ /** Human-readable context usage status (e.g. `"healthy"`, `"warning"`). */
126
179
  status: string;
180
+ /** Context usage as a percentage (0-100). */
127
181
  percentage: number;
182
+ /** Estimated current token count. */
128
183
  currentTokens: number;
184
+ /** Maximum token capacity for the provider. */
129
185
  maxTokens: number;
186
+ /** ISO 8601 timestamp of the last context measurement. */
130
187
  timestamp: string | null;
188
+ /** Whether the context data is stale (older than threshold). */
131
189
  stale: boolean;
190
+ /** Per-session context usage breakdown. */
132
191
  sessions: Array<{
133
192
  file: string;
134
193
  sessionId: string | null;
@@ -140,9 +199,13 @@ export interface ContextResult {
140
199
 
141
200
  /** Sequence counter data from system.sequence query. */
142
201
  export interface SequenceResult {
202
+ /** Current sequence counter value. */
143
203
  counter: number;
204
+ /** Last task ID generated. */
144
205
  lastId: string;
206
+ /** Integrity checksum of the sequence state. */
145
207
  checksum: string;
208
+ /** Next task ID that will be generated. */
146
209
  nextId: string;
147
210
  }
148
211
 
@@ -152,8 +215,11 @@ export interface SequenceResult {
152
215
 
153
216
  /** Compact task reference used across analysis and dependency results. */
154
217
  export interface TaskRef {
218
+ /** Task identifier. */
155
219
  id: string;
220
+ /** Task title. */
156
221
  title: string;
222
+ /** Current task status string. */
157
223
  status: string;
158
224
  }
159
225
 
@@ -162,28 +228,42 @@ export type TaskRefPriority = Pick<TaskRef, 'id' | 'title'> & { priority?: strin
162
228
 
163
229
  /** Task with leverage score for prioritization. */
164
230
  export interface LeveragedTask {
231
+ /** Task identifier. */
165
232
  id: string;
233
+ /** Task title. */
166
234
  title: string;
235
+ /** Leverage score (higher = more impactful to work on). */
167
236
  leverage: number;
237
+ /**
238
+ * Explanation of why this task has high leverage.
239
+ * @defaultValue undefined
240
+ */
168
241
  reason?: string;
169
242
  }
170
243
 
171
244
  /** Bottleneck task — blocks other tasks. */
172
245
  export interface BottleneckTask {
246
+ /** Task identifier. */
173
247
  id: string;
248
+ /** Task title. */
174
249
  title: string;
250
+ /** Number of other tasks blocked by this task. */
175
251
  blocksCount: number;
176
252
  }
177
253
 
178
254
  /** Task analysis result from tasks.analyze. */
179
255
  export interface TaskAnalysisResult {
256
+ /** Top recommended task to work on next, or `null` if none available. */
180
257
  recommended: (LeveragedTask & { reason: string }) | null;
258
+ /** Tasks that block the most other tasks. */
181
259
  bottlenecks: BottleneckTask[];
260
+ /** Tasks grouped by priority tier. */
182
261
  tiers: {
183
262
  critical: LeveragedTask[];
184
263
  high: LeveragedTask[];
185
264
  normal: LeveragedTask[];
186
265
  };
266
+ /** Aggregate analysis metrics. */
187
267
  metrics: {
188
268
  totalTasks: number;
189
269
  actionable: number;
@@ -194,14 +274,23 @@ export interface TaskAnalysisResult {
194
274
 
195
275
  /** Single task dependency result from tasks.deps. */
196
276
  export interface TaskDepsResult {
277
+ /** ID of the task whose dependencies were analyzed. */
197
278
  taskId: string;
279
+ /** Tasks that this task depends on. */
198
280
  dependsOn: TaskRef[];
281
+ /** Tasks that depend on this task. */
199
282
  dependedOnBy: TaskRef[];
283
+ /** Dependency IDs that reference non-existent tasks. */
200
284
  unresolvedDeps: string[];
285
+ /** Whether all dependencies are in a terminal status. */
201
286
  allDepsReady: boolean;
202
287
  }
203
288
 
204
289
  /** Completion result — unblocked tasks after completing a task. */
205
290
  export interface CompleteTaskUnblocked {
291
+ /**
292
+ * Tasks that became unblocked as a result of the completion.
293
+ * @defaultValue undefined
294
+ */
206
295
  unblockedTasks?: TaskRef[];
207
296
  }
package/src/session.ts CHANGED
@@ -13,58 +13,129 @@ export type { SessionStatus };
13
13
 
14
14
  /** Session scope JSON blob shape. */
15
15
  export interface SessionScope {
16
+ /** Scope type (e.g. `"global"`, `"epic"`, `"task"`, `"custom"`). */
16
17
  type: string;
18
+ /**
19
+ * Epic ID when scope type is `"epic"`.
20
+ * @defaultValue undefined
21
+ */
17
22
  epicId?: string;
23
+ /**
24
+ * Root task ID when scope is narrowed to a subtree.
25
+ * @defaultValue undefined
26
+ */
18
27
  rootTaskId?: string;
28
+ /**
29
+ * Whether to include descendant tasks of the root task.
30
+ * @defaultValue undefined
31
+ */
19
32
  includeDescendants?: boolean;
33
+ /**
34
+ * Phase slug to filter tasks by.
35
+ * @defaultValue undefined
36
+ */
20
37
  phaseFilter?: string | null;
38
+ /**
39
+ * Label filter to narrow the scope to specific labels.
40
+ * @defaultValue undefined
41
+ */
21
42
  labelFilter?: string[] | null;
43
+ /**
44
+ * Maximum hierarchy depth to include.
45
+ * @defaultValue undefined
46
+ */
22
47
  maxDepth?: number | null;
48
+ /**
49
+ * Explicit task IDs to include regardless of other filters.
50
+ * @defaultValue undefined
51
+ */
23
52
  explicitTaskIds?: string[] | null;
53
+ /**
54
+ * Task IDs to exclude from the scope.
55
+ * @defaultValue undefined
56
+ */
24
57
  excludeTaskIds?: string[] | null;
58
+ /**
59
+ * Task IDs computed from the scope definition at resolution time.
60
+ * @defaultValue undefined
61
+ */
25
62
  computedTaskIds?: string[];
63
+ /**
64
+ * ISO 8601 timestamp of when computed task IDs were last resolved.
65
+ * @defaultValue undefined
66
+ */
26
67
  computedAt?: string;
27
68
  }
28
69
 
29
70
  /** Session statistics. */
30
71
  export interface SessionStats {
72
+ /** Number of tasks completed during this session. */
31
73
  tasksCompleted: number;
74
+ /** Number of new tasks created during this session. */
32
75
  tasksCreated: number;
76
+ /** Number of task updates performed during this session. */
33
77
  tasksUpdated: number;
78
+ /** Number of times the focus task was changed. */
34
79
  focusChanges: number;
80
+ /** Total minutes the session was in active status. */
35
81
  totalActiveMinutes: number;
82
+ /** Number of times the session was suspended and resumed. */
36
83
  suspendCount: number;
37
84
  }
38
85
 
39
86
  /** Active task work state within a session. */
40
87
  export interface SessionTaskWork {
88
+ /** ID of the task currently being worked on, or `null` if none. */
41
89
  taskId: string | null;
90
+ /** ISO 8601 timestamp of when the current task was set, or `null`. */
42
91
  setAt: string | null;
43
92
  }
44
93
 
45
94
  /** Session domain type — plain interface aligned with Drizzle sessions table. */
46
95
  export interface Session {
96
+ /** Unique session identifier (e.g. `"ses_20260401..."`) . */
47
97
  id: string;
98
+ /** Human-readable session name. */
48
99
  name: string;
100
+ /** Current session lifecycle status. */
49
101
  status: SessionStatus;
102
+ /** Scope definition controlling which tasks are visible. */
50
103
  scope: SessionScope;
104
+ /** Active task work state within the session. */
51
105
  taskWork: SessionTaskWork;
106
+ /** ISO 8601 timestamp of when the session started. */
52
107
  startedAt: string;
108
+ /** ISO 8601 timestamp of when the session ended. @defaultValue undefined */
53
109
  endedAt?: string;
110
+ /** Agent identifier that owns this session. @defaultValue undefined */
54
111
  agent?: string;
112
+ /** Timestamped notes appended during the session. @defaultValue undefined */
55
113
  notes?: string[];
114
+ /** IDs of tasks completed during this session. @defaultValue undefined */
56
115
  tasksCompleted?: string[];
116
+ /** IDs of tasks created during this session. @defaultValue undefined */
57
117
  tasksCreated?: string[];
118
+ /** Serialized handoff JSON for session continuity. @defaultValue undefined */
58
119
  handoffJson?: string | null;
120
+ /** ID of the session that preceded this one. @defaultValue undefined */
59
121
  previousSessionId?: string | null;
122
+ /** ID of the session that follows this one. @defaultValue undefined */
60
123
  nextSessionId?: string | null;
124
+ /** Provider-specific agent identifier string. @defaultValue undefined */
61
125
  agentIdentifier?: string | null;
126
+ /** ISO 8601 timestamp of when the handoff was consumed. @defaultValue undefined */
62
127
  handoffConsumedAt?: string | null;
128
+ /** Agent that consumed the handoff. @defaultValue undefined */
63
129
  handoffConsumedBy?: string | null;
130
+ /** Serialized debrief JSON from session end. @defaultValue undefined */
64
131
  debriefJson?: string | null;
132
+ /** Aggregate session statistics. @defaultValue undefined */
65
133
  stats?: SessionStats;
134
+ /** Number of times this session has been resumed. @defaultValue undefined */
66
135
  resumeCount?: number;
136
+ /** Whether this session is in grade/evaluation mode. @defaultValue undefined */
67
137
  gradeMode?: boolean;
138
+ /** ID of the provider adapter used for this session. @defaultValue undefined */
68
139
  providerId?: string | null;
69
140
  }
70
141
 
@@ -75,7 +146,9 @@ export interface Session {
75
146
  * provided for consumers that expect it at the top level of the result.
76
147
  */
77
148
  export interface SessionStartResult {
149
+ /** The newly created or resumed session. */
78
150
  session: Session;
151
+ /** Convenience alias for `session.id`. */
79
152
  sessionId: string;
80
153
  }
81
154
 
@@ -84,6 +157,11 @@ export interface SessionStartResult {
84
157
  *
85
158
  * Provides discoverable query methods for common session lookups.
86
159
  * Does NOT change the DataAccessor interface — consumers create views from Session[].
160
+ *
161
+ * @remarks
162
+ * SessionView is a read-only collection wrapper that provides convenience
163
+ * methods for filtering, searching, and sorting sessions. It does not own
164
+ * the data and performs no mutations on the underlying array.
87
165
  */
88
166
  export class SessionView {
89
167
  private readonly _sessions: Session[];
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * Dependency direction:
8
8
  * status-registry.ts → schema.ts, types/task.ts, validation/engine.ts,
9
- * mcp/lib/security.ts, dispatch/lib/security.ts, ...
9
+ * dispatch/lib/security.ts, ...
10
10
  */
11
11
 
12
12
  // === WORKFLOW NAMESPACE ===