@aigile/engine 0.0.0-stage → 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 (118) hide show
  1. package/dist/agents/code-reviewer.d.ts +37 -0
  2. package/dist/agents/code-reviewer.d.ts.map +1 -0
  3. package/dist/agents/code-reviewer.js +192 -0
  4. package/dist/agents/code-reviewer.js.map +1 -0
  5. package/dist/agents/engineer.d.ts +118 -0
  6. package/dist/agents/engineer.d.ts.map +1 -0
  7. package/dist/agents/engineer.js +528 -0
  8. package/dist/agents/engineer.js.map +1 -0
  9. package/dist/agents/monitor.d.ts +66 -0
  10. package/dist/agents/monitor.d.ts.map +1 -0
  11. package/dist/agents/monitor.js +281 -0
  12. package/dist/agents/monitor.js.map +1 -0
  13. package/dist/agents/orchestrator.d.ts +49 -0
  14. package/dist/agents/orchestrator.d.ts.map +1 -0
  15. package/dist/agents/orchestrator.js +204 -0
  16. package/dist/agents/orchestrator.js.map +1 -0
  17. package/dist/agents/release-manager.d.ts +76 -0
  18. package/dist/agents/release-manager.d.ts.map +1 -0
  19. package/dist/agents/release-manager.js +312 -0
  20. package/dist/agents/release-manager.js.map +1 -0
  21. package/dist/agents/spec-analyst.d.ts +102 -0
  22. package/dist/agents/spec-analyst.d.ts.map +1 -0
  23. package/dist/agents/spec-analyst.js +406 -0
  24. package/dist/agents/spec-analyst.js.map +1 -0
  25. package/dist/agents/verifier.d.ts +41 -0
  26. package/dist/agents/verifier.d.ts.map +1 -0
  27. package/dist/agents/verifier.js +173 -0
  28. package/dist/agents/verifier.js.map +1 -0
  29. package/dist/ai-service.d.ts +52 -0
  30. package/dist/ai-service.d.ts.map +1 -0
  31. package/dist/ai-service.js +164 -0
  32. package/dist/ai-service.js.map +1 -0
  33. package/dist/build-service.d.ts +65 -0
  34. package/dist/build-service.d.ts.map +1 -0
  35. package/dist/build-service.js +140 -0
  36. package/dist/build-service.js.map +1 -0
  37. package/dist/checkout.d.ts +57 -0
  38. package/dist/checkout.d.ts.map +1 -0
  39. package/dist/checkout.js +187 -0
  40. package/dist/checkout.js.map +1 -0
  41. package/dist/command-runner.d.ts +67 -0
  42. package/dist/command-runner.d.ts.map +1 -0
  43. package/dist/command-runner.js +149 -0
  44. package/dist/command-runner.js.map +1 -0
  45. package/dist/conversations.d.ts +18 -0
  46. package/dist/conversations.d.ts.map +1 -0
  47. package/dist/conversations.js +34 -0
  48. package/dist/conversations.js.map +1 -0
  49. package/dist/data-access.d.ts +34 -0
  50. package/dist/data-access.d.ts.map +1 -0
  51. package/dist/data-access.js +85 -0
  52. package/dist/data-access.js.map +1 -0
  53. package/dist/git-host.d.ts +43 -0
  54. package/dist/git-host.d.ts.map +1 -0
  55. package/dist/git-host.js +83 -0
  56. package/dist/git-host.js.map +1 -0
  57. package/dist/in-memory-store.d.ts +25 -0
  58. package/dist/in-memory-store.d.ts.map +1 -0
  59. package/dist/in-memory-store.js +52 -0
  60. package/dist/in-memory-store.js.map +1 -0
  61. package/dist/index.d.ts +28 -0
  62. package/dist/index.d.ts.map +1 -0
  63. package/dist/index.js +28 -0
  64. package/dist/index.js.map +1 -0
  65. package/dist/milestones.d.ts +36 -0
  66. package/dist/milestones.d.ts.map +1 -0
  67. package/dist/milestones.js +50 -0
  68. package/dist/milestones.js.map +1 -0
  69. package/dist/pull-request-sync.d.ts +29 -0
  70. package/dist/pull-request-sync.d.ts.map +1 -0
  71. package/dist/pull-request-sync.js +79 -0
  72. package/dist/pull-request-sync.js.map +1 -0
  73. package/dist/questions.d.ts +37 -0
  74. package/dist/questions.d.ts.map +1 -0
  75. package/dist/questions.js +79 -0
  76. package/dist/questions.js.map +1 -0
  77. package/dist/queue.d.ts +51 -0
  78. package/dist/queue.d.ts.map +1 -0
  79. package/dist/queue.js +108 -0
  80. package/dist/queue.js.map +1 -0
  81. package/dist/reviews.d.ts +17 -0
  82. package/dist/reviews.d.ts.map +1 -0
  83. package/dist/reviews.js +42 -0
  84. package/dist/reviews.js.map +1 -0
  85. package/dist/router.d.ts +13 -0
  86. package/dist/router.d.ts.map +1 -0
  87. package/dist/router.js +22 -0
  88. package/dist/router.js.map +1 -0
  89. package/dist/scheduler.d.ts +57 -0
  90. package/dist/scheduler.d.ts.map +1 -0
  91. package/dist/scheduler.js +134 -0
  92. package/dist/scheduler.js.map +1 -0
  93. package/dist/services.d.ts +359 -0
  94. package/dist/services.d.ts.map +1 -0
  95. package/dist/services.js +674 -0
  96. package/dist/services.js.map +1 -0
  97. package/dist/spec-resolver.d.ts +69 -0
  98. package/dist/spec-resolver.d.ts.map +1 -0
  99. package/dist/spec-resolver.js +200 -0
  100. package/dist/spec-resolver.js.map +1 -0
  101. package/dist/text-diff.d.ts +16 -0
  102. package/dist/text-diff.d.ts.map +1 -0
  103. package/dist/text-diff.js +51 -0
  104. package/dist/text-diff.js.map +1 -0
  105. package/dist/tool-sandbox.d.ts +47 -0
  106. package/dist/tool-sandbox.d.ts.map +1 -0
  107. package/dist/tool-sandbox.js +245 -0
  108. package/dist/tool-sandbox.js.map +1 -0
  109. package/dist/tracks.d.ts +58 -0
  110. package/dist/tracks.d.ts.map +1 -0
  111. package/dist/tracks.js +149 -0
  112. package/dist/tracks.js.map +1 -0
  113. package/dist/verifier.d.ts +27 -0
  114. package/dist/verifier.d.ts.map +1 -0
  115. package/dist/verifier.js +99 -0
  116. package/dist/verifier.js.map +1 -0
  117. package/package.json +31 -4
  118. package/README.md +0 -3
@@ -0,0 +1,41 @@
1
+ import type { AppConfig, Build, DataStore, Role } from '@aigile/core';
2
+ import { type AiService } from '../ai-service.js';
3
+ import { type Actor } from '../services.js';
4
+ export declare const VERIFIER_KEY = "verifier";
5
+ export declare const VERIFIER_ROLE: {
6
+ name: string;
7
+ description: string;
8
+ appRole: "contributor";
9
+ kind: "agent";
10
+ agentKey: string;
11
+ };
12
+ export declare const VERIFIER_CONTRACT = "You are the Verifier of aigile, a system in which people write specs (statements of intent in Markdown) and agents turn them into work. The Engineer has made a change on a branch to satisfy the specs; the Code Reviewer will read it; a person will decide. Your job comes between: add the tests that prove the change does what the specs ask, in the repository's own test style and runner, then run the project's checks.\n\nYou are in a checkout of the branch. Your editor writes only under the project's test paths; everything else is read-only to you, on purpose: you never fix the code under test. A test that fails against the change is your finding, not something to work around: keep it, and say what it shows. Prefer one focused test per requirement over many; name what each proves. If the repository has no test runner you can use, say so and write nothing. Run the configured checks before you finish and report their result.\n\nWhen you are done, answer with your report and nothing else, in Markdown with exactly these headings:\n## Summary\nOne paragraph: what the specs ask and what you proved.\n## Tests\nA bullet per test file: the file, and what each test in it proves (and whether it passes).\n## Checks\nWhat you ran and the result.\n## Notes\nAnything the reviewer or the approver should know, or \"None\".";
13
+ export declare const VERIFIER_DEFAULT_BRIEF = "# Verifier brief\n\nHow the Verifier proves this installation's changes. Edit this spec to change its habits; add a spec mapped to the Verifier and to an organization or project for rules that apply only there (the test runner to use, fixtures, what is never tested).\n\n## What to prove\n\n- Each requirement the changed specs state, at the level the repository tests at (unit where the change is a unit; integration where it is a flow).\n- The edge the spec names, not every edge imaginable.\n\n## How\n\n- Match the repository's test style, layout and naming; reuse its helpers and fixtures.\n- Never weaken an existing test; never change the code under test.\n- A failing test against the change stays, with a note on what it shows.\n";
14
+ export interface WriteTestsResult {
15
+ build: Build;
16
+ status: 'added' | 'nothing' | 'skipped' | 'blocked';
17
+ detail: string;
18
+ }
19
+ /**
20
+ * The Verifier's agent half (documentation/agents.md §2.5): a detached
21
+ * worktree of the build's branch, a sandbox that writes only under the test
22
+ * paths, the specs and the change as the brief, the configured checks to run;
23
+ * whatever it wrote outside the test paths is reverted and named; its tests
24
+ * become a commit on the branch, which the Reviewer then reads and the checks
25
+ * then include.
26
+ */
27
+ export declare class VerifierAgent {
28
+ private readonly store;
29
+ private readonly ai;
30
+ private readonly config;
31
+ private readonly data;
32
+ private readonly builds;
33
+ private readonly projects;
34
+ private readonly resolver;
35
+ private readonly milestones;
36
+ constructor(store: DataStore, ai: AiService, config: AppConfig);
37
+ role(): Promise<Role | null>;
38
+ writeTests(buildId: string, installRoot: string, actor: Actor): Promise<WriteTestsResult>;
39
+ private prompt;
40
+ }
41
+ //# sourceMappingURL=verifier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifier.d.ts","sourceRoot":"","sources":["../../src/agents/verifier.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEtE,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAMlE,OAAO,EAAE,KAAK,KAAK,EAAkB,MAAM,gBAAgB,CAAC;AAK5D,eAAO,MAAM,YAAY,aAAa,CAAC;AAEvC,eAAO,MAAM,aAAa;;;;;;CAMzB,CAAC;AAEF,eAAO,MAAM,iBAAiB,gzCAYgC,CAAC;AAE/D,eAAO,MAAM,sBAAsB,uuBAclC,CAAC;AAKF,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC;IACpD,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;GAOG;AACH,qBAAa,aAAa;IAQtB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,EAAE;IACnB,OAAO,CAAC,QAAQ,CAAC,MAAM;IATzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAmB;gBAG3B,KAAK,EAAE,SAAS,EAChB,EAAE,EAAE,SAAS,EACb,MAAM,EAAE,SAAS;IAS9B,IAAI,IAAI,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;IAK5B,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,gBAAgB,CAAC;YAoEjF,MAAM;CAerB"}
@@ -0,0 +1,173 @@
1
+ import { join } from 'node:path';
2
+ import { COLLECTIONS, parseRole } from '@aigile/core';
3
+ import { AiBlockedError } from '../ai-service.js';
4
+ import { BuildService } from '../build-service.js';
5
+ import { Checkout } from '../checkout.js';
6
+ import { runnerFor } from '../command-runner.js';
7
+ import { DataAccess } from '../data-access.js';
8
+ import { MilestoneService } from '../milestones.js';
9
+ import { ProjectService } from '../services.js';
10
+ import { SpecResolver } from '../spec-resolver.js';
11
+ import { formatUnifiedDiff } from '../text-diff.js';
12
+ import { ToolSandbox } from '../tool-sandbox.js';
13
+ export const VERIFIER_KEY = 'verifier';
14
+ export const VERIFIER_ROLE = {
15
+ name: 'Verifier',
16
+ description: 'aigile’s proving agent: adds the tests that prove a build does what the specs ask, under the project’s test paths only, and runs the checks.',
17
+ appRole: 'contributor',
18
+ kind: 'agent',
19
+ agentKey: VERIFIER_KEY,
20
+ };
21
+ export const VERIFIER_CONTRACT = `You are the Verifier of aigile, a system in which people write specs (statements of intent in Markdown) and agents turn them into work. The Engineer has made a change on a branch to satisfy the specs; the Code Reviewer will read it; a person will decide. Your job comes between: add the tests that prove the change does what the specs ask, in the repository's own test style and runner, then run the project's checks.
22
+
23
+ You are in a checkout of the branch. Your editor writes only under the project's test paths; everything else is read-only to you, on purpose: you never fix the code under test. A test that fails against the change is your finding, not something to work around: keep it, and say what it shows. Prefer one focused test per requirement over many; name what each proves. If the repository has no test runner you can use, say so and write nothing. Run the configured checks before you finish and report their result.
24
+
25
+ When you are done, answer with your report and nothing else, in Markdown with exactly these headings:
26
+ ## Summary
27
+ One paragraph: what the specs ask and what you proved.
28
+ ## Tests
29
+ A bullet per test file: the file, and what each test in it proves (and whether it passes).
30
+ ## Checks
31
+ What you ran and the result.
32
+ ## Notes
33
+ Anything the reviewer or the approver should know, or "None".`;
34
+ export const VERIFIER_DEFAULT_BRIEF = `# Verifier brief
35
+
36
+ How the Verifier proves this installation's changes. Edit this spec to change its habits; add a spec mapped to the Verifier and to an organization or project for rules that apply only there (the test runner to use, fixtures, what is never tested).
37
+
38
+ ## What to prove
39
+
40
+ - Each requirement the changed specs state, at the level the repository tests at (unit where the change is a unit; integration where it is a flow).
41
+ - The edge the spec names, not every edge imaginable.
42
+
43
+ ## How
44
+
45
+ - Match the repository's test style, layout and naming; reuse its helpers and fixtures.
46
+ - Never weaken an existing test; never change the code under test.
47
+ - A failing test against the change stays, with a note on what it shows.
48
+ `;
49
+ const MAX_PATCH_CHARS = 150_000;
50
+ const MAX_SPECS_CHARS = 150_000;
51
+ /**
52
+ * The Verifier's agent half (documentation/agents.md §2.5): a detached
53
+ * worktree of the build's branch, a sandbox that writes only under the test
54
+ * paths, the specs and the change as the brief, the configured checks to run;
55
+ * whatever it wrote outside the test paths is reverted and named; its tests
56
+ * become a commit on the branch, which the Reviewer then reads and the checks
57
+ * then include.
58
+ */
59
+ export class VerifierAgent {
60
+ store;
61
+ ai;
62
+ config;
63
+ data;
64
+ builds;
65
+ projects;
66
+ resolver;
67
+ milestones;
68
+ constructor(store, ai, config) {
69
+ this.store = store;
70
+ this.ai = ai;
71
+ this.config = config;
72
+ this.data = new DataAccess(store);
73
+ this.builds = new BuildService(this.data, store);
74
+ this.projects = new ProjectService(store);
75
+ this.resolver = new SpecResolver(this.data);
76
+ this.milestones = new MilestoneService(store);
77
+ }
78
+ async role() {
79
+ const raw = await this.store.list(COLLECTIONS.roles);
80
+ return raw.map((r) => parseRole(r)).find((r) => r.agentKey === VERIFIER_KEY) ?? null;
81
+ }
82
+ async writeTests(buildId, installRoot, actor) {
83
+ let build = await this.builds.get(buildId);
84
+ const project = await this.projects.get(build.projectId);
85
+ const role = await this.role();
86
+ const agentActor = { userId: `agent:${VERIFIER_KEY}`, author: { name: role?.name ?? 'Verifier', email: `${VERIFIER_KEY}@aigile.local` } };
87
+ const post = (kind, summary, detail = '') => this.milestones.post({ kind, roleId: role?.id ?? null, agentKey: VERIFIER_KEY, about: { kind: 'build', id: buildId }, projectIds: [project.id], summary, detail }, agentActor);
88
+ const done = async (status, detail, report) => {
89
+ if (report !== undefined)
90
+ build = await this.builds.update(buildId, { testsReport: report }, `Build ${buildId.slice(0, 8)}: tests ${status}`);
91
+ if (status === 'blocked')
92
+ await post('blocked', `Could not add tests to build ${buildId.slice(0, 8)}`, detail);
93
+ else if (status === 'added')
94
+ await post('finished', `Added tests to build ${buildId.slice(0, 8)}`, detail);
95
+ return { build, status, detail };
96
+ };
97
+ if (!role)
98
+ return done('blocked', 'the Verifier role is not installed; run `aigile install`');
99
+ if ((build.status !== 'proposed' && build.status !== 'checking') || !build.branch || !build.commit || !project.gitUrl)
100
+ return done('skipped', `build ${buildId.slice(0, 8)} is ${build.status}; only a built branch gets tests`);
101
+ const checks = this.config.agents.verifier.checksByProject[project.id] ?? this.config.agents.verifier.checks;
102
+ if (checks.length === 0)
103
+ return done('skipped', 'no checks are configured, so no test could be run (agents.verifier.checks)');
104
+ const work = join(installRoot, '.aigile', 'work');
105
+ const checkout = new Checkout(join(work, project.id), project.gitUrl, project.gitBranch);
106
+ const dir = join(work, `${project.id}-tests-${build.id.slice(0, 8)}`);
107
+ try {
108
+ await checkout.addWorktree(build.branch, dir);
109
+ }
110
+ catch (err) {
111
+ return done('blocked', `could not check out ${build.branch}: ${err instanceof Error ? err.message : String(err)}`);
112
+ }
113
+ const testPaths = this.config.agents.verifier.testPaths;
114
+ let sandbox;
115
+ try {
116
+ sandbox = new ToolSandbox(dir, this.config.agents.engineer, false, runnerFor(this.config.agents.sandbox, [checkout.dir, dir], project.id), testPaths);
117
+ }
118
+ catch (err) {
119
+ await checkout.removeWorktree(dir);
120
+ return done('blocked', err instanceof Error ? err.message : String(err));
121
+ }
122
+ const tip = build.commit;
123
+ try {
124
+ const brief = await this.resolver.resolveRole(role.id, project.id);
125
+ const system = [VERIFIER_CONTRACT, ...brief.map((b) => `\n\n---\n\n${b.content}`)].join('');
126
+ const user = await this.prompt(build, project.name, checkout, checks, testPaths);
127
+ const engineer = this.config.agents.engineer;
128
+ const result = await this.ai.runTools({ system, messages: [{ role: 'user', content: user }], tools: sandbox.handlers(), budgetTokens: engineer.budgetTokens, deadline: Date.now() + engineer.buildTimeoutMs }, { roleId: role.id, agentKey: VERIFIER_KEY, purpose: `write tests for ${project.name}`, subject: null, briefRevisions: brief.map((b) => ({ specId: b.specId, revision: b.revision })) });
129
+ if (result.stopReason === 'refusal')
130
+ return done('blocked', `The model declined: ${result.refusal ?? ''}`);
131
+ let report = result.text.trim() || '(the Verifier gave no report)';
132
+ // The worktree must still sit on the Engineer's commit: a commit or a moved ref made in there is refused outright.
133
+ if ((await checkout.headOf(dir)) !== tip)
134
+ return done('blocked', 'the Verifier moved the branch or committed on its own; its work is not taken', report);
135
+ // Whatever it changed outside the test paths goes back; the report says so.
136
+ const changed = await checkout.changedIn(dir);
137
+ const outside = changed.filter((f) => !sandbox.mayWrite(f));
138
+ if (outside.length > 0) {
139
+ await checkout.revertIn(dir, outside);
140
+ report += `\n\n_Reverted by aigile, outside the test paths: ${outside.join(', ')}._`;
141
+ }
142
+ const sha = await checkout.commitIn(dir, `Tests by aigile's Verifier for build ${build.id.slice(0, 8)}\n\nApproved through aigile with the build.\n`, { name: role.name, email: `${VERIFIER_KEY}@aigile.local` });
143
+ if (!sha)
144
+ return done('nothing', 'the Verifier added no test', report);
145
+ await checkout.adoptCommit(build.branch, sha, tip);
146
+ build = await this.builds.update(buildId, { commit: sha, testsReport: report }, `Build ${buildId.slice(0, 8)}: tests added (${sha.slice(0, 8)})`);
147
+ const count = changed.filter((f) => sandbox.mayWrite(f)).length;
148
+ return done('added', `${count} test file(s) on ${build.branch}`, report);
149
+ }
150
+ catch (err) {
151
+ return done('blocked', err instanceof AiBlockedError ? `blocked: ${err.message}` : err instanceof Error ? err.message : String(err));
152
+ }
153
+ finally {
154
+ await checkout.removeWorktree(dir);
155
+ }
156
+ }
157
+ async prompt(build, projectName, checkout, checks, testPaths) {
158
+ const resolution = await this.resolver.resolveProject(build.projectId);
159
+ let budget = MAX_SPECS_CHARS;
160
+ const specs = resolution.resolved
161
+ .filter((r) => {
162
+ budget -= r.content.length;
163
+ return budget >= 0;
164
+ })
165
+ .map((r, i) => `### ${i + 1}. ${r.title}\n\n${r.content}`)
166
+ .join('\n\n');
167
+ const changes = (await this.builds.changesOf(build)).map((c) => `### Spec ${c.specId} (${c.kind})\n\`\`\`diff\n${formatUnifiedDiff(c.diff)}\n\`\`\``).join('\n\n');
168
+ const { stat, patch } = await checkout.diff(build.branch);
169
+ const shownPatch = patch.length > MAX_PATCH_CHARS ? `${patch.slice(0, MAX_PATCH_CHARS)}\n[patch truncated; read the files]` : patch;
170
+ return `## The project\n\n${projectName}; you are in a detached checkout of ${build.branch} at your working directory. You may write only under: ${testPaths.join(', ')}. The checks: ${checks.map((c) => `\`${c}\``).join(', ')}.\n\n## The specs that apply (${resolution.resolved.length})\n\n${specs}\n\n## The spec changes the build worked from\n\n${changes || '(first build: every spec is new)'}\n\n## The Engineer's report\n\n${build.report}\n\n## The change\n\n\`\`\`\n${stat.trim()}\n\`\`\`\n\n\`\`\`diff\n${shownPatch}\n\`\`\`\n\n## Your task\n\nAdd the tests that prove what the specs ask of this change, run the checks, and report as instructed.`;
171
+ }
172
+ }
173
+ //# sourceMappingURL=verifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifier.js","sourceRoot":"","sources":["../../src/agents/verifier.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,cAAc,EAAkB,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EA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,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,qCAAqC,CAAC,CAAC,CAAC,KAAK,CAAC;QACpI,OAAO,qBAAqB,WAAW,uCAAuC,KAAK,CAAC,MAAM,yDAAyD,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,iBAAiB,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,iCAAiC,UAAU,CAAC,QAAQ,CAAC,MAAM,QAAQ,KAAK,oDAAoD,OAAO,IAAI,kCAAkC,mCAAmC,KAAK,CAAC,MAAM,gCAAgC,IAAI,CAAC,IAAI,EAAE,2BAA2B,UAAU,mIAAmI,CAAC;IAC9oB,CAAC;CACF"}
@@ -0,0 +1,52 @@
1
+ import type { AiCompletionRequest, AiCompletionResult, AiProvider, AiToolRunRequest, AiToolRunResult, AppConfig, DataStore, SpecRevisionRef } from '@aigile/core';
2
+ /** What a call is for, recorded beside its cost. */
3
+ export interface AiCallContext {
4
+ /** The agent role making the call; its config entry (model, effort) applies. */
5
+ roleId: string | null;
6
+ /** The key of that agent in `ai.roles` ("spec-analyst"). */
7
+ agentKey: string | null;
8
+ purpose: string;
9
+ subject?: SpecRevisionRef | null;
10
+ briefRevisions?: SpecRevisionRef[];
11
+ }
12
+ /** A completion the gateway refused to make, with the reason the agent reports. */
13
+ export declare class AiBlockedError extends Error {
14
+ constructor(message: string);
15
+ }
16
+ /**
17
+ * The one way agents reach the provider: it applies the role's model and
18
+ * effort from config, refuses once the month's recorded cost reaches the cap
19
+ * or when the provider is unavailable, and records every call (and every
20
+ * refusal) in the `ai-calls` collection, so spend is visible from the first
21
+ * call. The datastore commits the record like any other write.
22
+ */
23
+ export declare class AiService {
24
+ private readonly provider;
25
+ private readonly store;
26
+ private readonly config;
27
+ private readonly data;
28
+ constructor(provider: AiProvider, store: DataStore, config: AppConfig['ai']);
29
+ /** Why no call can be made right now, or null. */
30
+ blocked(): Promise<string | null>;
31
+ /** The recorded cost of this calendar month's calls (UTC), known prices only. */
32
+ spentThisMonth(now?: Date): Promise<number>;
33
+ /** The model and effort for an agent: its own entry in `ai.roles`, else the defaults. */
34
+ settingsFor(agentKey: string | null): {
35
+ model: string;
36
+ effort: AppConfig['ai']['effort'];
37
+ };
38
+ /**
39
+ * Make a call, or throw AiBlockedError with the reason (recorded as a
40
+ * `blocked` call). A provider error is recorded and rethrown; a refusal is
41
+ * recorded and returned (stopReason `refusal`), so the agent decides.
42
+ */
43
+ complete(request: AiCompletionRequest, context: AiCallContext): Promise<AiCompletionResult>;
44
+ /**
45
+ * Run the model with tools (the Engineer's builds): the cap is checked
46
+ * once at the start, and one record covers the whole run with its totals,
47
+ * so a build is one line in the AI window.
48
+ */
49
+ runTools(request: AiToolRunRequest, context: AiCallContext): Promise<AiToolRunResult>;
50
+ private record;
51
+ }
52
+ //# sourceMappingURL=ai-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-service.d.ts","sourceRoot":"","sources":["../src/ai-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,mBAAmB,EAAE,kBAAkB,EAAE,UAAU,EAAE,gBAAgB,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAI1K,oDAAoD;AACpD,MAAM,WAAW,aAAa;IAC5B,gFAAgF;IAChF,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,eAAe,GAAG,IAAI,CAAC;IACjC,cAAc,CAAC,EAAE,eAAe,EAAE,CAAC;CACpC;AAED,mFAAmF;AACnF,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;;GAMG;AACH,qBAAa,SAAS;IAIlB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;gBAGf,QAAQ,EAAE,UAAU,EACpB,KAAK,EAAE,SAAS,EAChB,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC;IAK1C,kDAAkD;IAC5C,OAAO,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAUvC,iFAAiF;IAC3E,cAAc,CAAC,GAAG,OAAa,GAAG,OAAO,CAAC,MAAM,CAAC;IAKvD,yFAAyF;IACzF,WAAW,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,GAAG;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAA;KAAE;IAK1F;;;;OAIG;IACG,QAAQ,CAAC,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,kBAAkB,CAAC;IAiDjG;;;;OAIG;IACG,QAAQ,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC;YAoD7E,MAAM;CAGrB"}
@@ -0,0 +1,164 @@
1
+ import { COLLECTIONS, newId, nowIso } from '@aigile/core';
2
+ import { DataAccess } from './data-access.js';
3
+ /** A completion the gateway refused to make, with the reason the agent reports. */
4
+ export class AiBlockedError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = 'AiBlockedError';
8
+ }
9
+ }
10
+ /**
11
+ * The one way agents reach the provider: it applies the role's model and
12
+ * effort from config, refuses once the month's recorded cost reaches the cap
13
+ * or when the provider is unavailable, and records every call (and every
14
+ * refusal) in the `ai-calls` collection, so spend is visible from the first
15
+ * call. The datastore commits the record like any other write.
16
+ */
17
+ export class AiService {
18
+ provider;
19
+ store;
20
+ config;
21
+ data;
22
+ constructor(provider, store, config) {
23
+ this.provider = provider;
24
+ this.store = store;
25
+ this.config = config;
26
+ this.data = new DataAccess(store);
27
+ }
28
+ /** Why no call can be made right now, or null. */
29
+ async blocked() {
30
+ const unavailable = this.provider.unavailable();
31
+ if (unavailable)
32
+ return unavailable;
33
+ const spent = await this.spentThisMonth();
34
+ if (spent >= this.config.monthlyCostCapUsd) {
35
+ return `the monthly AI cost cap of $${this.config.monthlyCostCapUsd} is reached ($${spent.toFixed(2)} recorded this month); raise ai.monthlyCostCapUsd or wait for next month`;
36
+ }
37
+ return null;
38
+ }
39
+ /** The recorded cost of this calendar month's calls (UTC), known prices only. */
40
+ async spentThisMonth(now = new Date()) {
41
+ const month = now.toISOString().slice(0, 7);
42
+ return (await this.data.aiCalls()).filter((c) => c.createdAt.startsWith(month)).reduce((sum, c) => sum + (c.costUsd ?? 0), 0);
43
+ }
44
+ /** The model and effort for an agent: its own entry in `ai.roles`, else the defaults. */
45
+ settingsFor(agentKey) {
46
+ const own = agentKey ? this.config.roles[agentKey] : undefined;
47
+ return { model: own?.model ?? this.config.model, effort: own?.effort ?? this.config.effort };
48
+ }
49
+ /**
50
+ * Make a call, or throw AiBlockedError with the reason (recorded as a
51
+ * `blocked` call). A provider error is recorded and rethrown; a refusal is
52
+ * recorded and returned (stopReason `refusal`), so the agent decides.
53
+ */
54
+ async complete(request, context) {
55
+ const settings = this.settingsFor(context.agentKey);
56
+ const ts = nowIso();
57
+ const base = {
58
+ id: newId(),
59
+ createdAt: ts,
60
+ updatedAt: ts,
61
+ roleId: context.roleId,
62
+ purpose: context.purpose,
63
+ subject: context.subject ?? null,
64
+ briefRevisions: context.briefRevisions ?? [],
65
+ status: 'ok',
66
+ model: request.model ?? settings.model,
67
+ effort: request.effort ?? settings.effort,
68
+ inputTokens: 0,
69
+ outputTokens: 0,
70
+ cacheReadInputTokens: 0,
71
+ cacheCreationInputTokens: 0,
72
+ costUsd: null,
73
+ durationMs: 0,
74
+ detail: null,
75
+ };
76
+ const blocked = await this.blocked();
77
+ if (blocked) {
78
+ await this.record({ ...base, status: 'blocked', detail: blocked });
79
+ throw new AiBlockedError(blocked);
80
+ }
81
+ const started = Date.now();
82
+ try {
83
+ const result = await this.provider.complete({ ...request, model: base.model, effort: (base.effort ?? settings.effort) });
84
+ await this.record({
85
+ ...base,
86
+ status: result.stopReason === 'refusal' ? 'refused' : 'ok',
87
+ model: result.model,
88
+ inputTokens: result.usage.inputTokens,
89
+ outputTokens: result.usage.outputTokens,
90
+ cacheReadInputTokens: result.usage.cacheReadInputTokens,
91
+ cacheCreationInputTokens: result.usage.cacheCreationInputTokens,
92
+ costUsd: result.costUsd,
93
+ durationMs: Date.now() - started,
94
+ detail: result.stopReason === 'refusal' ? (result.refusal ?? 'the model declined') : result.stopReason === 'max_tokens' ? 'the answer hit max_tokens' : null,
95
+ });
96
+ return result;
97
+ }
98
+ catch (err) {
99
+ await this.record({ ...base, status: 'error', durationMs: Date.now() - started, detail: err instanceof Error ? err.message : String(err) });
100
+ throw err;
101
+ }
102
+ }
103
+ /**
104
+ * Run the model with tools (the Engineer's builds): the cap is checked
105
+ * once at the start, and one record covers the whole run with its totals,
106
+ * so a build is one line in the AI window.
107
+ */
108
+ async runTools(request, context) {
109
+ const settings = this.settingsFor(context.agentKey);
110
+ const ts = nowIso();
111
+ const base = {
112
+ id: newId(),
113
+ createdAt: ts,
114
+ updatedAt: ts,
115
+ roleId: context.roleId,
116
+ purpose: context.purpose,
117
+ subject: context.subject ?? null,
118
+ briefRevisions: context.briefRevisions ?? [],
119
+ status: 'ok',
120
+ model: request.model ?? settings.model,
121
+ effort: request.effort ?? settings.effort,
122
+ inputTokens: 0,
123
+ outputTokens: 0,
124
+ cacheReadInputTokens: 0,
125
+ cacheCreationInputTokens: 0,
126
+ costUsd: null,
127
+ durationMs: 0,
128
+ detail: null,
129
+ };
130
+ const blocked = await this.blocked();
131
+ if (blocked) {
132
+ await this.record({ ...base, status: 'blocked', detail: blocked });
133
+ throw new AiBlockedError(blocked);
134
+ }
135
+ const started = Date.now();
136
+ const withUsage = (r) => ({
137
+ model: r.model,
138
+ inputTokens: r.usage.inputTokens,
139
+ outputTokens: r.usage.outputTokens,
140
+ cacheReadInputTokens: r.usage.cacheReadInputTokens,
141
+ cacheCreationInputTokens: r.usage.cacheCreationInputTokens,
142
+ costUsd: r.costUsd,
143
+ durationMs: Date.now() - started,
144
+ });
145
+ try {
146
+ const result = await this.provider.runTools({ ...request, model: base.model, effort: (base.effort ?? settings.effort) });
147
+ await this.record({
148
+ ...base,
149
+ ...withUsage(result),
150
+ status: result.stopReason === 'refusal' ? 'refused' : 'ok',
151
+ detail: result.stopReason === 'refusal' ? (result.refusal ?? 'the model declined') : `${result.turns} turn(s), ${result.toolCalls} tool call(s), stopped: ${result.stopReason}`,
152
+ });
153
+ return result;
154
+ }
155
+ catch (err) {
156
+ await this.record({ ...base, status: 'error', durationMs: Date.now() - started, detail: err instanceof Error ? err.message : String(err) });
157
+ throw err;
158
+ }
159
+ }
160
+ async record(call) {
161
+ await this.store.put(COLLECTIONS.aiCalls, call.id, call, { message: `AI call: ${call.purpose} (${call.status})` });
162
+ }
163
+ }
164
+ //# sourceMappingURL=ai-service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-service.js","sourceRoot":"","sources":["../src/ai-service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAa9C,mFAAmF;AACnF,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,SAAS;IAID;IACA;IACA;IALF,IAAI,CAAa;IAElC,YACmB,Q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M,IAAI,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC5I,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;IAEO,KAAK,CAAC,MAAM,CAAC,IAAY;QAC/B,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,YAAY,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;IACrH,CAAC;CACF"}
@@ -0,0 +1,65 @@
1
+ import type { AiCompletionRequest, Build, DataStore } from '@aigile/core';
2
+ import type { DataAccess } from './data-access.js';
3
+ import { type DiffLine } from './text-diff.js';
4
+ export type SpecChangeKind = 'added' | 'removed' | 'changed';
5
+ /** One spec's change between the previous build and the new build. */
6
+ export interface SpecChange {
7
+ specId: string;
8
+ kind: SpecChangeKind;
9
+ fromRevision: string | null;
10
+ toRevision: string | null;
11
+ diff: DiffLine[];
12
+ }
13
+ /**
14
+ * The result of planning a build: the newly created Build, what changed versus the
15
+ * previous build, and the content diffs an agent would apply to the source repo.
16
+ */
17
+ export interface BuildPlan {
18
+ projectId: string;
19
+ build: Build;
20
+ previousBuildId: string | null;
21
+ changes: SpecChange[];
22
+ unchangedCount: number;
23
+ }
24
+ export interface PlanBuildOptions {
25
+ /** Persist the new Build to the datastore (default true). */
26
+ persist?: boolean;
27
+ /** Fields the planner sets on the new Build (who asked, what it retries). */
28
+ seed?: Partial<Pick<Build, 'requestedBy' | 'retryOf' | 'status'>>;
29
+ }
30
+ /**
31
+ * Creates Builds from the resolved spec set and diffs consecutive Builds.
32
+ *
33
+ * Flow (matching the product spec): load the most recent Build for the project,
34
+ * create a new Build from the currently-resolved spec revisions, diff the revision
35
+ * references to find changed specs, and diff their content. The resulting
36
+ * {@link BuildPlan} — content diffs + git ref — is what gets handed to the (still
37
+ * deferred) build/code-modification agent via {@link buildAgentMessages}.
38
+ */
39
+ export declare class BuildService {
40
+ private readonly data;
41
+ private readonly store;
42
+ private readonly resolver;
43
+ constructor(data: DataAccess, store: DataStore);
44
+ /** Most recent Build for a project (by timestamp), or null. */
45
+ latestBuild(projectId: string): Promise<Build | null>;
46
+ planBuild(projectId: string, gitRef: string, options?: PlanBuildOptions): Promise<BuildPlan>;
47
+ get(id: string): Promise<Build>;
48
+ /** Every build, newest first. */
49
+ forProjectAll(): Promise<Build[]>;
50
+ /** Every build of a project, newest first. */
51
+ forProject(projectId: string): Promise<Build[]>;
52
+ update(id: string, patch: Partial<Build>, message: string): Promise<Build>;
53
+ /** The spec changes a build was planned from (against the build before it). */
54
+ changesOf(build: Build): Promise<SpecChange[]>;
55
+ /** Compute per-spec changes between two builds' revision sets and content. */
56
+ private diffBuilds;
57
+ private contentAt;
58
+ }
59
+ /**
60
+ * Assemble the message payload for the build/code-modification agent from a plan
61
+ * plus caller-supplied application instructions. The AiProvider call itself is
62
+ * deferred (the default provider is a stub); this is the seam that feeds it.
63
+ */
64
+ export declare function buildAgentMessages(plan: BuildPlan, instructions: string): AiCompletionRequest;
65
+ //# sourceMappingURL=build-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-service.d.ts","sourceRoot":"","sources":["../src/build-service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,KAAK,EAAE,SAAS,EAAmB,MAAM,cAAc,CAAC;AAE3F,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,KAAK,QAAQ,EAAgC,MAAM,gBAAgB,CAAC;AAE7E,MAAM,MAAM,cA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