holo-codex 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/.agents/plugins/marketplace.json +20 -0
  2. package/CONTRIBUTING.md +54 -0
  3. package/LICENSE +21 -0
  4. package/README.md +215 -0
  5. package/README.zh-CN.md +215 -0
  6. package/SECURITY.md +39 -0
  7. package/assets/brand/README.md +35 -0
  8. package/assets/brand/holo-codex-icon.svg +28 -0
  9. package/assets/brand/holo-codex-lockup.svg +49 -0
  10. package/assets/brand/holo-codex-mark.svg +33 -0
  11. package/assets/brand/holo-codex-plugin-card.png +0 -0
  12. package/assets/brand/holo-codex-plugin-card.svg +81 -0
  13. package/assets/brand/holo-codex-readme-hero.png +0 -0
  14. package/assets/brand/holo-codex-readme-hero.svg +140 -0
  15. package/assets/brand/holo-codex-social-preview.png +0 -0
  16. package/assets/brand/holo-codex-social-preview.svg +130 -0
  17. package/assets/brand/holo-codex-wordmark-options.svg +52 -0
  18. package/docs/checklists/agent-loop-first-delivery-audit.md +129 -0
  19. package/docs/examples/generic-loop-repo-hygiene.md +168 -0
  20. package/docs/install.md +190 -0
  21. package/docs/local-release-readiness.md +206 -0
  22. package/docs/release-checklist.md +144 -0
  23. package/docs/self-bootstrap.md +150 -0
  24. package/docs/trust-and-safety.md +45 -0
  25. package/package.json +83 -0
  26. package/plugins/autonomous-pr-loop/.codex-plugin/plugin.json +17 -0
  27. package/plugins/autonomous-pr-loop/.mcp.json +13 -0
  28. package/plugins/autonomous-pr-loop/bin/agent-loop.mjs +31 -0
  29. package/plugins/autonomous-pr-loop/core/artifacts.ts +164 -0
  30. package/plugins/autonomous-pr-loop/core/autonomy-policy.ts +206 -0
  31. package/plugins/autonomous-pr-loop/core/ci.ts +131 -0
  32. package/plugins/autonomous-pr-loop/core/cli-i18n.ts +123 -0
  33. package/plugins/autonomous-pr-loop/core/cli.ts +1413 -0
  34. package/plugins/autonomous-pr-loop/core/command-runner.ts +446 -0
  35. package/plugins/autonomous-pr-loop/core/command.ts +47 -0
  36. package/plugins/autonomous-pr-loop/core/config-editor.ts +140 -0
  37. package/plugins/autonomous-pr-loop/core/config.ts +293 -0
  38. package/plugins/autonomous-pr-loop/core/controller-host.ts +19 -0
  39. package/plugins/autonomous-pr-loop/core/dashboard-server.ts +536 -0
  40. package/plugins/autonomous-pr-loop/core/delivery-work-item.ts +217 -0
  41. package/plugins/autonomous-pr-loop/core/doctor.ts +335 -0
  42. package/plugins/autonomous-pr-loop/core/errors.ts +82 -0
  43. package/plugins/autonomous-pr-loop/core/gate-recovery.ts +176 -0
  44. package/plugins/autonomous-pr-loop/core/gates.ts +26 -0
  45. package/plugins/autonomous-pr-loop/core/generic-lifecycle.ts +399 -0
  46. package/plugins/autonomous-pr-loop/core/git.ts +213 -0
  47. package/plugins/autonomous-pr-loop/core/github.ts +269 -0
  48. package/plugins/autonomous-pr-loop/core/gitnexus.ts +90 -0
  49. package/plugins/autonomous-pr-loop/core/happy.ts +42 -0
  50. package/plugins/autonomous-pr-loop/core/hook-capture.ts +115 -0
  51. package/plugins/autonomous-pr-loop/core/hook-events.ts +22 -0
  52. package/plugins/autonomous-pr-loop/core/hook-installation.ts +85 -0
  53. package/plugins/autonomous-pr-loop/core/hook-observer.ts +84 -0
  54. package/plugins/autonomous-pr-loop/core/hook-policy.ts +423 -0
  55. package/plugins/autonomous-pr-loop/core/hook-router.ts +452 -0
  56. package/plugins/autonomous-pr-loop/core/index.ts +32 -0
  57. package/plugins/autonomous-pr-loop/core/local-install.ts +778 -0
  58. package/plugins/autonomous-pr-loop/core/locale.ts +60 -0
  59. package/plugins/autonomous-pr-loop/core/loop-shapes.ts +190 -0
  60. package/plugins/autonomous-pr-loop/core/mcp-controller.ts +1479 -0
  61. package/plugins/autonomous-pr-loop/core/notification-feed.ts +263 -0
  62. package/plugins/autonomous-pr-loop/core/plan-parser.ts +206 -0
  63. package/plugins/autonomous-pr-loop/core/plugin-paths.ts +32 -0
  64. package/plugins/autonomous-pr-loop/core/policy.ts +65 -0
  65. package/plugins/autonomous-pr-loop/core/pr-lifecycle.ts +464 -0
  66. package/plugins/autonomous-pr-loop/core/pr-selector.ts +284 -0
  67. package/plugins/autonomous-pr-loop/core/profiles.ts +439 -0
  68. package/plugins/autonomous-pr-loop/core/redaction.ts +17 -0
  69. package/plugins/autonomous-pr-loop/core/repo-root.ts +22 -0
  70. package/plugins/autonomous-pr-loop/core/review-comments.ts +77 -0
  71. package/plugins/autonomous-pr-loop/core/scope-guard.ts +179 -0
  72. package/plugins/autonomous-pr-loop/core/state-machine.ts +828 -0
  73. package/plugins/autonomous-pr-loop/core/state-types.ts +130 -0
  74. package/plugins/autonomous-pr-loop/core/storage.ts +2527 -0
  75. package/plugins/autonomous-pr-loop/core/types.ts +567 -0
  76. package/plugins/autonomous-pr-loop/core/worker-events.ts +412 -0
  77. package/plugins/autonomous-pr-loop/core/worker-policy.ts +72 -0
  78. package/plugins/autonomous-pr-loop/core/worker-prompts.ts +182 -0
  79. package/plugins/autonomous-pr-loop/core/worker.ts +809 -0
  80. package/plugins/autonomous-pr-loop/core/workflow-board.ts +1515 -0
  81. package/plugins/autonomous-pr-loop/hooks/dist/permission-request.js +2462 -0
  82. package/plugins/autonomous-pr-loop/hooks/dist/post-compact.js +2462 -0
  83. package/plugins/autonomous-pr-loop/hooks/dist/post-tool-use.js +2462 -0
  84. package/plugins/autonomous-pr-loop/hooks/dist/pre-compact.js +2462 -0
  85. package/plugins/autonomous-pr-loop/hooks/dist/pre-tool-use.js +3460 -0
  86. package/plugins/autonomous-pr-loop/hooks/dist/session-start.js +2462 -0
  87. package/plugins/autonomous-pr-loop/hooks/dist/stop.js +2462 -0
  88. package/plugins/autonomous-pr-loop/hooks/dist/user-prompt-submit.js +2462 -0
  89. package/plugins/autonomous-pr-loop/hooks/hooks.json +106 -0
  90. package/plugins/autonomous-pr-loop/hooks/observe-runner.ts +25 -0
  91. package/plugins/autonomous-pr-loop/hooks/permission-request.ts +4 -0
  92. package/plugins/autonomous-pr-loop/hooks/post-compact.ts +4 -0
  93. package/plugins/autonomous-pr-loop/hooks/post-tool-use.ts +4 -0
  94. package/plugins/autonomous-pr-loop/hooks/pre-compact.ts +4 -0
  95. package/plugins/autonomous-pr-loop/hooks/pre-tool-use.ts +44 -0
  96. package/plugins/autonomous-pr-loop/hooks/session-start.ts +4 -0
  97. package/plugins/autonomous-pr-loop/hooks/stop.ts +4 -0
  98. package/plugins/autonomous-pr-loop/hooks/user-prompt-submit.ts +4 -0
  99. package/plugins/autonomous-pr-loop/mcp-server/src/index.ts +87 -0
  100. package/plugins/autonomous-pr-loop/mcp-server/src/tools.ts +205 -0
  101. package/plugins/autonomous-pr-loop/package.json +9 -0
  102. package/plugins/autonomous-pr-loop/schemas/config.schema.json +74 -0
  103. package/plugins/autonomous-pr-loop/schemas/marketplace.schema.json +46 -0
  104. package/plugins/autonomous-pr-loop/schemas/plugin.schema.json +32 -0
  105. package/plugins/autonomous-pr-loop/schemas/state.schema.json +19 -0
  106. package/plugins/autonomous-pr-loop/schemas/worker-event.schema.json +19 -0
  107. package/plugins/autonomous-pr-loop/schemas/worker-result.schema.json +58 -0
  108. package/plugins/autonomous-pr-loop/scripts/agent-loop.ts +44 -0
  109. package/plugins/autonomous-pr-loop/skills/autonomous-pr-loop/SKILL.md +26 -0
  110. package/plugins/autonomous-pr-loop/skills/autonomous-pr-loop/agents/openai.yaml +6 -0
  111. package/plugins/autonomous-pr-loop/ui/index.html +26 -0
  112. package/plugins/autonomous-pr-loop/ui/public/favicon.svg +7 -0
  113. package/plugins/autonomous-pr-loop/ui/src/api.ts +639 -0
  114. package/plugins/autonomous-pr-loop/ui/src/app.tsx +238 -0
  115. package/plugins/autonomous-pr-loop/ui/src/components/ActivityBadge.tsx +31 -0
  116. package/plugins/autonomous-pr-loop/ui/src/components/BrandMark.tsx +36 -0
  117. package/plugins/autonomous-pr-loop/ui/src/components/Collapsible.tsx +6 -0
  118. package/plugins/autonomous-pr-loop/ui/src/components/CommandPreview.tsx +15 -0
  119. package/plugins/autonomous-pr-loop/ui/src/components/ConfigEditor.tsx +389 -0
  120. package/plugins/autonomous-pr-loop/ui/src/components/EmptyState.tsx +10 -0
  121. package/plugins/autonomous-pr-loop/ui/src/components/ErrorState.tsx +12 -0
  122. package/plugins/autonomous-pr-loop/ui/src/components/List.tsx +7 -0
  123. package/plugins/autonomous-pr-loop/ui/src/components/MetricRow.tsx +6 -0
  124. package/plugins/autonomous-pr-loop/ui/src/components/ResponsiveTable.tsx +65 -0
  125. package/plugins/autonomous-pr-loop/ui/src/components/RiskBadge.tsx +10 -0
  126. package/plugins/autonomous-pr-loop/ui/src/components/StatusBadge.tsx +29 -0
  127. package/plugins/autonomous-pr-loop/ui/src/components/TopMetric.tsx +10 -0
  128. package/plugins/autonomous-pr-loop/ui/src/fixtures.ts +1152 -0
  129. package/plugins/autonomous-pr-loop/ui/src/i18n.ts +1105 -0
  130. package/plugins/autonomous-pr-loop/ui/src/main.tsx +14 -0
  131. package/plugins/autonomous-pr-loop/ui/src/pages/CommandCenter.tsx +470 -0
  132. package/plugins/autonomous-pr-loop/ui/src/pages/CommandCenterParts.tsx +276 -0
  133. package/plugins/autonomous-pr-loop/ui/src/pages/agent-timeline/AgentTimelineView.tsx +73 -0
  134. package/plugins/autonomous-pr-loop/ui/src/pages/artifact-viewer/ArtifactViewer.tsx +44 -0
  135. package/plugins/autonomous-pr-loop/ui/src/pages/dry-run-preview/DryRunPreview.tsx +66 -0
  136. package/plugins/autonomous-pr-loop/ui/src/pages/event-ledger/EventLedger.tsx +17 -0
  137. package/plugins/autonomous-pr-loop/ui/src/pages/gate-center/GateCenter.tsx +34 -0
  138. package/plugins/autonomous-pr-loop/ui/src/pages/mission-control/MissionControl.tsx +104 -0
  139. package/plugins/autonomous-pr-loop/ui/src/pages/mission-control/WorkflowBoard.tsx +577 -0
  140. package/plugins/autonomous-pr-loop/ui/src/pages/notifications/NotificationsView.tsx +30 -0
  141. package/plugins/autonomous-pr-loop/ui/src/pages/plan-navigator/PlanNavigator.tsx +19 -0
  142. package/plugins/autonomous-pr-loop/ui/src/pages/policy-config/PolicyConfig.tsx +22 -0
  143. package/plugins/autonomous-pr-loop/ui/src/pages/pr-inbox/PrInbox.tsx +26 -0
  144. package/plugins/autonomous-pr-loop/ui/src/pages/recovery-center/RecoveryCenter.tsx +125 -0
  145. package/plugins/autonomous-pr-loop/ui/src/pages/scope-guard/ScopeGuard.tsx +16 -0
  146. package/plugins/autonomous-pr-loop/ui/src/pages/worker-runs/WorkerRuns.tsx +39 -0
  147. package/plugins/autonomous-pr-loop/ui/src/styles.css +2673 -0
  148. package/plugins/autonomous-pr-loop/ui/src/theme.ts +57 -0
  149. package/tsconfig.json +18 -0
@@ -0,0 +1,567 @@
1
+ import type { LocaleSetting } from "./locale.js";
2
+
3
+ /** Repository-level configuration for a portable HOLO-Codex installation. */
4
+ export interface AgentLoopConfig {
5
+ repoId: string;
6
+ locale: LocaleSetting;
7
+ loopShape: LoopShapeId;
8
+ workflowProfile: WorkflowProfileId;
9
+ roleProfile: RoleProfileId;
10
+ baseBranch: string;
11
+ branchPrefix: string;
12
+ plansDir: string;
13
+ lintCommand?: string;
14
+ testCommand?: string;
15
+ gitnexusRepo?: string;
16
+ gitnexusRequired: boolean;
17
+ requiredChecks: string[];
18
+ requireReviewApproval: boolean;
19
+ autonomyMode: AutonomyMode;
20
+ mergeMode: MergeMode;
21
+ notifyMode: NotifyMode;
22
+ reviewHandling: ReviewHandlingMode;
23
+ carryoverTarget?: string;
24
+ allowAutoMerge: boolean;
25
+ maxReviewFixRounds: number;
26
+ maxTestFixRounds: number;
27
+ maxCiReruns: number;
28
+ commandTimeoutMs: number;
29
+ commandOutputLimitBytes: number;
30
+ githubRetryMaxAttempts: number;
31
+ githubRetryBaseDelayMs: number;
32
+ reviewCiPollIntervalMs: number;
33
+ reviewCiMaxWaitMs: number;
34
+ workerBackend: WorkerBackend;
35
+ workerTimeoutMs: number;
36
+ workerMaxRetries: number;
37
+ workerEphemeral: boolean;
38
+ protectedPaths: string[];
39
+ dashboard?: {
40
+ enabled: boolean;
41
+ host: string;
42
+ port?: number;
43
+ };
44
+ }
45
+
46
+ /** Supported loop shape identifiers. */
47
+ export type LoopShapeId = "pr-loop" | "generic-loop";
48
+
49
+ /** Built-in workflow profile identifiers selected by repo config. */
50
+ export type WorkflowProfileId =
51
+ | "default_pr_loop"
52
+ | "docs_only_loop"
53
+ | "review_fix_loop"
54
+ | "release_ready_loop"
55
+ | "research_report_loop"
56
+ | "document_preparation_loop"
57
+ | "repo_hygiene_loop"
58
+ | "weekly_review_loop"
59
+ | "data_extraction_loop";
60
+
61
+ /** Built-in role profile identifiers selected by repo config. */
62
+ export type RoleProfileId = "default_pr_roles";
63
+
64
+
65
+ /** How far the loop may proceed without asking the operator to intervene. */
66
+ export type AutonomyMode = "supervised" | "autonomous_until_gate" | "autonomous_until_terminal";
67
+
68
+ /** Canonical merge strategy. Legacy `allowAutoMerge` is derived from this field. */
69
+ export type MergeMode = "manual" | "conditional" | "disabled";
70
+
71
+ /** Notification posture used to avoid turning progress into interruption. */
72
+ export type NotifyMode = "all_gates" | "important_only" | "blockers_only";
73
+
74
+ /** Review handling strategy for scoped fixes and follow-up carryover. */
75
+ export type ReviewHandlingMode =
76
+ | "fix_scoped_and_carry_forward"
77
+ | "ask_on_any_review"
78
+ | "require_zero_open_findings";
79
+
80
+ /** Stable gate categories that stop or block loop progress. */
81
+ export type AgentLoopGateKind =
82
+ | "needs_repo_init"
83
+ | "unsupported_remote"
84
+ | "needs_secret_or_login"
85
+ | "policy_violation"
86
+ | "ambiguous_next_pr"
87
+ | "dirty_unowned_worktree"
88
+ | "required_tool_unavailable"
89
+ | "ci_required_checks_missing"
90
+ | "ci_pending_timeout"
91
+ | "merge_requires_confirmation"
92
+ | "github_transient_failure"
93
+ | "gitnexus_check_failed"
94
+ | "github_resource_not_found"
95
+ | "worker_failed"
96
+ | "worker_output_invalid"
97
+ | "review_out_of_scope"
98
+ | "worker_timeout"
99
+ | "worker_already_running"
100
+ | "generic_goal_needs_confirmation"
101
+ | "generic_human_gate"
102
+ | "generic_scope_change_requested";
103
+
104
+ /** Current high-level loop status reported by CLI, hooks, MCP, and UI surfaces. */
105
+ export type AgentLoopStatus =
106
+ | "IDLE"
107
+ | "READY"
108
+ | "RUNNING"
109
+ | "BLOCKED"
110
+ | "NEEDS_REPO_INIT"
111
+ | "ERROR"
112
+ | "STOPPED";
113
+
114
+ /** Persisted loop run with optimistic-lock version metadata. */
115
+ export interface AgentLoopRun {
116
+ id: string;
117
+ status: AgentLoopStatus;
118
+ currentState?: string;
119
+ version: number;
120
+ branch?: string;
121
+ worktreeClean?: boolean;
122
+ createdAt: string;
123
+ updatedAt: string;
124
+ startedAt?: string;
125
+ stoppedAt?: string;
126
+ }
127
+
128
+ /** Append-only event written to the loop event ledger. */
129
+ export interface AgentLoopEvent {
130
+ id: string;
131
+ seq: number;
132
+ runId?: string;
133
+ kind: string;
134
+ message: string;
135
+ stateBefore?: string;
136
+ stateAfter?: string;
137
+ payload?: unknown;
138
+ artifactIds?: string[];
139
+ createdAt: string;
140
+ }
141
+
142
+ /** Persisted artifact metadata shared by storage, CLI, and future UI surfaces. */
143
+ export interface AgentLoopArtifactRecord {
144
+ id: string;
145
+ runId: string;
146
+ kind: string;
147
+ name: string;
148
+ path: string;
149
+ sha256: string;
150
+ createdAt: string;
151
+ }
152
+
153
+ /** Stored GitHub PR identity associated with a run and branch. */
154
+ export interface AgentLoopPrLink {
155
+ id: string;
156
+ runId: string;
157
+ branch: string;
158
+ prNumber: number;
159
+ url: string;
160
+ headRef: string;
161
+ baseRef: string;
162
+ state: string;
163
+ draft: boolean;
164
+ createdAt: string;
165
+ updatedAt: string;
166
+ }
167
+
168
+ /** Latest observed CI check for a pull request. */
169
+ export interface AgentLoopCiCheck {
170
+ id: string;
171
+ runId: string;
172
+ prNumber: number;
173
+ name: string;
174
+ status: string;
175
+ conclusion?: string;
176
+ url?: string;
177
+ startedAt?: string;
178
+ completedAt?: string;
179
+ observedAt: string;
180
+ }
181
+
182
+ /** Normalized review comment from GitHub review threads. */
183
+ export interface AgentLoopReviewComment {
184
+ id: string;
185
+ runId: string;
186
+ prNumber: number;
187
+ commentId: string;
188
+ url: string;
189
+ author: string;
190
+ body: string;
191
+ path: string;
192
+ line?: number;
193
+ diffHunk: string;
194
+ isResolved: boolean;
195
+ isOutdated: boolean;
196
+ actionable: boolean;
197
+ status: "open" | "handled" | "out_of_scope" | "stale";
198
+ observedAt: string;
199
+ }
200
+
201
+ /** Append-only decision explaining an idempotent lifecycle choice. */
202
+ export interface AgentLoopDecision {
203
+ id: string;
204
+ runId: string;
205
+ kind: string;
206
+ message: string;
207
+ details?: unknown;
208
+ createdAt: string;
209
+ }
210
+
211
+ /** Persisted gate row with approval/rejection metadata for control surfaces. */
212
+ export interface AgentLoopGate {
213
+ id: string;
214
+ runId?: string;
215
+ kind: AgentLoopGateKind;
216
+ status: "open" | "resolved" | "approved" | "rejected";
217
+ message: string;
218
+ details?: unknown;
219
+ createdAt: string;
220
+ resolvedAt?: string;
221
+ decisionNote?: string;
222
+ decidedAt?: string;
223
+ }
224
+
225
+ /** Structured operator decision metadata accepted by CLI, API, MCP, and UI gate controls. */
226
+ export interface GateDecisionInput {
227
+ note: string;
228
+ source?: "cli" | "api" | "ui" | "nl";
229
+ payload?: Record<string, unknown>;
230
+ }
231
+
232
+ /** Trusted supervisor check recorded before publish actions are allowed. */
233
+ export interface AgentLoopRunCheck {
234
+ runId: string;
235
+ kind: "self_check" | "gitnexus_detect_changes" | "scope_guard" | "protected_paths" | "carryover_recorded";
236
+ status: "passed" | "skipped";
237
+ details?: unknown;
238
+ createdAt: string;
239
+ }
240
+
241
+ /** Worker roles that may be delegated to Codex without owning GitHub lifecycle actions. */
242
+ export type WorkerType = "planner" | "implementation" | "review-fix" | "ci-fix" | "reviewer";
243
+
244
+ /** Profile summary exposed to CLI, MCP, Dashboard, audit, and prompts. */
245
+ export interface AgentLoopProfileSummary {
246
+ loopShape: LoopShapeId;
247
+ workflowProfile: WorkflowProfileId;
248
+ workflowLabel: string;
249
+ workflowDescription: string;
250
+ roleProfile: RoleProfileId;
251
+ lifecycleKind?: "pr" | "generic";
252
+ expectedDeliverable?: string;
253
+ allowedWriteRoots?: string[];
254
+ currentRole?: {
255
+ state: string;
256
+ alias: string;
257
+ workerType: WorkerType;
258
+ label: string;
259
+ sandbox: "read-only" | "workspace-write";
260
+ };
261
+ roleMapping: Array<{
262
+ state: string;
263
+ alias: string;
264
+ workerType: WorkerType;
265
+ label: string;
266
+ sandbox: "read-only" | "workspace-write";
267
+ }>;
268
+ autonomyBoundary: string;
269
+ handoffSummary: string;
270
+ validationPosture: string;
271
+ likelyGates: string[];
272
+ availableWorkflows: Array<{ id: WorkflowProfileId; label: string; description: string }>;
273
+ availableRoleProfiles: Array<{ id: RoleProfileId; label: string; description: string }>;
274
+ }
275
+
276
+ /** Workflow stage forecast rendered by dry-run surfaces. */
277
+ export interface WorkflowStageSummary {
278
+ state: string;
279
+ roleAlias?: string;
280
+ workerType?: WorkerType;
281
+ sandbox?: "read-only" | "workspace-write";
282
+ gateExpected: boolean;
283
+ deliverable?: string;
284
+ }
285
+
286
+ /** Supported worker runtime backends. */
287
+ export type WorkerBackend = "codex-exec" | "codex-app-server";
288
+
289
+ /** Worker execution status persisted for resume, retries, and future UI surfaces. */
290
+ export type WorkerStatus = "running" | "succeeded" | "failed" | "timed_out" | "invalid_output";
291
+
292
+ /** Structured result a worker must produce through `--output-schema`. */
293
+ export interface WorkerResult {
294
+ ok: boolean;
295
+ summary: string;
296
+ changedFiles: string[];
297
+ commandsRun: Array<{ command: string; exitCode: number }>;
298
+ testsRun: string[];
299
+ gitnexus: { impactRun: boolean; detectChangesRun: boolean; notes?: string };
300
+ outOfScope: Array<{ item: string; reason: string }>;
301
+ followUps: string[];
302
+ error?: { kind: string; message: string };
303
+ }
304
+
305
+ /** Stored worker process metadata. */
306
+ export interface WorkerRun {
307
+ id: string;
308
+ runId: string;
309
+ type: WorkerType;
310
+ backend: string;
311
+ status: WorkerStatus;
312
+ threadId?: string;
313
+ attempt: number;
314
+ resumeUsed: boolean;
315
+ startedAt: string;
316
+ completedAt?: string;
317
+ exitCode?: number;
318
+ resultArtifactId?: string;
319
+ rawJsonlArtifactId?: string;
320
+ error?: string;
321
+ }
322
+
323
+ /** Summary event extracted from Codex JSONL worker output. */
324
+ export interface WorkerEvent {
325
+ id: string;
326
+ seq: number;
327
+ workerId: string;
328
+ runId: string;
329
+ eventType: string;
330
+ itemType?: string;
331
+ itemId?: string;
332
+ itemStatus?: string;
333
+ threadId?: string;
334
+ backend?: WorkerBackend;
335
+ summary?: unknown;
336
+ usage?: unknown;
337
+ artifactIds?: string[];
338
+ createdAt: string;
339
+ }
340
+
341
+ /** Fact sources normalized into the Agent Timeline read model. */
342
+ export type AgentTimelineSource =
343
+ | "event"
344
+ | "worker_event"
345
+ | "worker"
346
+ | "state"
347
+ | "gate"
348
+ | "artifact"
349
+ | "decision";
350
+
351
+ /** Public, redacted timeline entry assembled from immutable source rows. */
352
+ export interface AgentTimelineEntry {
353
+ timelineSeq: number;
354
+ occurredAt: string;
355
+ cursor: string;
356
+ source: AgentTimelineSource;
357
+ kind: string;
358
+ runId?: string;
359
+ workerId?: string;
360
+ threadId?: string;
361
+ title: string;
362
+ summary: string;
363
+ status?: string;
364
+ artifactIds?: string[];
365
+ createdAt: string;
366
+ rawRef: { table: string; id: string; seq?: number };
367
+ }
368
+
369
+ /** Timeline query filters exposed to MCP, API, and Dashboard surfaces. */
370
+ export interface AgentTimelineQuery {
371
+ cursor?: string;
372
+ limit?: number;
373
+ sources?: AgentTimelineSource[];
374
+ runId?: string;
375
+ workerId?: string;
376
+ }
377
+
378
+ /** Stable cursor page returned by the Agent Timeline read model. */
379
+ export interface AgentTimelinePage {
380
+ entries: AgentTimelineEntry[];
381
+ nextCursor?: string;
382
+ }
383
+
384
+ /** Timeline storage consistency report used by doctor and tests. */
385
+ export interface AgentTimelineIntegrityReport {
386
+ ok: boolean;
387
+ missingTable: boolean;
388
+ missingTriggers: string[];
389
+ missingSourceRows: Array<{ source: AgentTimelineSource; missing: number }>;
390
+ sourceCounts: Record<AgentTimelineSource, number>;
391
+ repair: string;
392
+ }
393
+
394
+ /** Structured Codex command plan used for dry-runs and policy checks. */
395
+ export interface WorkerCommandPlan {
396
+ file: "codex";
397
+ args: string[];
398
+ cwd: string;
399
+ sandbox: "read-only" | "workspace-write";
400
+ promptPath: string;
401
+ outputSchemaPath: string;
402
+ outputLastMessagePath: string;
403
+ }
404
+
405
+ /** Scope guard report comparing worker claims with real git changes. */
406
+ export interface ScopeGuardReport {
407
+ ok: boolean;
408
+ actualChangedFiles: string[];
409
+ reportedChangedFiles: string[];
410
+ missingFromReport: string[];
411
+ extraInReport: string[];
412
+ protectedPathHits: string[];
413
+ invalidWorkerPaths: string[];
414
+ outOfScope: Array<{ item: string; reason: string }>;
415
+ gate?: AgentLoopGateKind;
416
+ }
417
+
418
+ /** Storage contract shared by CLI, future hooks, MCP, and UI. */
419
+ export interface AgentLoopStorage {
420
+ /** Close the storage handle and release SQLite resources. */
421
+ close(): void;
422
+ /** Persist the normalized repository configuration snapshot. */
423
+ writeRepoConfig(config: AgentLoopConfig): void;
424
+ /** Read the repository configuration snapshot when present. */
425
+ readRepoConfig(): AgentLoopConfig | undefined;
426
+ /** Create a new run with initial status and optional resume reality metadata. */
427
+ createRun(status: AgentLoopStatus, options?: {
428
+ currentState?: string;
429
+ branch?: string;
430
+ worktreeClean?: boolean;
431
+ }): AgentLoopRun;
432
+ /** Return the active RUNNING run or atomically create one. */
433
+ getOrCreateActiveRun(options?: {
434
+ currentState?: string;
435
+ branch?: string;
436
+ worktreeClean?: boolean;
437
+ }): { run: AgentLoopRun; created: boolean };
438
+ /** Update a run using optimistic locking on `expectedVersion`. */
439
+ updateRunStatus(
440
+ runId: string,
441
+ expectedVersion: number,
442
+ status: AgentLoopStatus,
443
+ options?: {
444
+ currentState?: string;
445
+ branch?: string;
446
+ worktreeClean?: boolean;
447
+ stoppedAt?: string;
448
+ }
449
+ ): AgentLoopRun;
450
+ /** Append an immutable event to the run ledger. */
451
+ appendEvent(event: Omit<AgentLoopEvent, "id" | "seq" | "createdAt">): AgentLoopEvent;
452
+ /** Open a gate that blocks loop progress until resolved. */
453
+ writeGate(gate: {
454
+ runId?: string;
455
+ kind: AgentLoopGateKind;
456
+ message: string;
457
+ details?: unknown;
458
+ }): void;
459
+ /** Resolve all open gates for a run without deleting gate history. */
460
+ resolveOpenGates(runId: string): void;
461
+ /** Resolve open gates of one kind; default scope is repo-level unless `runId` or `scope: "all"` is supplied. */
462
+ resolveOpenGatesByKind(kind: AgentLoopGateKind, options?: { scope?: "repo" | "run" | "all"; runId?: string }): void;
463
+ /** List persisted gates newest-first, optionally scoped to one run. */
464
+ listGates(runId?: string): AgentLoopGate[];
465
+ /** Fetch a gate by stable id. */
466
+ getGate(gateId: string): AgentLoopGate | undefined;
467
+ /** Mark an open gate as approved or rejected with an operator note. */
468
+ decideGate(gateId: string, decision: "approved" | "rejected", note: string): AgentLoopGate;
469
+ /** Record a trusted supervisor check for publish prerequisites. */
470
+ recordRunCheck(check: Omit<AgentLoopRunCheck, "createdAt">): AgentLoopRunCheck;
471
+ /** Return true when a trusted supervisor check exists for a run. */
472
+ hasRunCheck(runId: string, kind: AgentLoopRunCheck["kind"]): boolean;
473
+ /** List trusted supervisor checks recorded for a run. */
474
+ listRunChecks(runId: string): AgentLoopRunCheck[];
475
+ /** Return the latest run by update time, if any exists. */
476
+ getCurrentRun(): AgentLoopRun | undefined;
477
+ /** List persisted runs newest-first. */
478
+ listRuns(limit?: number): AgentLoopRun[];
479
+ /** Run a group of read queries against one consistent SQLite snapshot. */
480
+ readTransaction<T>(fn: () => T): T;
481
+ /** Insert artifact metadata after its file has been written and hashed. */
482
+ insertArtifact(record: AgentLoopArtifactRecord): void;
483
+ /** Fetch artifact metadata by id. */
484
+ getArtifact(artifactId: string): AgentLoopArtifactRecord;
485
+ /** List artifacts for a run in creation order. */
486
+ listArtifacts(runId: string): AgentLoopArtifactRecord[];
487
+ /** Add an artifact id to an event without duplicating existing links. */
488
+ linkArtifactToEvent(eventId: string, artifactId: string): void;
489
+ /** Return the current status, latest run, and newest open gate. */
490
+ getCurrentStatus(): {
491
+ status: AgentLoopStatus;
492
+ run?: AgentLoopRun;
493
+ gate?: {
494
+ kind: AgentLoopGateKind;
495
+ message: string;
496
+ details?: unknown;
497
+ };
498
+ };
499
+ /** List recent ledger events newest-first, or sinceSeq deltas oldest-first for polling. */
500
+ listEvents(options?: number | { sinceSeq?: number; limit?: number }): AgentLoopEvent[];
501
+ /** List normalized agent timeline entries using an opaque cursor. */
502
+ listAgentTimeline(query?: AgentTimelineQuery): AgentTimelinePage;
503
+ /** Check whether the derived timeline index and triggers are present. */
504
+ checkTimelineIntegrity(): AgentTimelineIntegrityReport;
505
+ /** Upsert a pull request link for the run. */
506
+ upsertPrLink(link: Omit<AgentLoopPrLink, "id" | "createdAt" | "updatedAt">): AgentLoopPrLink;
507
+ /** Return the newest PR link for a run. */
508
+ getPrLink(runId: string): AgentLoopPrLink | undefined;
509
+ /** Replace the latest observed CI checks for a run and PR. */
510
+ replaceCiChecks(runId: string, prNumber: number, checks: Array<Omit<AgentLoopCiCheck, "id" | "runId" | "prNumber" | "observedAt">>): AgentLoopCiCheck[];
511
+ /** List stored CI checks for a run. */
512
+ listCiChecks(runId: string): AgentLoopCiCheck[];
513
+ /** Replace review comments for a run and PR. */
514
+ replaceReviewComments(runId: string, prNumber: number, comments: Array<Omit<AgentLoopReviewComment, "id" | "runId" | "prNumber" | "observedAt">>): AgentLoopReviewComment[];
515
+ /** List stored review comments for a run. */
516
+ listReviewComments(runId: string): AgentLoopReviewComment[];
517
+ /** Append a lifecycle decision. */
518
+ appendDecision(decision: Omit<AgentLoopDecision, "id" | "createdAt">): AgentLoopDecision;
519
+ /** List lifecycle decisions newest-first. */
520
+ listDecisions(runId: string): AgentLoopDecision[];
521
+ /** Create a persisted worker execution row. */
522
+ createWorker(worker: {
523
+ runId: string;
524
+ type: WorkerType;
525
+ backend: string;
526
+ attempt: number;
527
+ resumeUsed: boolean;
528
+ }): WorkerRun;
529
+ /** Update worker metadata after JSONL ingest, completion, or failure. */
530
+ updateWorker(workerId: string, patch: {
531
+ status?: WorkerStatus;
532
+ threadId?: string;
533
+ completedAt?: string;
534
+ exitCode?: number;
535
+ resultArtifactId?: string;
536
+ rawJsonlArtifactId?: string;
537
+ error?: string;
538
+ }): WorkerRun;
539
+ /** Return any currently running worker. */
540
+ getRunningWorker(): WorkerRun | undefined;
541
+ /** List persisted workers newest-first, optionally scoped to a run. */
542
+ listWorkers(runId?: string, limit?: number): WorkerRun[];
543
+ /** Append a normalized worker JSONL event. */
544
+ appendWorkerEvent(event: Omit<WorkerEvent, "id" | "seq" | "createdAt">): WorkerEvent;
545
+ /** List worker events for one worker in creation order. */
546
+ listWorkerEvents(workerId: string): WorkerEvent[];
547
+ }
548
+
549
+ /** Single diagnostic check emitted by `agent-loop doctor`. */
550
+ export interface DoctorCheck {
551
+ name: string;
552
+ status: "pass" | "warn" | "fail";
553
+ message: string;
554
+ details?: unknown;
555
+ }
556
+
557
+ /** Structured doctor output used by humans, tests, and future control surfaces. */
558
+ export interface DoctorReport {
559
+ status: "pass" | "warn" | "fail";
560
+ checks: DoctorCheck[];
561
+ gate?: AgentLoopGateKind;
562
+ }
563
+
564
+ export interface LoadedConfig {
565
+ path: string;
566
+ config: AgentLoopConfig;
567
+ }