iosm-cli 0.1.3 → 0.2.1

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 (132) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +88 -46
  3. package/dist/core/agent-teams.d.ts.map +1 -1
  4. package/dist/core/agent-teams.js +38 -11
  5. package/dist/core/agent-teams.js.map +1 -1
  6. package/dist/core/blast.d.ts +62 -0
  7. package/dist/core/blast.d.ts.map +1 -0
  8. package/dist/core/blast.js +448 -0
  9. package/dist/core/blast.js.map +1 -0
  10. package/dist/core/contract.d.ts +54 -0
  11. package/dist/core/contract.d.ts.map +1 -0
  12. package/dist/core/contract.js +300 -0
  13. package/dist/core/contract.js.map +1 -0
  14. package/dist/core/failure-retrospective.d.ts +12 -0
  15. package/dist/core/failure-retrospective.d.ts.map +1 -0
  16. package/dist/core/failure-retrospective.js +115 -0
  17. package/dist/core/failure-retrospective.js.map +1 -0
  18. package/dist/core/project-index/index.d.ts +17 -0
  19. package/dist/core/project-index/index.d.ts.map +1 -0
  20. package/dist/core/project-index/index.js +323 -0
  21. package/dist/core/project-index/index.js.map +1 -0
  22. package/dist/core/project-index/types.d.ts +34 -0
  23. package/dist/core/project-index/types.d.ts.map +1 -0
  24. package/dist/core/project-index/types.js +2 -0
  25. package/dist/core/project-index/types.js.map +1 -0
  26. package/dist/core/sdk.d.ts.map +1 -1
  27. package/dist/core/sdk.js +8 -0
  28. package/dist/core/sdk.js.map +1 -1
  29. package/dist/core/semantic/config.d.ts.map +1 -1
  30. package/dist/core/semantic/config.js +5 -0
  31. package/dist/core/semantic/config.js.map +1 -1
  32. package/dist/core/semantic/index.d.ts +1 -1
  33. package/dist/core/semantic/index.d.ts.map +1 -1
  34. package/dist/core/semantic/index.js +1 -1
  35. package/dist/core/semantic/index.js.map +1 -1
  36. package/dist/core/semantic/runtime.d.ts.map +1 -1
  37. package/dist/core/semantic/runtime.js +12 -1
  38. package/dist/core/semantic/runtime.js.map +1 -1
  39. package/dist/core/semantic/types.d.ts +6 -0
  40. package/dist/core/semantic/types.d.ts.map +1 -1
  41. package/dist/core/semantic/types.js +6 -0
  42. package/dist/core/semantic/types.js.map +1 -1
  43. package/dist/core/shadow-guard.d.ts +30 -0
  44. package/dist/core/shadow-guard.d.ts.map +1 -0
  45. package/dist/core/shadow-guard.js +81 -0
  46. package/dist/core/shadow-guard.js.map +1 -0
  47. package/dist/core/shared-memory.d.ts +46 -0
  48. package/dist/core/shared-memory.d.ts.map +1 -0
  49. package/dist/core/shared-memory.js +253 -0
  50. package/dist/core/shared-memory.js.map +1 -0
  51. package/dist/core/singular.d.ts +73 -0
  52. package/dist/core/singular.d.ts.map +1 -0
  53. package/dist/core/singular.js +413 -0
  54. package/dist/core/singular.js.map +1 -0
  55. package/dist/core/slash-commands.d.ts.map +1 -1
  56. package/dist/core/slash-commands.js +14 -2
  57. package/dist/core/slash-commands.js.map +1 -1
  58. package/dist/core/subagents.js +1 -1
  59. package/dist/core/subagents.js.map +1 -1
  60. package/dist/core/swarm/gates.d.ts +9 -0
  61. package/dist/core/swarm/gates.d.ts.map +1 -0
  62. package/dist/core/swarm/gates.js +65 -0
  63. package/dist/core/swarm/gates.js.map +1 -0
  64. package/dist/core/swarm/index.d.ts +9 -0
  65. package/dist/core/swarm/index.d.ts.map +1 -0
  66. package/dist/core/swarm/index.js +9 -0
  67. package/dist/core/swarm/index.js.map +1 -0
  68. package/dist/core/swarm/locks.d.ts +21 -0
  69. package/dist/core/swarm/locks.d.ts.map +1 -0
  70. package/dist/core/swarm/locks.js +93 -0
  71. package/dist/core/swarm/locks.js.map +1 -0
  72. package/dist/core/swarm/planner.d.ts +16 -0
  73. package/dist/core/swarm/planner.d.ts.map +1 -0
  74. package/dist/core/swarm/planner.js +137 -0
  75. package/dist/core/swarm/planner.js.map +1 -0
  76. package/dist/core/swarm/retry.d.ts +16 -0
  77. package/dist/core/swarm/retry.d.ts.map +1 -0
  78. package/dist/core/swarm/retry.js +32 -0
  79. package/dist/core/swarm/retry.js.map +1 -0
  80. package/dist/core/swarm/scheduler.d.ts +48 -0
  81. package/dist/core/swarm/scheduler.d.ts.map +1 -0
  82. package/dist/core/swarm/scheduler.js +554 -0
  83. package/dist/core/swarm/scheduler.js.map +1 -0
  84. package/dist/core/swarm/spawn.d.ts +16 -0
  85. package/dist/core/swarm/spawn.d.ts.map +1 -0
  86. package/dist/core/swarm/spawn.js +42 -0
  87. package/dist/core/swarm/spawn.js.map +1 -0
  88. package/dist/core/swarm/state-store.d.ts +35 -0
  89. package/dist/core/swarm/state-store.d.ts.map +1 -0
  90. package/dist/core/swarm/state-store.js +106 -0
  91. package/dist/core/swarm/state-store.js.map +1 -0
  92. package/dist/core/swarm/types.d.ts +116 -0
  93. package/dist/core/swarm/types.d.ts.map +1 -0
  94. package/dist/core/swarm/types.js +2 -0
  95. package/dist/core/swarm/types.js.map +1 -0
  96. package/dist/core/system-prompt.d.ts.map +1 -1
  97. package/dist/core/system-prompt.js +6 -3
  98. package/dist/core/system-prompt.js.map +1 -1
  99. package/dist/core/tools/semantic-search.d.ts.map +1 -1
  100. package/dist/core/tools/semantic-search.js +1 -0
  101. package/dist/core/tools/semantic-search.js.map +1 -1
  102. package/dist/core/tools/shared-memory.d.ts +23 -0
  103. package/dist/core/tools/shared-memory.d.ts.map +1 -0
  104. package/dist/core/tools/shared-memory.js +134 -0
  105. package/dist/core/tools/shared-memory.js.map +1 -0
  106. package/dist/core/tools/task.d.ts +8 -1
  107. package/dist/core/tools/task.d.ts.map +1 -1
  108. package/dist/core/tools/task.js +664 -123
  109. package/dist/core/tools/task.js.map +1 -1
  110. package/dist/main.d.ts.map +1 -1
  111. package/dist/main.js +8 -1
  112. package/dist/main.js.map +1 -1
  113. package/dist/modes/interactive/components/custom-editor.d.ts +8 -0
  114. package/dist/modes/interactive/components/custom-editor.d.ts.map +1 -1
  115. package/dist/modes/interactive/components/custom-editor.js +70 -1
  116. package/dist/modes/interactive/components/custom-editor.js.map +1 -1
  117. package/dist/modes/interactive/components/login-dialog.d.ts +1 -0
  118. package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
  119. package/dist/modes/interactive/components/login-dialog.js +27 -4
  120. package/dist/modes/interactive/components/login-dialog.js.map +1 -1
  121. package/dist/modes/interactive/components/subagent-message.d.ts.map +1 -1
  122. package/dist/modes/interactive/components/subagent-message.js +14 -0
  123. package/dist/modes/interactive/components/subagent-message.js.map +1 -1
  124. package/dist/modes/interactive/interactive-mode.d.ts +81 -0
  125. package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
  126. package/dist/modes/interactive/interactive-mode.js +3481 -870
  127. package/dist/modes/interactive/interactive-mode.js.map +1 -1
  128. package/docs/cli-reference.md +29 -1
  129. package/docs/configuration.md +5 -0
  130. package/docs/interactive-mode.md +171 -2
  131. package/docs/orchestration-and-subagents.md +96 -169
  132. package/package.json +4 -3
@@ -0,0 +1,300 @@
1
+ import AjvModule from "ajv";
2
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
4
+ const Ajv = AjvModule.default || AjvModule;
5
+ const ajv = new Ajv({ allErrors: true, allowUnionTypes: true });
6
+ export class ContractValidationError extends Error {
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "ContractValidationError";
10
+ }
11
+ }
12
+ export class ContractParseError extends Error {
13
+ constructor(filePath, message) {
14
+ super(message);
15
+ this.name = "ContractParseError";
16
+ this.filePath = filePath;
17
+ }
18
+ }
19
+ const CONTRACT_SCHEMA = {
20
+ type: "object",
21
+ additionalProperties: false,
22
+ properties: {
23
+ goal: { type: "string" },
24
+ scope_include: {
25
+ type: "array",
26
+ items: { type: "string" },
27
+ },
28
+ scope_exclude: {
29
+ type: "array",
30
+ items: { type: "string" },
31
+ },
32
+ constraints: {
33
+ type: "array",
34
+ items: { type: "string" },
35
+ },
36
+ quality_gates: {
37
+ type: "array",
38
+ items: { type: "string" },
39
+ },
40
+ definition_of_done: {
41
+ type: "array",
42
+ items: { type: "string" },
43
+ },
44
+ assumptions: {
45
+ type: "array",
46
+ items: { type: "string" },
47
+ },
48
+ non_goals: {
49
+ type: "array",
50
+ items: { type: "string" },
51
+ },
52
+ risks: {
53
+ type: "array",
54
+ items: { type: "string" },
55
+ },
56
+ deliverables: {
57
+ type: "array",
58
+ items: { type: "string" },
59
+ },
60
+ success_metrics: {
61
+ type: "array",
62
+ items: { type: "string" },
63
+ },
64
+ stakeholders: {
65
+ type: "array",
66
+ items: { type: "string" },
67
+ },
68
+ owner: { type: "string" },
69
+ timebox: { type: "string" },
70
+ notes: { type: "string" },
71
+ },
72
+ required: [],
73
+ };
74
+ const validateContract = ajv.compile(CONTRACT_SCHEMA);
75
+ function isRecord(value) {
76
+ return typeof value === "object" && value !== null;
77
+ }
78
+ function normalizeString(value) {
79
+ if (typeof value !== "string")
80
+ return undefined;
81
+ const normalized = value.trim();
82
+ return normalized.length > 0 ? normalized : undefined;
83
+ }
84
+ function normalizeStringArray(value) {
85
+ if (!Array.isArray(value))
86
+ return undefined;
87
+ const normalized = value
88
+ .filter((item) => typeof item === "string")
89
+ .map((item) => item.trim())
90
+ .filter((item) => item.length > 0);
91
+ return normalized.length > 0 ? normalized : undefined;
92
+ }
93
+ function cloneContract(contract) {
94
+ return {
95
+ ...(contract.goal ? { goal: contract.goal } : {}),
96
+ ...(contract.scope_include ? { scope_include: [...contract.scope_include] } : {}),
97
+ ...(contract.scope_exclude ? { scope_exclude: [...contract.scope_exclude] } : {}),
98
+ ...(contract.constraints ? { constraints: [...contract.constraints] } : {}),
99
+ ...(contract.quality_gates ? { quality_gates: [...contract.quality_gates] } : {}),
100
+ ...(contract.definition_of_done ? { definition_of_done: [...contract.definition_of_done] } : {}),
101
+ ...(contract.assumptions ? { assumptions: [...contract.assumptions] } : {}),
102
+ ...(contract.non_goals ? { non_goals: [...contract.non_goals] } : {}),
103
+ ...(contract.risks ? { risks: [...contract.risks] } : {}),
104
+ ...(contract.deliverables ? { deliverables: [...contract.deliverables] } : {}),
105
+ ...(contract.success_metrics ? { success_metrics: [...contract.success_metrics] } : {}),
106
+ ...(contract.stakeholders ? { stakeholders: [...contract.stakeholders] } : {}),
107
+ ...(contract.owner ? { owner: contract.owner } : {}),
108
+ ...(contract.timebox ? { timebox: contract.timebox } : {}),
109
+ ...(contract.notes ? { notes: contract.notes } : {}),
110
+ };
111
+ }
112
+ function formatValidationError(payload) {
113
+ const errors = validateContract.errors ?? [];
114
+ if (errors.length === 0) {
115
+ return `Invalid contract payload: ${JSON.stringify(payload)}`;
116
+ }
117
+ const details = errors
118
+ .map((error) => {
119
+ const path = error.instancePath || "/";
120
+ return `${path} ${error.message ?? "is invalid"}`;
121
+ })
122
+ .join("; ");
123
+ return `Invalid contract payload: ${details}`;
124
+ }
125
+ export function normalizeEngineeringContract(payload) {
126
+ if (!isRecord(payload)) {
127
+ throw new ContractValidationError("Contract payload must be a JSON object.");
128
+ }
129
+ if (!validateContract(payload)) {
130
+ throw new ContractValidationError(formatValidationError(payload));
131
+ }
132
+ const goal = normalizeString(payload.goal);
133
+ const scopeInclude = normalizeStringArray(payload.scope_include);
134
+ const scopeExclude = normalizeStringArray(payload.scope_exclude);
135
+ const constraints = normalizeStringArray(payload.constraints);
136
+ const qualityGates = normalizeStringArray(payload.quality_gates);
137
+ const definitionOfDone = normalizeStringArray(payload.definition_of_done);
138
+ const assumptions = normalizeStringArray(payload.assumptions);
139
+ const nonGoals = normalizeStringArray(payload.non_goals);
140
+ const risks = normalizeStringArray(payload.risks);
141
+ const deliverables = normalizeStringArray(payload.deliverables);
142
+ const successMetrics = normalizeStringArray(payload.success_metrics);
143
+ const stakeholders = normalizeStringArray(payload.stakeholders);
144
+ const owner = normalizeString(payload.owner);
145
+ const timebox = normalizeString(payload.timebox);
146
+ const notes = normalizeString(payload.notes);
147
+ return {
148
+ ...(goal ? { goal } : {}),
149
+ ...(scopeInclude ? { scope_include: scopeInclude } : {}),
150
+ ...(scopeExclude ? { scope_exclude: scopeExclude } : {}),
151
+ ...(constraints ? { constraints } : {}),
152
+ ...(qualityGates ? { quality_gates: qualityGates } : {}),
153
+ ...(definitionOfDone ? { definition_of_done: definitionOfDone } : {}),
154
+ ...(assumptions ? { assumptions } : {}),
155
+ ...(nonGoals ? { non_goals: nonGoals } : {}),
156
+ ...(risks ? { risks } : {}),
157
+ ...(deliverables ? { deliverables } : {}),
158
+ ...(successMetrics ? { success_metrics: successMetrics } : {}),
159
+ ...(stakeholders ? { stakeholders } : {}),
160
+ ...(owner ? { owner } : {}),
161
+ ...(timebox ? { timebox } : {}),
162
+ ...(notes ? { notes } : {}),
163
+ };
164
+ }
165
+ export function deepMergeContracts(base, override) {
166
+ const merged = cloneContract(base);
167
+ for (const [key, value] of Object.entries(override)) {
168
+ if (value === undefined)
169
+ continue;
170
+ if (Array.isArray(value)) {
171
+ merged[key] = [...value];
172
+ continue;
173
+ }
174
+ merged[key] = value;
175
+ }
176
+ return normalizeEngineeringContract(merged);
177
+ }
178
+ function readContractFile(filePath) {
179
+ if (!existsSync(filePath)) {
180
+ return {};
181
+ }
182
+ let parsed;
183
+ try {
184
+ parsed = JSON.parse(readFileSync(filePath, "utf8"));
185
+ }
186
+ catch (error) {
187
+ const message = error instanceof Error ? error.message : String(error);
188
+ throw new ContractParseError(filePath, `Failed to parse contract JSON: ${message}`);
189
+ }
190
+ try {
191
+ return normalizeEngineeringContract(parsed);
192
+ }
193
+ catch (error) {
194
+ const message = error instanceof Error ? error.message : String(error);
195
+ throw new ContractParseError(filePath, message);
196
+ }
197
+ }
198
+ function writeContractFile(filePath, contract) {
199
+ mkdirSync(dirname(filePath), { recursive: true });
200
+ writeFileSync(filePath, `${JSON.stringify(contract, null, 2)}\n`, "utf8");
201
+ }
202
+ export class ContractService {
203
+ constructor(options) {
204
+ this.sessionOverlay = {};
205
+ this.cwd = options.cwd;
206
+ }
207
+ getProjectPath() {
208
+ return join(this.cwd, ".iosm", "contract.json");
209
+ }
210
+ getSessionOverlay() {
211
+ return cloneContract(this.sessionOverlay);
212
+ }
213
+ setSessionOverlay(payload) {
214
+ const normalized = normalizeEngineeringContract(payload);
215
+ this.sessionOverlay = normalized;
216
+ return cloneContract(normalized);
217
+ }
218
+ clearSessionOverlay() {
219
+ this.sessionOverlay = {};
220
+ }
221
+ loadProjectContract() {
222
+ return readContractFile(this.getProjectPath());
223
+ }
224
+ saveProjectContract(payload) {
225
+ const normalized = normalizeEngineeringContract(payload);
226
+ writeContractFile(this.getProjectPath(), normalized);
227
+ return cloneContract(normalized);
228
+ }
229
+ clearProjectContract() {
230
+ const projectPath = this.getProjectPath();
231
+ if (!existsSync(projectPath))
232
+ return false;
233
+ rmSync(projectPath, { force: true });
234
+ return true;
235
+ }
236
+ save(scope, payload) {
237
+ if (scope === "project") {
238
+ return this.saveProjectContract(payload);
239
+ }
240
+ return this.setSessionOverlay(payload);
241
+ }
242
+ clear(scope) {
243
+ if (scope === "project") {
244
+ return this.clearProjectContract();
245
+ }
246
+ this.clearSessionOverlay();
247
+ return true;
248
+ }
249
+ getState() {
250
+ const projectPath = this.getProjectPath();
251
+ const hasProjectFile = existsSync(projectPath);
252
+ const project = this.loadProjectContract();
253
+ const sessionOverlay = this.getSessionOverlay();
254
+ const effective = deepMergeContracts(project, sessionOverlay);
255
+ return {
256
+ projectPath,
257
+ hasProjectFile,
258
+ project,
259
+ sessionOverlay,
260
+ effective,
261
+ };
262
+ }
263
+ buildPromptContext(maxItemsPerList = 4) {
264
+ const state = this.getState();
265
+ const contract = state.effective;
266
+ if (Object.keys(contract).length === 0) {
267
+ return undefined;
268
+ }
269
+ const lines = ["Active engineering contract (effective):"];
270
+ if (contract.goal)
271
+ lines.push(`- goal: ${contract.goal}`);
272
+ const pushList = (label, values) => {
273
+ if (!values || values.length === 0)
274
+ return;
275
+ const preview = values.slice(0, Math.max(1, maxItemsPerList));
276
+ const suffix = values.length > preview.length ? ` (+${values.length - preview.length} more)` : "";
277
+ lines.push(`- ${label}: ${preview.join("; ")}${suffix}`);
278
+ };
279
+ pushList("scope_include", contract.scope_include);
280
+ pushList("scope_exclude", contract.scope_exclude);
281
+ pushList("constraints", contract.constraints);
282
+ pushList("quality_gates", contract.quality_gates);
283
+ pushList("definition_of_done", contract.definition_of_done);
284
+ pushList("assumptions", contract.assumptions);
285
+ pushList("non_goals", contract.non_goals);
286
+ pushList("risks", contract.risks);
287
+ pushList("deliverables", contract.deliverables);
288
+ pushList("success_metrics", contract.success_metrics);
289
+ pushList("stakeholders", contract.stakeholders);
290
+ if (contract.owner)
291
+ lines.push(`- owner: ${contract.owner}`);
292
+ if (contract.timebox)
293
+ lines.push(`- timebox: ${contract.timebox}`);
294
+ if (contract.notes)
295
+ lines.push(`- notes: ${contract.notes}`);
296
+ lines.push("Treat this contract as execution constraints unless user explicitly overrides it.");
297
+ return lines.join("\n");
298
+ }
299
+ }
300
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/core/contract.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,KAAK,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACrF,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAE1C,MAAM,GAAG,GAAI,SAAiB,CAAC,OAAO,IAAI,SAAS,CAAC;AACpD,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC;AA8BhE,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IACjD,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,yBAAyB,CAAC;IACvC,CAAC;CACD;AAED,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAG5C,YAAY,QAAgB,EAAE,OAAe;QAC5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C;QAC7D,KAAK,CAAC,IAAI,CAAC,mFAAmF,CAAC,CAAC;QAChG,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACzB,CAAC;CACD","sourcesContent":["import AjvModule from \"ajv\";\nimport { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\n\nconst Ajv = (AjvModule as any).default || AjvModule;\nconst ajv = new Ajv({ allErrors: true, allowUnionTypes: true });\n\nexport type ContractScope = \"project\" | \"session\";\n\nexport interface EngineeringContract {\n\tgoal?: string;\n\tscope_include?: string[];\n\tscope_exclude?: string[];\n\tconstraints?: string[];\n\tquality_gates?: string[];\n\tdefinition_of_done?: string[];\n\tassumptions?: string[];\n\tnon_goals?: string[];\n\trisks?: string[];\n\tdeliverables?: string[];\n\tsuccess_metrics?: string[];\n\tstakeholders?: string[];\n\towner?: string;\n\ttimebox?: string;\n\tnotes?: string;\n}\n\nexport interface ContractState {\n\tprojectPath: string;\n\thasProjectFile: boolean;\n\tproject: EngineeringContract;\n\tsessionOverlay: EngineeringContract;\n\teffective: EngineeringContract;\n}\n\nexport class ContractValidationError extends Error {\n\tconstructor(message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"ContractValidationError\";\n\t}\n}\n\nexport class ContractParseError extends Error {\n\treadonly filePath: string;\n\n\tconstructor(filePath: string, message: string) {\n\t\tsuper(message);\n\t\tthis.name = \"ContractParseError\";\n\t\tthis.filePath = filePath;\n\t}\n}\n\ntype ContractSchemaPayload = {\n\tgoal?: string;\n\tscope_include?: string[];\n\tscope_exclude?: string[];\n\tconstraints?: string[];\n\tquality_gates?: string[];\n\tdefinition_of_done?: string[];\n\tassumptions?: string[];\n\tnon_goals?: string[];\n\trisks?: string[];\n\tdeliverables?: string[];\n\tsuccess_metrics?: string[];\n\tstakeholders?: string[];\n\towner?: string;\n\ttimebox?: string;\n\tnotes?: string;\n};\n\nconst CONTRACT_SCHEMA = {\n\ttype: \"object\",\n\tadditionalProperties: false,\n\tproperties: {\n\t\tgoal: { type: \"string\" },\n\t\tscope_include: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\tscope_exclude: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\tconstraints: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\tquality_gates: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\tdefinition_of_done: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\tassumptions: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\tnon_goals: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\trisks: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\tdeliverables: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\tsuccess_metrics: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\tstakeholders: {\n\t\t\ttype: \"array\",\n\t\t\titems: { type: \"string\" },\n\t\t},\n\t\towner: { type: \"string\" },\n\t\ttimebox: { type: \"string\" },\n\t\tnotes: { type: \"string\" },\n\t},\n\trequired: [],\n} as const;\n\nconst validateContract = ajv.compile(CONTRACT_SCHEMA as any) as {\n\t(payload: unknown): boolean;\n\terrors?: Array<{ instancePath?: string; message?: string }>;\n};\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === \"object\" && value !== null;\n}\n\nfunction normalizeString(value: unknown): string | undefined {\n\tif (typeof value !== \"string\") return undefined;\n\tconst normalized = value.trim();\n\treturn normalized.length > 0 ? normalized : undefined;\n}\n\nfunction normalizeStringArray(value: unknown): string[] | undefined {\n\tif (!Array.isArray(value)) return undefined;\n\tconst normalized = value\n\t\t.filter((item): item is string => typeof item === \"string\")\n\t\t.map((item) => item.trim())\n\t\t.filter((item) => item.length > 0);\n\treturn normalized.length > 0 ? normalized : undefined;\n}\n\nfunction cloneContract(contract: EngineeringContract): EngineeringContract {\n\treturn {\n\t\t...(contract.goal ? { goal: contract.goal } : {}),\n\t\t...(contract.scope_include ? { scope_include: [...contract.scope_include] } : {}),\n\t\t...(contract.scope_exclude ? { scope_exclude: [...contract.scope_exclude] } : {}),\n\t\t...(contract.constraints ? { constraints: [...contract.constraints] } : {}),\n\t\t...(contract.quality_gates ? { quality_gates: [...contract.quality_gates] } : {}),\n\t\t...(contract.definition_of_done ? { definition_of_done: [...contract.definition_of_done] } : {}),\n\t\t...(contract.assumptions ? { assumptions: [...contract.assumptions] } : {}),\n\t\t...(contract.non_goals ? { non_goals: [...contract.non_goals] } : {}),\n\t\t...(contract.risks ? { risks: [...contract.risks] } : {}),\n\t\t...(contract.deliverables ? { deliverables: [...contract.deliverables] } : {}),\n\t\t...(contract.success_metrics ? { success_metrics: [...contract.success_metrics] } : {}),\n\t\t...(contract.stakeholders ? { stakeholders: [...contract.stakeholders] } : {}),\n\t\t...(contract.owner ? { owner: contract.owner } : {}),\n\t\t...(contract.timebox ? { timebox: contract.timebox } : {}),\n\t\t...(contract.notes ? { notes: contract.notes } : {}),\n\t};\n}\n\nfunction formatValidationError(payload: unknown): string {\n\tconst errors = validateContract.errors ?? [];\n\tif (errors.length === 0) {\n\t\treturn `Invalid contract payload: ${JSON.stringify(payload)}`;\n\t}\n\tconst details = errors\n\t\t.map((error: { instancePath?: string; message?: string }) => {\n\t\t\tconst path = error.instancePath || \"/\";\n\t\t\treturn `${path} ${error.message ?? \"is invalid\"}`;\n\t\t})\n\t\t.join(\"; \");\n\treturn `Invalid contract payload: ${details}`;\n}\n\nexport function normalizeEngineeringContract(payload: unknown): EngineeringContract {\n\tif (!isRecord(payload)) {\n\t\tthrow new ContractValidationError(\"Contract payload must be a JSON object.\");\n\t}\n\tif (!validateContract(payload)) {\n\t\tthrow new ContractValidationError(formatValidationError(payload));\n\t}\n\n\tconst goal = normalizeString(payload.goal);\n\tconst scopeInclude = normalizeStringArray(payload.scope_include);\n\tconst scopeExclude = normalizeStringArray(payload.scope_exclude);\n\tconst constraints = normalizeStringArray(payload.constraints);\n\tconst qualityGates = normalizeStringArray(payload.quality_gates);\n\tconst definitionOfDone = normalizeStringArray(payload.definition_of_done);\n\tconst assumptions = normalizeStringArray(payload.assumptions);\n\tconst nonGoals = normalizeStringArray(payload.non_goals);\n\tconst risks = normalizeStringArray(payload.risks);\n\tconst deliverables = normalizeStringArray(payload.deliverables);\n\tconst successMetrics = normalizeStringArray(payload.success_metrics);\n\tconst stakeholders = normalizeStringArray(payload.stakeholders);\n\tconst owner = normalizeString(payload.owner);\n\tconst timebox = normalizeString(payload.timebox);\n\tconst notes = normalizeString(payload.notes);\n\n\treturn {\n\t\t...(goal ? { goal } : {}),\n\t\t...(scopeInclude ? { scope_include: scopeInclude } : {}),\n\t\t...(scopeExclude ? { scope_exclude: scopeExclude } : {}),\n\t\t...(constraints ? { constraints } : {}),\n\t\t...(qualityGates ? { quality_gates: qualityGates } : {}),\n\t\t...(definitionOfDone ? { definition_of_done: definitionOfDone } : {}),\n\t\t...(assumptions ? { assumptions } : {}),\n\t\t...(nonGoals ? { non_goals: nonGoals } : {}),\n\t\t...(risks ? { risks } : {}),\n\t\t...(deliverables ? { deliverables } : {}),\n\t\t...(successMetrics ? { success_metrics: successMetrics } : {}),\n\t\t...(stakeholders ? { stakeholders } : {}),\n\t\t...(owner ? { owner } : {}),\n\t\t...(timebox ? { timebox } : {}),\n\t\t...(notes ? { notes } : {}),\n\t};\n}\n\nexport function deepMergeContracts(base: EngineeringContract, override: EngineeringContract): EngineeringContract {\n\tconst merged: EngineeringContract = cloneContract(base);\n\tfor (const [key, value] of Object.entries(override) as Array<[keyof EngineeringContract, unknown]>) {\n\t\tif (value === undefined) continue;\n\t\tif (Array.isArray(value)) {\n\t\t\t(merged as Record<string, unknown>)[key] = [...value];\n\t\t\tcontinue;\n\t\t}\n\t\t(merged as Record<string, unknown>)[key] = value;\n\t}\n\treturn normalizeEngineeringContract(merged);\n}\n\nfunction readContractFile(filePath: string): EngineeringContract {\n\tif (!existsSync(filePath)) {\n\t\treturn {};\n\t}\n\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(readFileSync(filePath, \"utf8\"));\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new ContractParseError(filePath, `Failed to parse contract JSON: ${message}`);\n\t}\n\n\ttry {\n\t\treturn normalizeEngineeringContract(parsed);\n\t} catch (error) {\n\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\tthrow new ContractParseError(filePath, message);\n\t}\n}\n\nfunction writeContractFile(filePath: string, contract: EngineeringContract): void {\n\tmkdirSync(dirname(filePath), { recursive: true });\n\twriteFileSync(filePath, `${JSON.stringify(contract, null, 2)}\\n`, \"utf8\");\n}\n\nexport interface ContractServiceOptions {\n\tcwd: string;\n}\n\nexport class ContractService {\n\tprivate readonly cwd: string;\n\tprivate sessionOverlay: EngineeringContract = {};\n\n\tconstructor(options: ContractServiceOptions) {\n\t\tthis.cwd = options.cwd;\n\t}\n\n\tgetProjectPath(): string {\n\t\treturn join(this.cwd, \".iosm\", \"contract.json\");\n\t}\n\n\tgetSessionOverlay(): EngineeringContract {\n\t\treturn cloneContract(this.sessionOverlay);\n\t}\n\n\tsetSessionOverlay(payload: unknown): EngineeringContract {\n\t\tconst normalized = normalizeEngineeringContract(payload);\n\t\tthis.sessionOverlay = normalized;\n\t\treturn cloneContract(normalized);\n\t}\n\n\tclearSessionOverlay(): void {\n\t\tthis.sessionOverlay = {};\n\t}\n\n\tloadProjectContract(): EngineeringContract {\n\t\treturn readContractFile(this.getProjectPath());\n\t}\n\n\tsaveProjectContract(payload: unknown): EngineeringContract {\n\t\tconst normalized = normalizeEngineeringContract(payload);\n\t\twriteContractFile(this.getProjectPath(), normalized);\n\t\treturn cloneContract(normalized);\n\t}\n\n\tclearProjectContract(): boolean {\n\t\tconst projectPath = this.getProjectPath();\n\t\tif (!existsSync(projectPath)) return false;\n\t\trmSync(projectPath, { force: true });\n\t\treturn true;\n\t}\n\n\tsave(scope: ContractScope, payload: unknown): EngineeringContract {\n\t\tif (scope === \"project\") {\n\t\t\treturn this.saveProjectContract(payload);\n\t\t}\n\t\treturn this.setSessionOverlay(payload);\n\t}\n\n\tclear(scope: ContractScope): boolean {\n\t\tif (scope === \"project\") {\n\t\t\treturn this.clearProjectContract();\n\t\t}\n\t\tthis.clearSessionOverlay();\n\t\treturn true;\n\t}\n\n\tgetState(): ContractState {\n\t\tconst projectPath = this.getProjectPath();\n\t\tconst hasProjectFile = existsSync(projectPath);\n\t\tconst project = this.loadProjectContract();\n\t\tconst sessionOverlay = this.getSessionOverlay();\n\t\tconst effective = deepMergeContracts(project, sessionOverlay);\n\t\treturn {\n\t\t\tprojectPath,\n\t\t\thasProjectFile,\n\t\t\tproject,\n\t\t\tsessionOverlay,\n\t\t\teffective,\n\t\t};\n\t}\n\n\tbuildPromptContext(maxItemsPerList = 4): string | undefined {\n\t\tconst state = this.getState();\n\t\tconst contract = state.effective;\n\t\tif (Object.keys(contract).length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst lines: string[] = [\"Active engineering contract (effective):\"];\n\t\tif (contract.goal) lines.push(`- goal: ${contract.goal}`);\n\n\t\tconst pushList = (label: string, values: string[] | undefined): void => {\n\t\t\tif (!values || values.length === 0) return;\n\t\t\tconst preview = values.slice(0, Math.max(1, maxItemsPerList));\n\t\t\tconst suffix = values.length > preview.length ? ` (+${values.length - preview.length} more)` : \"\";\n\t\t\tlines.push(`- ${label}: ${preview.join(\"; \")}${suffix}`);\n\t\t};\n\n\t\tpushList(\"scope_include\", contract.scope_include);\n\t\tpushList(\"scope_exclude\", contract.scope_exclude);\n\t\tpushList(\"constraints\", contract.constraints);\n\t\tpushList(\"quality_gates\", contract.quality_gates);\n\t\tpushList(\"definition_of_done\", contract.definition_of_done);\n\t\tpushList(\"assumptions\", contract.assumptions);\n\t\tpushList(\"non_goals\", contract.non_goals);\n\t\tpushList(\"risks\", contract.risks);\n\t\tpushList(\"deliverables\", contract.deliverables);\n\t\tpushList(\"success_metrics\", contract.success_metrics);\n\t\tpushList(\"stakeholders\", contract.stakeholders);\n\t\tif (contract.owner) lines.push(`- owner: ${contract.owner}`);\n\t\tif (contract.timebox) lines.push(`- timebox: ${contract.timebox}`);\n\t\tif (contract.notes) lines.push(`- notes: ${contract.notes}`);\n\t\tlines.push(\"Treat this contract as execution constraints unless user explicitly overrides it.\");\n\t\treturn lines.join(\"\\n\");\n\t}\n}\n"]}
@@ -0,0 +1,12 @@
1
+ export type FailureCause = "token_limit" | "logic_error" | "aborted" | "timeout" | "dependency_env" | "empty_output" | "unknown";
2
+ export declare function classifyFailureCause(errorMessage: string): FailureCause;
3
+ export declare function isRetrospectiveRetryable(cause: FailureCause): boolean;
4
+ export declare function buildRetrospectiveDirective(input: {
5
+ cause: FailureCause;
6
+ errorMessage: string;
7
+ attempt: number;
8
+ target: "root" | "delegate";
9
+ }): string;
10
+ export declare function formatFailureCauseCounts(counts: Partial<Record<FailureCause, number>>): string;
11
+ export declare function dominantFailureCause(counts: Partial<Record<FailureCause, number>>): FailureCause | undefined;
12
+ //# sourceMappingURL=failure-retrospective.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure-retrospective.d.ts","sourceRoot":"","sources":["../../src/core/failure-retrospective.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GACrB,aAAa,GACb,aAAa,GACb,SAAS,GACT,SAAS,GACT,gBAAgB,GAChB,cAAc,GACd,SAAS,CAAC;AAYb,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,YAAY,CAUvE;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,YAAY,GAAG,OAAO,CAErE;AAgDD,wBAAgB,2BAA2B,CAAC,KAAK,EAAE;IAClD,KAAK,EAAE,YAAY,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC;CAC5B,GAAG,MAAM,CAYT;AAED,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,GAAG,MAAM,CAe9F;AAED,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC,GAC3C,YAAY,GAAG,SAAS,CAY1B"}
@@ -0,0 +1,115 @@
1
+ const tokenLimitPattern = /(token limit|max(?:imum)? tokens?|too many tokens?|context length|context window|prompt is too long|input too long|length exceeded)/i;
2
+ const logicPattern = /(logic|invariant|assert(?:ion)?|expect\(|failed assumption|incorrect result|wrong output|invalid state|regression|failed dependency)/i;
3
+ const abortPattern = /(operation aborted|aborted|signal aborted)/i;
4
+ const timeoutPattern = /(timeout|timed out|deadline exceeded|took too long|hang(?:ing)?)/i;
5
+ const dependencyPattern = /(module not found|cannot find module|dependency|package|importerror|missing dependency|command not found|enoent|env(?:ironment)?)/i;
6
+ const emptyOutputPattern = /(empty output|no output|returned empty)/i;
7
+ export function classifyFailureCause(errorMessage) {
8
+ const message = errorMessage.trim();
9
+ if (!message)
10
+ return "unknown";
11
+ if (emptyOutputPattern.test(message))
12
+ return "empty_output";
13
+ if (tokenLimitPattern.test(message))
14
+ return "token_limit";
15
+ if (abortPattern.test(message))
16
+ return "aborted";
17
+ if (timeoutPattern.test(message))
18
+ return "timeout";
19
+ if (dependencyPattern.test(message))
20
+ return "dependency_env";
21
+ if (logicPattern.test(message))
22
+ return "logic_error";
23
+ return "unknown";
24
+ }
25
+ export function isRetrospectiveRetryable(cause) {
26
+ return cause !== "empty_output" && cause !== "aborted";
27
+ }
28
+ function guidanceForCause(cause) {
29
+ switch (cause) {
30
+ case "token_limit":
31
+ return [
32
+ "- Narrow scope to only the minimum files/commands needed.",
33
+ "- Produce concise output (bullet points + critical diffs only).",
34
+ "- Avoid broad scans and repeated large reads.",
35
+ ];
36
+ case "logic_error":
37
+ return [
38
+ "- Diagnose why the prior approach failed before changing code.",
39
+ "- Use an alternative strategy, not a repeat of the same path.",
40
+ "- Prefer smallest verifiable step and validate assumptions explicitly.",
41
+ ];
42
+ case "aborted":
43
+ return [
44
+ "- Stop retries for this task execution; cancellation came from an external signal.",
45
+ "- Report cancellation context (where it happened and what was in progress).",
46
+ "- Resume only via an explicit new task/run request.",
47
+ ];
48
+ case "timeout":
49
+ return [
50
+ "- Split work into smaller bounded steps.",
51
+ "- Reduce expensive commands and long-running checks.",
52
+ "- Prioritize fast targeted verification first.",
53
+ ];
54
+ case "dependency_env":
55
+ return [
56
+ "- Verify environment/dependency preconditions first.",
57
+ "- Prefer deterministic remediation steps and minimal commands.",
58
+ "- If blocked by environment, report exact missing prerequisite.",
59
+ ];
60
+ case "empty_output":
61
+ return [
62
+ "- Ensure the response includes a concrete result summary.",
63
+ "- If still impossible, return a clear blocked reason.",
64
+ ];
65
+ default:
66
+ return [
67
+ "- Re-evaluate assumptions and reduce scope.",
68
+ "- Try a different implementation approach.",
69
+ "- Produce a concise, verifiable outcome.",
70
+ ];
71
+ }
72
+ }
73
+ export function buildRetrospectiveDirective(input) {
74
+ const guidance = guidanceForCause(input.cause).join("\n");
75
+ return [
76
+ "[RETROSPECTIVE_RETRY]",
77
+ `target: ${input.target}`,
78
+ `attempt: ${input.attempt}`,
79
+ `cause: ${input.cause}`,
80
+ `previous_error: ${input.errorMessage.replace(/\s+/g, " ").trim()}`,
81
+ "retry_policy:",
82
+ guidance,
83
+ "[/RETROSPECTIVE_RETRY]",
84
+ ].join("\n");
85
+ }
86
+ export function formatFailureCauseCounts(counts) {
87
+ const ordered = [
88
+ "token_limit",
89
+ "logic_error",
90
+ "aborted",
91
+ "timeout",
92
+ "dependency_env",
93
+ "empty_output",
94
+ "unknown",
95
+ ];
96
+ const parts = ordered
97
+ .map((cause) => ({ cause, count: counts[cause] ?? 0 }))
98
+ .filter((item) => item.count > 0)
99
+ .map((item) => `${item.cause}=${item.count}`);
100
+ return parts.join(", ");
101
+ }
102
+ export function dominantFailureCause(counts) {
103
+ const entries = Object.entries(counts);
104
+ let best;
105
+ let bestCount = 0;
106
+ for (const [cause, count] of entries) {
107
+ const normalized = count ?? 0;
108
+ if (normalized > bestCount) {
109
+ best = cause;
110
+ bestCount = normalized;
111
+ }
112
+ }
113
+ return best;
114
+ }
115
+ //# sourceMappingURL=failure-retrospective.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"failure-retrospective.js","sourceRoot":"","sources":["../../src/core/failure-retrospective.ts"],"names":[],"mappings":"AASA,MAAM,iBAAiB,GACtB,sIAAsI,CAAC;AACxI,MAAM,YAAY,GACjB,uIAAuI,CAAC;AACzI,MAAM,YAAY,GAAG,6CAA6C,CAAC;AACnE,MAAM,cAAc,GAAG,mEAAmE,CAAC;AAC3F,MAAM,iBAAiB,GACtB,oIAAoI,CAAC;AACtI,MAAM,kBAAkB,GAAG,0CAA0C,CAAC;AAEtE,MAAM,UAAU,oBAAoB,CAAC,YAAoB;IACxD,MAAM,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,CAAC;IACpC,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAC;IAC/B,IAAI,kBAAkB,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,cAAc,CAAC;IAC5D,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,aAAa,CAAC;IAC1D,IAAI,YAAY,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IACjD,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,SAAS,CAAC;IACnD,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,gBAAgB,CA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\"\n\t| \"timeout\"\n\t| \"dependency_env\"\n\t| \"empty_output\"\n\t| \"unknown\";\n\nconst tokenLimitPattern =\n\t/(token limit|max(?:imum)? tokens?|too many tokens?|context length|context window|prompt is too long|input too long|length exceeded)/i;\nconst logicPattern =\n\t/(logic|invariant|assert(?:ion)?|expect\\(|failed assumption|incorrect result|wrong output|invalid state|regression|failed dependency)/i;\nconst abortPattern = /(operation aborted|aborted|signal aborted)/i;\nconst timeoutPattern = /(timeout|timed out|deadline exceeded|took too long|hang(?:ing)?)/i;\nconst dependencyPattern =\n\t/(module not found|cannot find module|dependency|package|importerror|missing dependency|command not found|enoent|env(?:ironment)?)/i;\nconst emptyOutputPattern = /(empty output|no output|returned empty)/i;\n\nexport function classifyFailureCause(errorMessage: string): FailureCause {\n\tconst message = errorMessage.trim();\n\tif (!message) return \"unknown\";\n\tif (emptyOutputPattern.test(message)) return \"empty_output\";\n\tif (tokenLimitPattern.test(message)) return \"token_limit\";\n\tif (abortPattern.test(message)) return \"aborted\";\n\tif (timeoutPattern.test(message)) return \"timeout\";\n\tif (dependencyPattern.test(message)) return \"dependency_env\";\n\tif (logicPattern.test(message)) return \"logic_error\";\n\treturn \"unknown\";\n}\n\nexport function isRetrospectiveRetryable(cause: FailureCause): boolean {\n\treturn cause !== \"empty_output\" && cause !== \"aborted\";\n}\n\nfunction guidanceForCause(cause: FailureCause): string[] {\n\tswitch (cause) {\n\t\tcase \"token_limit\":\n\t\t\treturn [\n\t\t\t\t\"- Narrow scope to only the minimum files/commands needed.\",\n\t\t\t\t\"- Produce concise output (bullet points + critical diffs only).\",\n\t\t\t\t\"- Avoid broad scans and repeated large reads.\",\n\t\t\t];\n\t\tcase \"logic_error\":\n\t\t\treturn [\n\t\t\t\t\"- Diagnose why the prior approach failed before changing code.\",\n\t\t\t\t\"- Use an alternative strategy, not a repeat of the same path.\",\n\t\t\t\t\"- Prefer smallest verifiable step and validate assumptions explicitly.\",\n\t\t\t];\n\t\tcase \"aborted\":\n\t\t\treturn [\n\t\t\t\t\"- Stop retries for this task execution; cancellation came from an external signal.\",\n\t\t\t\t\"- Report cancellation context (where it happened and what was in progress).\",\n\t\t\t\t\"- Resume only via an explicit new task/run request.\",\n\t\t\t];\n\t\tcase \"timeout\":\n\t\t\treturn [\n\t\t\t\t\"- Split work into smaller bounded steps.\",\n\t\t\t\t\"- Reduce expensive commands and long-running checks.\",\n\t\t\t\t\"- Prioritize fast targeted verification first.\",\n\t\t\t];\n\t\tcase \"dependency_env\":\n\t\t\treturn [\n\t\t\t\t\"- Verify environment/dependency preconditions first.\",\n\t\t\t\t\"- Prefer deterministic remediation steps and minimal commands.\",\n\t\t\t\t\"- If blocked by environment, report exact missing prerequisite.\",\n\t\t\t];\n\t\tcase \"empty_output\":\n\t\t\treturn [\n\t\t\t\t\"- Ensure the response includes a concrete result summary.\",\n\t\t\t\t\"- If still impossible, return a clear blocked reason.\",\n\t\t\t];\n\t\tdefault:\n\t\t\treturn [\n\t\t\t\t\"- Re-evaluate assumptions and reduce scope.\",\n\t\t\t\t\"- Try a different implementation approach.\",\n\t\t\t\t\"- Produce a concise, verifiable outcome.\",\n\t\t\t];\n\t}\n}\n\nexport function buildRetrospectiveDirective(input: {\n\tcause: FailureCause;\n\terrorMessage: string;\n\tattempt: number;\n\ttarget: \"root\" | \"delegate\";\n}): string {\n\tconst guidance = guidanceForCause(input.cause).join(\"\\n\");\n\treturn [\n\t\t\"[RETROSPECTIVE_RETRY]\",\n\t\t`target: ${input.target}`,\n\t\t`attempt: ${input.attempt}`,\n\t\t`cause: ${input.cause}`,\n\t\t`previous_error: ${input.errorMessage.replace(/\\s+/g, \" \").trim()}`,\n\t\t\"retry_policy:\",\n\t\tguidance,\n\t\t\"[/RETROSPECTIVE_RETRY]\",\n\t].join(\"\\n\");\n}\n\nexport function formatFailureCauseCounts(counts: Partial<Record<FailureCause, number>>): string {\n\tconst ordered: FailureCause[] = [\n\t\t\"token_limit\",\n\t\t\"logic_error\",\n\t\t\"aborted\",\n\t\t\"timeout\",\n\t\t\"dependency_env\",\n\t\t\"empty_output\",\n\t\t\"unknown\",\n\t];\n\tconst parts = ordered\n\t\t.map((cause) => ({ cause, count: counts[cause] ?? 0 }))\n\t\t.filter((item) => item.count > 0)\n\t\t.map((item) => `${item.cause}=${item.count}`);\n\treturn parts.join(\", \");\n}\n\nexport function dominantFailureCause(\n\tcounts: Partial<Record<FailureCause, number>>,\n): FailureCause | undefined {\n\tconst entries = Object.entries(counts) as Array<[FailureCause, number | undefined]>;\n\tlet best: FailureCause | undefined;\n\tlet bestCount = 0;\n\tfor (const [cause, count] of entries) {\n\t\tconst normalized = count ?? 0;\n\t\tif (normalized > bestCount) {\n\t\t\tbest = cause;\n\t\t\tbestCount = normalized;\n\t\t}\n\t}\n\treturn best;\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import type { BuildProjectIndexOptions, ProjectIndex, ProjectIndexQueryResult, RepoScaleMode } from "./types.js";
2
+ export type { BuildProjectIndexOptions, ProjectIndex, ProjectIndexEntry, ProjectIndexMeta, ProjectIndexQueryResult, RepoScaleMode, } from "./types.js";
3
+ export declare function getProjectIndexPath(cwd: string): string;
4
+ export declare function loadProjectIndex(cwd: string): ProjectIndex | undefined;
5
+ export declare function saveProjectIndex(cwd: string, index: ProjectIndex): void;
6
+ export declare function buildProjectIndex(cwd: string, options?: BuildProjectIndexOptions): ProjectIndex;
7
+ export declare function ensureProjectIndex(cwd: string, modeHint?: RepoScaleMode): {
8
+ index: ProjectIndex;
9
+ rebuilt: boolean;
10
+ };
11
+ export declare function queryProjectIndex(index: ProjectIndex, queryText: string, limit?: number): ProjectIndexQueryResult;
12
+ export declare function inferRepoScaleMode(input: {
13
+ totalFiles: number;
14
+ sourceFiles: number;
15
+ }): RepoScaleMode;
16
+ export declare function collectChangedFilesSince(index: ProjectIndex, cwd: string): string[];
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/project-index/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACX,wBAAwB,EACxB,YAAY,EAGZ,uBAAuB,EACvB,aAAa,EACb,MAAM,YAAY,CAAC;AACpB,YAAY,EACX,wBAAwB,EACxB,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,aAAa,GACb,MAAM,YAAY,CAAC;AAwHpB,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAUtE;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,GAAG,IAAI,CAIvE;AA+ED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,YAAY,CA0C/F;AAED,wBAAgB,kBAAkB,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,aAAa,GAAG;IAAE,KAAK,EAAE,YAAY,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAkBnH;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,uBAAuB,CAW7G;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,GAAG,aAAa,CAEpG;AAED,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAqBnF"}