specrails-core 5.2.3 → 5.4.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 (165) hide show
  1. package/README.md +3 -0
  2. package/bin/specrails-core.mjs +5 -0
  3. package/dist/agent-runtime/capabilities.d.ts +27 -0
  4. package/dist/agent-runtime/capabilities.js +73 -0
  5. package/dist/agent-runtime/capabilities.js.map +1 -0
  6. package/dist/agent-runtime/cli-executor.d.ts +43 -0
  7. package/dist/agent-runtime/cli-executor.js +405 -0
  8. package/dist/agent-runtime/cli-executor.js.map +1 -0
  9. package/dist/agent-runtime/cli-process.d.ts +32 -0
  10. package/dist/agent-runtime/cli-process.js +159 -0
  11. package/dist/agent-runtime/cli-process.js.map +1 -0
  12. package/dist/agent-runtime/cli.d.ts +39 -0
  13. package/dist/agent-runtime/cli.js +216 -0
  14. package/dist/agent-runtime/cli.js.map +1 -0
  15. package/dist/agent-runtime/codex-schema.d.ts +4 -0
  16. package/dist/agent-runtime/codex-schema.js +31 -0
  17. package/dist/agent-runtime/codex-schema.js.map +1 -0
  18. package/dist/agent-runtime/config.d.ts +11 -0
  19. package/dist/agent-runtime/config.js +263 -0
  20. package/dist/agent-runtime/config.js.map +1 -0
  21. package/dist/agent-runtime/core-host.d.ts +41 -0
  22. package/dist/agent-runtime/core-host.js +132 -0
  23. package/dist/agent-runtime/core-host.js.map +1 -0
  24. package/dist/agent-runtime/durable-store.d.ts +22 -0
  25. package/dist/agent-runtime/durable-store.js +205 -0
  26. package/dist/agent-runtime/durable-store.js.map +1 -0
  27. package/dist/agent-runtime/efficiency-summary.d.ts +67 -0
  28. package/dist/agent-runtime/efficiency-summary.js +52 -0
  29. package/dist/agent-runtime/efficiency-summary.js.map +1 -0
  30. package/dist/agent-runtime/efficiency-types.d.ts +60 -0
  31. package/dist/agent-runtime/efficiency-types.js +8 -0
  32. package/dist/agent-runtime/efficiency-types.js.map +1 -0
  33. package/dist/agent-runtime/efficiency.d.ts +5 -0
  34. package/dist/agent-runtime/efficiency.js +35 -0
  35. package/dist/agent-runtime/efficiency.js.map +1 -0
  36. package/dist/agent-runtime/evaluation-corpus.d.ts +13 -0
  37. package/dist/agent-runtime/evaluation-corpus.js +8 -0
  38. package/dist/agent-runtime/evaluation-corpus.js.map +1 -0
  39. package/dist/agent-runtime/evaluation.d.ts +43 -0
  40. package/dist/agent-runtime/evaluation.js +171 -0
  41. package/dist/agent-runtime/evaluation.js.map +1 -0
  42. package/dist/agent-runtime/executor-types.d.ts +125 -0
  43. package/dist/agent-runtime/executor-types.js +29 -0
  44. package/dist/agent-runtime/executor-types.js.map +1 -0
  45. package/dist/agent-runtime/executors.d.ts +23 -0
  46. package/dist/agent-runtime/executors.js +48 -0
  47. package/dist/agent-runtime/executors.js.map +1 -0
  48. package/dist/agent-runtime/gemini-policy.d.ts +8 -0
  49. package/dist/agent-runtime/gemini-policy.js +36 -0
  50. package/dist/agent-runtime/gemini-policy.js.map +1 -0
  51. package/dist/agent-runtime/graph/artifacts.d.ts +26 -0
  52. package/dist/agent-runtime/graph/artifacts.js +205 -0
  53. package/dist/agent-runtime/graph/artifacts.js.map +1 -0
  54. package/dist/agent-runtime/graph/nodes.d.ts +39 -0
  55. package/dist/agent-runtime/graph/nodes.js +321 -0
  56. package/dist/agent-runtime/graph/nodes.js.map +1 -0
  57. package/dist/agent-runtime/graph/review-policy.d.ts +18 -0
  58. package/dist/agent-runtime/graph/review-policy.js +32 -0
  59. package/dist/agent-runtime/graph/review-policy.js.map +1 -0
  60. package/dist/agent-runtime/graph/roles.d.ts +47 -0
  61. package/dist/agent-runtime/graph/roles.js +190 -0
  62. package/dist/agent-runtime/graph/roles.js.map +1 -0
  63. package/dist/agent-runtime/graph/state.d.ts +83 -0
  64. package/dist/agent-runtime/graph/state.js +23 -0
  65. package/dist/agent-runtime/graph/state.js.map +1 -0
  66. package/dist/agent-runtime/graph-checkpointer.d.ts +61 -0
  67. package/dist/agent-runtime/graph-checkpointer.js +137 -0
  68. package/dist/agent-runtime/graph-checkpointer.js.map +1 -0
  69. package/dist/agent-runtime/index.d.ts +20 -0
  70. package/dist/agent-runtime/index.js +21 -0
  71. package/dist/agent-runtime/index.js.map +1 -0
  72. package/dist/agent-runtime/kimi-acp.d.ts +11 -0
  73. package/dist/agent-runtime/kimi-acp.js +190 -0
  74. package/dist/agent-runtime/kimi-acp.js.map +1 -0
  75. package/dist/agent-runtime/openai-executor.d.ts +26 -0
  76. package/dist/agent-runtime/openai-executor.js +192 -0
  77. package/dist/agent-runtime/openai-executor.js.map +1 -0
  78. package/dist/agent-runtime/openspec-tool-server.d.ts +1 -0
  79. package/dist/agent-runtime/openspec-tool-server.js +37 -0
  80. package/dist/agent-runtime/openspec-tool-server.js.map +1 -0
  81. package/dist/agent-runtime/openspec.d.ts +123 -0
  82. package/dist/agent-runtime/openspec.js +263 -0
  83. package/dist/agent-runtime/openspec.js.map +1 -0
  84. package/dist/agent-runtime/prompts.d.ts +44 -0
  85. package/dist/agent-runtime/prompts.js +310 -0
  86. package/dist/agent-runtime/prompts.js.map +1 -0
  87. package/dist/agent-runtime/provider-diagnostic.d.ts +2 -0
  88. package/dist/agent-runtime/provider-diagnostic.js +25 -0
  89. package/dist/agent-runtime/provider-diagnostic.js.map +1 -0
  90. package/dist/agent-runtime/repository-context.d.ts +25 -0
  91. package/dist/agent-runtime/repository-context.js +100 -0
  92. package/dist/agent-runtime/repository-context.js.map +1 -0
  93. package/dist/agent-runtime/review-context.d.ts +14 -0
  94. package/dist/agent-runtime/review-context.js +41 -0
  95. package/dist/agent-runtime/review-context.js.map +1 -0
  96. package/dist/agent-runtime/role-routing.d.ts +10 -0
  97. package/dist/agent-runtime/role-routing.js +29 -0
  98. package/dist/agent-runtime/role-routing.js.map +1 -0
  99. package/dist/agent-runtime/role-state.d.ts +19 -0
  100. package/dist/agent-runtime/role-state.js +24 -0
  101. package/dist/agent-runtime/role-state.js.map +1 -0
  102. package/dist/agent-runtime/runtime-identity.d.ts +11 -0
  103. package/dist/agent-runtime/runtime-identity.js +33 -0
  104. package/dist/agent-runtime/runtime-identity.js.map +1 -0
  105. package/dist/agent-runtime/tool-event.d.ts +3 -0
  106. package/dist/agent-runtime/tool-event.js +24 -0
  107. package/dist/agent-runtime/tool-event.js.map +1 -0
  108. package/dist/agent-runtime/verification-plan.d.ts +55 -0
  109. package/dist/agent-runtime/verification-plan.js +206 -0
  110. package/dist/agent-runtime/verification-plan.js.map +1 -0
  111. package/dist/agent-runtime/workflow-types.d.ts +226 -0
  112. package/dist/agent-runtime/workflow-types.js +2 -0
  113. package/dist/agent-runtime/workflow-types.js.map +1 -0
  114. package/dist/agent-runtime/workflow.d.ts +17 -0
  115. package/dist/agent-runtime/workflow.js +636 -0
  116. package/dist/agent-runtime/workflow.js.map +1 -0
  117. package/dist/agent-runtime/workspace-tools.d.ts +29 -0
  118. package/dist/agent-runtime/workspace-tools.js +282 -0
  119. package/dist/agent-runtime/workspace-tools.js.map +1 -0
  120. package/dist/installer/cli.d.ts +35 -0
  121. package/dist/installer/cli.js +3 -0
  122. package/dist/installer/cli.js.map +1 -1
  123. package/dist/installer/commands/doctor.d.ts +27 -0
  124. package/dist/installer/commands/framework.d.ts +85 -0
  125. package/dist/installer/commands/init.d.ts +147 -0
  126. package/dist/installer/commands/update.d.ts +56 -0
  127. package/dist/installer/commands/v5-migration.d.ts +32 -0
  128. package/dist/installer/phases/framework-lifecycle.d.ts +53 -0
  129. package/dist/installer/phases/install-config.d.ts +64 -0
  130. package/dist/installer/phases/manifest.d.ts +45 -0
  131. package/dist/installer/phases/prereqs.d.ts +51 -0
  132. package/dist/installer/phases/provider-detect.d.ts +89 -0
  133. package/dist/installer/phases/scaffold.d.ts +211 -0
  134. package/dist/installer/phases/scaffold.js +39 -109
  135. package/dist/installer/phases/scaffold.js.map +1 -1
  136. package/dist/installer/runtime/kimi.d.ts +84 -0
  137. package/dist/installer/runtime/pipeline-state.d.ts +351 -0
  138. package/dist/installer/runtime/pipeline-state.js +514 -41
  139. package/dist/installer/runtime/pipeline-state.js.map +1 -1
  140. package/dist/installer/util/errors.d.ts +46 -0
  141. package/dist/installer/util/exec.d.ts +41 -0
  142. package/dist/installer/util/fs.d.ts +153 -0
  143. package/dist/installer/util/git.d.ts +44 -0
  144. package/dist/installer/util/install-transaction.d.ts +29 -0
  145. package/dist/installer/util/logger.d.ts +31 -0
  146. package/dist/installer/util/paths.d.ts +34 -0
  147. package/dist/installer/util/prompts.d.ts +23 -0
  148. package/dist/installer/util/registry.d.ts +174 -0
  149. package/dist/installer/util/template.d.ts +23 -0
  150. package/docs/README.md +1 -0
  151. package/docs/agent-runtime-efficiency.md +65 -0
  152. package/docs/agent-runtime.md +339 -0
  153. package/integration-contract.json +80 -7
  154. package/package.json +20 -2
  155. package/schemas/agent-runtime.schema.json +77 -0
  156. package/schemas/fixtures/runtime-efficiency-summary.v1.json +790 -0
  157. package/templates/codex-skills/batch-implement/SKILL.md +33 -58
  158. package/templates/codex-skills/implement/SKILL.md +21 -124
  159. package/templates/codex-skills/retry/SKILL.md +8 -34
  160. package/templates/commands/specrails/batch-implement.md +21 -16
  161. package/templates/commands/specrails/implement.md +17 -276
  162. package/templates/commands/specrails/retry.md +6 -34
  163. package/templates/gemini-commands/batch-implement.toml +34 -28
  164. package/templates/gemini-commands/implement.toml +34 -55
  165. package/templates/gemini-commands/retry.toml +10 -16
@@ -0,0 +1,226 @@
1
+ import type { AnnotationRoot } from '@langchain/langgraph';
2
+ import type { ProviderInvocation } from './efficiency-types.js';
3
+ /** JSON-only contracts keep checkpoints portable and independent of executors. */
4
+ export type JsonValue = null | boolean | number | string | JsonValue[] | {
5
+ [key: string]: JsonValue;
6
+ };
7
+ export type StepStatus = 'succeeded' | 'failed' | 'blocked' | 'paused';
8
+ export type WorkflowStatus = 'running' | StepStatus | 'cancelled';
9
+ export interface StepUsage {
10
+ costUsd?: number | null;
11
+ inputTokens?: number | null;
12
+ outputTokens?: number | null;
13
+ }
14
+ export interface WorkflowBudget {
15
+ maxCostUsd?: number;
16
+ maxTokens?: number;
17
+ maxDurationMs?: number;
18
+ }
19
+ /** A node asks the host to pause: the run resumes only with the matching answer. */
20
+ export type InterruptRequest = {
21
+ kind: 'approval';
22
+ reason: string;
23
+ } | {
24
+ kind: 'question';
25
+ question: string;
26
+ };
27
+ export type InterruptResume = {
28
+ approved: true;
29
+ } | {
30
+ answer: string;
31
+ };
32
+ export interface NodeResult<S extends Record<string, unknown>> {
33
+ /** Nodes pause through `context.interrupt`, never through a result. */
34
+ status: Exclude<StepStatus, 'paused'>;
35
+ /** Graph state update, merged through the schema's reducers. */
36
+ update?: Partial<S>;
37
+ /** Ledger output: kept in the checkpoint receipt and exposed by `runtime status`. */
38
+ output?: JsonValue;
39
+ error?: string;
40
+ /** Omit for the node's first declared successor; null completes the workflow. */
41
+ next?: string | null;
42
+ /** Usage not already reported through `context.reportUsage`. */
43
+ usage?: StepUsage;
44
+ retryable?: boolean;
45
+ }
46
+ export interface WorkflowStepContext {
47
+ runId: string;
48
+ stepId: string;
49
+ /** Stable identifier for this invocation, suitable for external idempotency keys. */
50
+ attemptId: string;
51
+ attempt: number;
52
+ input: JsonValue;
53
+ signal: AbortSignal;
54
+ /** A detached snapshot; modifying it cannot modify the persisted run. */
55
+ checkpoint: WorkflowState;
56
+ /** The interrupt this node raised earlier, when the host now resumes it with an answer or approval. */
57
+ pending?: InterruptRequest;
58
+ /**
59
+ * Pause the workflow until the host resumes it. Throws on the first call; on
60
+ * a resumed node it returns the host's answer immediately, so collect it
61
+ * before repeating any work.
62
+ */
63
+ interrupt<R extends InterruptResume = InterruptResume>(request: InterruptRequest): R;
64
+ /** Account provider spend as soon as it is known; a later pause or failure keeps it. */
65
+ reportUsage(usage: StepUsage): void;
66
+ /** Persist a completed provider call with its already-reported usage. Optional for custom hosts. */
67
+ reportEfficiencyActivity?(kind: string, payload: Record<string, string | number | null>): Promise<void>;
68
+ reportInvocationStarted?(invocation: Omit<import('./efficiency-types.js').PendingProviderInvocation, 'invocationId' | 'ordinal'>): Promise<{
69
+ invocationId: string;
70
+ ordinal: number;
71
+ }>;
72
+ reportInvocation?(invocation: ProviderInvocation): Promise<void>;
73
+ /** Budget left for the next provider call, after everything reported so far. */
74
+ remainingBudget(): {
75
+ maxTokens?: number;
76
+ maxCostUsd?: number;
77
+ maxDurationMs?: number;
78
+ };
79
+ }
80
+ export interface WorkflowNode<S extends Record<string, unknown>> {
81
+ effect?: 'read' | 'write';
82
+ maxAttempts?: number;
83
+ /** Explicitly opt a write step into retries after a reported retryable failure. */
84
+ retrySafe?: boolean;
85
+ /** Declared successors; the first is the default when a result omits `next`. */
86
+ ends: string[];
87
+ run(state: S, context: WorkflowStepContext): Promise<NodeResult<S>>;
88
+ }
89
+ export interface WorkflowDefinition<S extends Record<string, unknown> = Record<string, unknown>> {
90
+ id: string;
91
+ version: string;
92
+ /** LangGraph state schema; every field must be plain JSON. Any `Annotation.Root` is accepted. */
93
+ schema: AnnotationRoot<any>;
94
+ entry: string;
95
+ /** Declaration order defines "downstream" for invalidation. */
96
+ nodes: Record<string, WorkflowNode<S>>;
97
+ /** Maximum visits across conditional loops, independent of per-visit retries. */
98
+ maxTransitions?: number;
99
+ }
100
+ export interface StepRecord {
101
+ id: string;
102
+ status: 'pending' | 'running' | 'interrupted' | StepStatus;
103
+ effect: 'read' | 'write';
104
+ visits: number;
105
+ attempt: number;
106
+ attemptId?: string;
107
+ output?: JsonValue;
108
+ /** The graph state update of the last successful visit, replayed when a lost checkpoint re-runs the node. */
109
+ update?: JsonValue;
110
+ /** The successor chosen by the last successful visit; null completed the workflow. */
111
+ next?: string | null;
112
+ error?: string;
113
+ startedAt?: string;
114
+ completedAt?: string;
115
+ }
116
+ export interface StepAttemptRecord {
117
+ id: string;
118
+ stepId: string;
119
+ attempt: number;
120
+ visit: number;
121
+ status: 'running' | 'interrupted' | StepStatus;
122
+ startedAt: string;
123
+ completedAt?: string;
124
+ output?: JsonValue;
125
+ error?: string;
126
+ usage?: StepUsage;
127
+ pendingInvocations?: import('./efficiency-types.js').PendingProviderInvocation[];
128
+ invocations?: ProviderInvocation[];
129
+ }
130
+ export interface WorkflowEvent {
131
+ id: string;
132
+ sequence: number;
133
+ runId: string;
134
+ /** Trace correlation: the run's trace and the attempt span this event belongs to. */
135
+ traceId: string;
136
+ spanId?: string;
137
+ efficiencyActivity?: {
138
+ kind: string;
139
+ payload: Record<string, string | number | null>;
140
+ };
141
+ efficiency?: ProviderInvocation;
142
+ type: 'efficiency_updated' | 'workflow_started' | 'workflow_resumed' | 'workflow_invalidated' | 'workflow_succeeded' | 'workflow_failed' | 'workflow_blocked' | 'workflow_paused' | 'workflow_cancelled' | 'step_started' | 'step_succeeded' | 'step_failed' | 'step_blocked' | 'step_paused' | 'step_interrupted';
143
+ timestamp: string;
144
+ stepId?: string;
145
+ attemptId?: string;
146
+ usage?: StepUsage;
147
+ message?: string;
148
+ }
149
+ /** One completed step attempt, shaped for tracing back ends (OpenTelemetry or otherwise). */
150
+ export interface WorkflowSpan {
151
+ traceId: string;
152
+ spanId: string;
153
+ name: string;
154
+ stepId: string;
155
+ attempt: number;
156
+ visit: number;
157
+ startedAt: string;
158
+ endedAt: string;
159
+ status: 'running' | 'interrupted' | StepStatus;
160
+ usage?: StepUsage;
161
+ error?: string;
162
+ }
163
+ export interface WorkflowState {
164
+ schemaVersion: 2;
165
+ runId: string;
166
+ /** Stable trace identifier for every event and span of this run. */
167
+ traceId: string;
168
+ workflowId: string;
169
+ workflowVersion: string;
170
+ workflowFingerprint: string;
171
+ inputFingerprint: string;
172
+ status: WorkflowStatus;
173
+ createdAt: string;
174
+ updatedAt: string;
175
+ nextStep: string | null;
176
+ nextAttempt: number;
177
+ transitions: number;
178
+ executionCount: number;
179
+ steps: Record<string, StepRecord>;
180
+ history: StepAttemptRecord[];
181
+ events: WorkflowEvent[];
182
+ budget: WorkflowBudget;
183
+ usage: {
184
+ costUsd: number | null;
185
+ inputTokens: number | null;
186
+ outputTokens: number | null;
187
+ /** Known lower bounds, even when some providers omit usage. */
188
+ knownCostUsd: number;
189
+ knownTokens: number;
190
+ durationMs: number;
191
+ };
192
+ pendingApproval?: {
193
+ stepId: string;
194
+ requestedAt: string;
195
+ grantedAt?: string;
196
+ reason?: string;
197
+ };
198
+ pendingQuestion?: {
199
+ stepId: string;
200
+ requestedAt: string;
201
+ question: string;
202
+ answeredAt?: string;
203
+ answer?: string;
204
+ };
205
+ error?: string;
206
+ }
207
+ export interface RunWorkflowOptions<S extends Record<string, unknown> = Record<string, unknown>> {
208
+ directory: string;
209
+ runId: string;
210
+ workflow: WorkflowDefinition<S>;
211
+ input: JsonValue;
212
+ budget?: WorkflowBudget;
213
+ signal?: AbortSignal;
214
+ resume?: boolean;
215
+ approve?: string[];
216
+ /** Answer to the pending question; resumes the node that asked it. */
217
+ answer?: string;
218
+ recoverInterrupted?: string[];
219
+ /** Invalidating a step also invalidates all later declared steps. */
220
+ invalidate?: string[];
221
+ validateCompleted?: (stepId: string, record: StepRecord, state: WorkflowState) => Promise<boolean>;
222
+ /** Notification is after durable commit. Observer failures never replay effects. */
223
+ onEvent?: (event: WorkflowEvent) => void | Promise<void>;
224
+ /** One span per finished step attempt, after durable commit. */
225
+ onSpan?: (span: WorkflowSpan) => void | Promise<void>;
226
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=workflow-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"workflow-types.js","sourceRoot":"","sources":["../../src/agent-runtime/workflow-types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,17 @@
1
+ import type { RunWorkflowOptions, WorkflowState } from './workflow-types.js';
2
+ export * from './workflow-types.js';
3
+ export { readWorkflowState, readWorkflowEnvelope, writeWorkflowEnvelope, WorkflowStoreError, type WorkflowEnvelope } from './durable-store.js';
4
+ export declare class WorkflowError extends Error {
5
+ readonly code: 'INVALID_WORKFLOW' | 'ALREADY_EXISTS' | 'NOT_FOUND' | 'INCOMPATIBLE_RESUME';
6
+ constructor(code: 'INVALID_WORKFLOW' | 'ALREADY_EXISTS' | 'NOT_FOUND' | 'INCOMPATIBLE_RESUME', message: string);
7
+ }
8
+ /**
9
+ * Execute a LangGraph state graph with a durable host ledger at every effect
10
+ * boundary. LangGraph owns traversal, state reducers, checkpoints, interrupts
11
+ * and time travel; the ledger owns receipts, usage, budgets, leases and
12
+ * interrupted-write recovery, and it is authoritative for which node runs
13
+ * next. Both are written through one atomic envelope, so they cannot disagree
14
+ * after a crash. Cancellation is cooperative; node callbacks must settle only
15
+ * after their owned subprocesses/tools have stopped.
16
+ */
17
+ export declare function runWorkflow<S extends Record<string, unknown>>(options: RunWorkflowOptions<S>): Promise<WorkflowState>;