@aigile/engine 0.0.0-stage → 0.2.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 (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 @@
1
+ {"version":3,"file":"milestones.js","sourceRoot":"","sources":["../src/milestones.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAgB9C;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAGE;IAFZ,IAAI,CAAa;IACj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AAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAChO,IAAI,SAAS,CAAC,eAAe,EAAE,CAAC;YAC9B,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,SAAS,CAAC,eAAe,EAAE,KAAK,SAAS,CAAC,QAAQ,IAAI,UAAU,KAAK,SAAS,CAAC,IAAI,QAAQ,SAAS,CAAC,OAAO,OAAO,SAAS,CAAC,KAAK,EAAE,EAAE,KAAK,CAAC,CAAC;QAC/K,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,mDAAmD;IACnD,KAAK,CAAC,MAAM,CAAC,KAAK,GAAG,EAAE,EAAE,KAAoC;QAC3D,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACzC,OAAO,GAAG;aACP,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,KAAK,EAAE,IAAI,KAAK,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,CAAC,EAAE,CAAC,CAAC;aAClF,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;aACtD,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ import type { DataStore } from '@aigile/core';
2
+ import { type PullRequestState } from './git-host.js';
3
+ type StateLookup = (remoteUrl: string, number: number, token: string) => Promise<PullRequestState>;
4
+ /**
5
+ * What the host knows and aigile does not: whether a pushed build's pull
6
+ * request was merged or declined. Checked on reads (at most once per
7
+ * `minIntervalMs` per process), never written to the host. Merged moves the
8
+ * Build to merged and the review ledger to merged; declined withdraws.
9
+ */
10
+ export declare class PullRequestSync {
11
+ private readonly env;
12
+ private readonly minIntervalMs;
13
+ private readonly lookup;
14
+ private readonly builds;
15
+ private readonly projects;
16
+ private readonly reviews;
17
+ private lastRun;
18
+ private running;
19
+ /** The builds the last run saw merged, for the clock to schedule audits. */
20
+ lastMerged: string[];
21
+ constructor(store: DataStore, env?: Record<string, string | undefined>, minIntervalMs?: number, lookup?: StateLookup);
22
+ /** Sync if the interval has passed; returns how many builds changed (0 when skipped). */
23
+ maybe(): Promise<number>;
24
+ now(): Promise<number>;
25
+ private sync;
26
+ private pushed;
27
+ }
28
+ export {};
29
+ //# sourceMappingURL=pull-request-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pull-request-sync.d.ts","sourceRoot":"","sources":["../src/pull-request-sync.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAS,SAAS,EAAE,MAAM,cAAc,CAAC;AAGrD,OAAO,EAA4C,KAAK,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAIhG,KAAK,WAAW,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAEnG;;;;;GAKG;AACH,qBAAa,eAAe;IAWxB,OAAO,CAAC,QAAQ,CAAC,GAAG;IACpB,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAZzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAe;IACtC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAgB;IACxC,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,OAAO,CAAgC;IAC/C,4EAA4E;IAC5E,UAAU,EAAE,MAAM,EAAE,CAAM;gBAGxB,KAAK,EAAE,SAAS,EACC,GAAG,GAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAe,EACrD,aAAa,SAAS,EACtB,MAAM,GAAE,WAAwF;IAOnH,yFAAyF;IACnF,KAAK,IAAI,OAAO,CAAC,MAAM,CAAC;IAKxB,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;YASd,IAAI;YAyBJ,MAAM;CAIrB"}
@@ -0,0 +1,79 @@
1
+ import { BuildService } from './build-service.js';
2
+ import { DataAccess } from './data-access.js';
3
+ import { parseRemote, pullRequestState, TOKEN_ENV } from './git-host.js';
4
+ import { ReviewService } from './reviews.js';
5
+ import { ProjectService } from './services.js';
6
+ /**
7
+ * What the host knows and aigile does not: whether a pushed build's pull
8
+ * request was merged or declined. Checked on reads (at most once per
9
+ * `minIntervalMs` per process), never written to the host. Merged moves the
10
+ * Build to merged and the review ledger to merged; declined withdraws.
11
+ */
12
+ export class PullRequestSync {
13
+ env;
14
+ minIntervalMs;
15
+ lookup;
16
+ builds;
17
+ projects;
18
+ reviews;
19
+ lastRun = 0;
20
+ running = null;
21
+ /** The builds the last run saw merged, for the clock to schedule audits. */
22
+ lastMerged = [];
23
+ constructor(store, env = process.env, minIntervalMs = 60_000, lookup = (url, number, token) => pullRequestState(parseRemote(url), number, token)) {
24
+ this.env = env;
25
+ this.minIntervalMs = minIntervalMs;
26
+ this.lookup = lookup;
27
+ this.builds = new BuildService(new DataAccess(store), store);
28
+ this.projects = new ProjectService(store);
29
+ this.reviews = new ReviewService(store);
30
+ }
31
+ /** Sync if the interval has passed; returns how many builds changed (0 when skipped). */
32
+ async maybe() {
33
+ if (Date.now() - this.lastRun < this.minIntervalMs)
34
+ return 0;
35
+ return this.now();
36
+ }
37
+ async now() {
38
+ if (this.running)
39
+ return this.running;
40
+ this.running = this.sync().finally(() => {
41
+ this.lastRun = Date.now();
42
+ this.running = null;
43
+ });
44
+ return this.running;
45
+ }
46
+ async sync() {
47
+ const actor = { userId: 'aigile' };
48
+ let changed = 0;
49
+ this.lastMerged = [];
50
+ for (const build of await this.pushed()) {
51
+ const project = await this.projects.get(build.projectId).catch(() => null);
52
+ const remote = project?.gitUrl ? parseRemote(project.gitUrl) : null;
53
+ const token = remote ? this.env[TOKEN_ENV[remote.host]] : undefined;
54
+ if (!project?.gitUrl || !remote || !token || !build.pullRequest || build.pullRequest.number === null)
55
+ continue;
56
+ let state;
57
+ try {
58
+ state = await this.lookup(project.gitUrl, build.pullRequest.number, token);
59
+ }
60
+ catch (err) {
61
+ console.warn(`[aigile] pull request sync: ${err instanceof Error ? err.message : String(err)}`);
62
+ continue;
63
+ }
64
+ if (state === 'open')
65
+ continue;
66
+ await this.builds.update(build.id, { status: state }, `Build ${build.id.slice(0, 8)} ${state} on the host`);
67
+ await this.reviews.settleForBuild(build.id, state === 'merged' ? 'merged' : 'withdrawn', actor);
68
+ if (state === 'merged')
69
+ this.lastMerged.push(build.id);
70
+ changed++;
71
+ }
72
+ return changed;
73
+ }
74
+ async pushed() {
75
+ const all = await this.builds.forProjectAll();
76
+ return all.filter((b) => b.status === 'pushed' && b.pullRequest !== null);
77
+ }
78
+ }
79
+ //# sourceMappingURL=pull-request-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pull-request-sync.js","sourceRoot":"","sources":["../src/pull-request-sync.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,SAAS,EAAyB,MAAM,eAAe,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAc,cAAc,EAAE,MAAM,eAAe,CAAC;AAI3D;;;;;GAKG;AACH,MAAM,OAAO,eAAe;IAWP;IACA;IACA;IAZF,MAAM,CAAe;IACrB,QAAQ,CAAiB;IACzB,OAAO,CAAgB;IAChC,OAAO,GAAG,CAAC,CAAC;IACZ,OAAO,GAA2B,IAAI,CAAC;IAC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AAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,SAAS,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC;YAC5G,MAAM,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,EAAE,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;YAChG,IAAI,KAAK,KAAK,QAAQ;gBAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACvD,OAAO,EAAE,CAAC;QACZ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IAEO,KAAK,CAAC,MAAM;QAClB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,aAAa,EAAE,CAAC;QAC9C,OAAO,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,QAAQ,IAAI,CAAC,CAAC,WAAW,KAAK,IAAI,CAAC,CAAC;IAC5E,CAAC;CACF"}
@@ -0,0 +1,37 @@
1
+ import type { Answer, DataStore, MessageAuthor, Question } from '@aigile/core';
2
+ import { z } from 'zod';
3
+ import { QueueService } from './queue.js';
4
+ import { type Actor } from './services.js';
5
+ export declare const questionInputSchema: z.ZodObject<{
6
+ body: z.ZodString;
7
+ projectId: z.ZodDefault<z.ZodNullable<z.ZodString>>;
8
+ area: z.ZodDefault<z.ZodString>;
9
+ }, "strip", z.ZodTypeAny, {
10
+ projectId: string | null;
11
+ body: string;
12
+ area: string;
13
+ }, {
14
+ body: string;
15
+ projectId?: string | null | undefined;
16
+ area?: string | undefined;
17
+ }>;
18
+ /**
19
+ * Questions about what the specs say: asked, answered by the Spec Analyst
20
+ * with a grade and citations (see SpecAnalyst.answer), and, when no spec
21
+ * decides, waiting for a person in the Questions queue until they decide.
22
+ */
23
+ export declare class QuestionService {
24
+ private readonly store;
25
+ private readonly queue;
26
+ private readonly data;
27
+ private readonly conversations;
28
+ constructor(store: DataStore, queue?: QueueService);
29
+ list(): Promise<Question[]>;
30
+ get(id: string): Promise<Question>;
31
+ ask(input: unknown, askedBy: MessageAuthor, actor: Actor): Promise<Question>;
32
+ /** The Analyst's answer: final when documented or inferred; undecided goes to a person. */
33
+ recordAnswer(id: string, answer: Answer, assigneeUserId: string | null, actor: Actor): Promise<Question>;
34
+ /** A person decides an undecided question; the asker hears, and the item closes. */
35
+ decide(id: string, body: unknown, actor: Actor): Promise<Question>;
36
+ }
37
+ //# sourceMappingURL=questions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questions.d.ts","sourceRoot":"","sources":["../src/questions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE/E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,KAAK,KAAK,EAAgB,MAAM,eAAe,CAAC;AAEzD,eAAO,MAAM,mBAAmB;;;;;;;;;;;;EAI9B,CAAC;AAEH;;;;GAIG;AACH,qBAAa,eAAe;IAIxB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,KAAK;IAJxB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;gBAEjC,KAAK,EAAE,SAAS,EAChB,KAAK,GAAE,YAAsC;IAMhE,IAAI,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;IAIrB,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC;IAMlC,GAAG,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC;IAUlF,2FAA2F;IACrF,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC;IAiB9G,oFAAoF;IAC9E,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC;CAazE"}
@@ -0,0 +1,79 @@
1
+ import { COLLECTIONS, newId, nowIso, questionSchema } from '@aigile/core';
2
+ import { z } from 'zod';
3
+ import { ConversationService } from './conversations.js';
4
+ import { DataAccess } from './data-access.js';
5
+ import { QueueService } from './queue.js';
6
+ import { ServiceError } from './services.js';
7
+ export const questionInputSchema = z.object({
8
+ body: z.string().trim().min(1),
9
+ projectId: z.string().min(1).nullable().default(null),
10
+ area: z.string().default(''),
11
+ });
12
+ /**
13
+ * Questions about what the specs say: asked, answered by the Spec Analyst
14
+ * with a grade and citations (see SpecAnalyst.answer), and, when no spec
15
+ * decides, waiting for a person in the Questions queue until they decide.
16
+ */
17
+ export class QuestionService {
18
+ store;
19
+ queue;
20
+ data;
21
+ conversations;
22
+ constructor(store, queue = new QueueService(store)) {
23
+ this.store = store;
24
+ this.queue = queue;
25
+ this.data = new DataAccess(store);
26
+ this.conversations = new ConversationService(store);
27
+ }
28
+ list() {
29
+ return this.data.questions().then((q) => q.sort((a, b) => b.createdAt.localeCompare(a.createdAt)));
30
+ }
31
+ async get(id) {
32
+ const raw = await this.store.get(COLLECTIONS.questions, id);
33
+ if (raw === null)
34
+ throw new ServiceError(404, `question ${id} not found`);
35
+ return questionSchema.parse(raw);
36
+ }
37
+ async ask(input, askedBy, actor) {
38
+ const parsed = questionInputSchema.safeParse(input);
39
+ if (!parsed.success)
40
+ throw new ServiceError(400, parsed.error.issues[0]?.message ?? 'invalid question');
41
+ if (parsed.data.projectId && (await this.store.get(COLLECTIONS.projects, parsed.data.projectId)) === null)
42
+ throw new ServiceError(404, `project ${parsed.data.projectId} not found`);
43
+ const ts = nowIso();
44
+ const question = { id: newId(), ...parsed.data, askedBy, status: 'open', answer: null, assigneeUserId: null, createdAt: ts, updatedAt: ts };
45
+ await this.store.put(COLLECTIONS.questions, question.id, question, { message: `Ask: ${question.body.slice(0, 60)}`, ...(actor.author ? { author: actor.author } : {}) });
46
+ return question;
47
+ }
48
+ /** The Analyst's answer: final when documented or inferred; undecided goes to a person. */
49
+ async recordAnswer(id, answer, assigneeUserId, actor) {
50
+ const current = await this.get(id);
51
+ const undecided = answer.grade === 'undecided';
52
+ const next = { ...current, answer, status: undecided ? 'open' : 'answered', assigneeUserId: undecided ? assigneeUserId : null, updatedAt: nowIso() };
53
+ await this.store.put(COLLECTIONS.questions, id, next, { message: `Answer (${answer.grade}): ${current.body.slice(0, 50)}`, ...(actor.author ? { author: actor.author } : {}) });
54
+ if (undecided && assigneeUserId) {
55
+ await this.queue.open({ kind: 'question', assigneeUserId, title: current.body.slice(0, 80), summary: 'No spec decides this; the Analyst needs your answer.', ref: { kind: 'question', id }, waitingOnRoleId: actor.userId.startsWith('agent:') ? null : null, projectIds: current.projectId ? [current.projectId] : [] }, actor);
56
+ }
57
+ else if (current.askedBy.kind === 'user' && current.askedBy.id) {
58
+ const head = undecided ? '**No spec decides your question, and nobody is ranked to answer it:**' : `**Your question was answered (${answer.grade}):**`;
59
+ await this.conversations.notify(current.askedBy.id, `${head} ${current.body.slice(0, 80)}\n\n${answer.body}`, actor);
60
+ }
61
+ return next;
62
+ }
63
+ /** A person decides an undecided question; the asker hears, and the item closes. */
64
+ async decide(id, body, actor) {
65
+ const current = await this.get(id);
66
+ const text = typeof body === 'string' ? body.trim() : '';
67
+ if (!text)
68
+ throw new ServiceError(400, 'an answer is required');
69
+ const answer = { grade: 'decided', body: text, citations: current.answer?.citations ?? [], by: { kind: 'user', id: actor.userId } };
70
+ const next = { ...current, answer, status: 'answered', assigneeUserId: null, updatedAt: nowIso() };
71
+ await this.store.put(COLLECTIONS.questions, id, next, { message: `Decided: ${current.body.slice(0, 50)}`, ...(actor.author ? { author: actor.author } : {}) });
72
+ await this.queue.closeAbout({ kind: 'question', id }, actor);
73
+ if (current.askedBy.kind === 'user' && current.askedBy.id && current.askedBy.id !== actor.userId) {
74
+ await this.conversations.notify(current.askedBy.id, `**Your question was decided by ${actor.author?.name ?? actor.userId}:** ${current.body.slice(0, 80)}\n\n${text}`, actor);
75
+ }
76
+ return next;
77
+ }
78
+ }
79
+ //# sourceMappingURL=questions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questions.js","sourceRoot":"","sources":["../src/questions.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAc,YAAY,EAAE,MAAM,eAAe,CAAC;AAEzD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAC9B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IACrD,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;CAC7B,CAAC,CAAC;AAEH;;;;GAIG;AACH,M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K,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC/J,MAAM,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,CAAC;QAC7D,IAAI,OAAO,CAAC,OAAO,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;YACjG,MAAM,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,EAAE,kCAAkC,KAAK,CAAC,MAAM,EAAE,IAAI,IAAI,KAAK,CAAC,MAAM,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,IAAI,EAAE,EAAE,KAAK,CAAC,CAAC;QAChL,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
@@ -0,0 +1,51 @@
1
+ import type { DataStore, QueueItem, QueueKind } from '@aigile/core';
2
+ import { type Actor } from './services.js';
3
+ export interface QueueItemInput {
4
+ kind: QueueKind;
5
+ assigneeUserId: string;
6
+ title: string;
7
+ summary?: string;
8
+ ref: {
9
+ kind: string;
10
+ id: string;
11
+ };
12
+ waitingOnRoleId?: string | null;
13
+ projectIds?: string[];
14
+ }
15
+ /**
16
+ * The queues: what waits for whom. Writes go to the datastore like everything
17
+ * else; reads go through the index, an in-memory view rebuilt from the
18
+ * datastore when it is stale (any write through this service marks it so;
19
+ * a process that only reads refreshes on a timer). SQLite can replace the
20
+ * rebuild if an installation outgrows it.
21
+ */
22
+ export declare class QueueService {
23
+ private readonly store;
24
+ private readonly maxAgeMs;
25
+ private readonly data;
26
+ private readonly conversations;
27
+ private readonly router;
28
+ private index;
29
+ private builtAt;
30
+ constructor(store: DataStore, maxAgeMs?: number);
31
+ /** Every item, open and done, from the index. */
32
+ all(): Promise<QueueItem[]>;
33
+ invalidate(): void;
34
+ /** A person's open items, newest first. */
35
+ openFor(userId: string): Promise<QueueItem[]>;
36
+ get(id: string): Promise<QueueItem>;
37
+ /**
38
+ * Open an item for the person the router picks (past reassignments first,
39
+ * the given assignee otherwise), unless they already have an open one about
40
+ * the same record; and tell them in their conversation, the one door.
41
+ */
42
+ open(input: QueueItemInput, actor: Actor): Promise<QueueItem>;
43
+ /** Hand an item to someone else, and remember it for the next one of its kind (documentation/agents.md §3.7). */
44
+ reassign(id: string, toUserId: string, actor: Actor): Promise<QueueItem>;
45
+ /** Mark every open item about a record done (the conflict was resolved, the question answered). */
46
+ closeAbout(ref: {
47
+ kind: string;
48
+ id: string;
49
+ }, actor: Actor): Promise<number>;
50
+ }
51
+ //# sourceMappingURL=queue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAgB,MAAM,cAAc,CAAC;AAKlF,OAAO,EAAE,KAAK,KAAK,EAAgB,MAAM,eAAe,CAAC;AAIzD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,cAAc,EAAE,MAAM,CAAC;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;CACvB;AAED;;;;;;GAMG;AACH,qBAAa,YAAY;IAQrB,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ;IAR3B,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;IAClC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAsB;IACpD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,KAAK,CAA4B;IACzC,OAAO,CAAC,OAAO,CAAK;gBAGD,KAAK,EAAE,SAAS,EAChB,QAAQ,SAAQ;IAOnC,iDAAiD;IAC3C,GAAG,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;IAQjC,UAAU,IAAI,IAAI;IAIlB,2CAA2C;IACrC,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IAI7C,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAMzC;;;;OAIG;IACG,IAAI,CAAC,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC;IAwBnE,iHAAiH;IAC3G,QAAQ,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,SAAS,CAAC;IAe9E,mGAAmG;IAC7F,UAAU,CAAC,GAAG,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAA;KAAE,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;CAQnF"}
package/dist/queue.js ADDED
@@ -0,0 +1,108 @@
1
+ import { COLLECTIONS, newId, nowIso, queueItemSchema } from '@aigile/core';
2
+ import { ConversationService } from './conversations.js';
3
+ import { DataAccess } from './data-access.js';
4
+ import { Router } from './router.js';
5
+ import { ServiceError } from './services.js';
6
+ const KIND_LABEL = { question: 'A question', conflict: 'A conflict', review: 'A review', approval: 'An approval', gate: 'A gate', incident: 'An incident' };
7
+ /**
8
+ * The queues: what waits for whom. Writes go to the datastore like everything
9
+ * else; reads go through the index, an in-memory view rebuilt from the
10
+ * datastore when it is stale (any write through this service marks it so;
11
+ * a process that only reads refreshes on a timer). SQLite can replace the
12
+ * rebuild if an installation outgrows it.
13
+ */
14
+ export class QueueService {
15
+ store;
16
+ maxAgeMs;
17
+ data;
18
+ conversations;
19
+ router;
20
+ index = null;
21
+ builtAt = 0;
22
+ constructor(store, maxAgeMs = 5_000) {
23
+ this.store = store;
24
+ this.maxAgeMs = maxAgeMs;
25
+ this.data = new DataAccess(store);
26
+ this.conversations = new ConversationService(store);
27
+ this.router = new Router(store);
28
+ }
29
+ /** Every item, open and done, from the index. */
30
+ async all() {
31
+ if (this.index === null || Date.now() - this.builtAt > this.maxAgeMs) {
32
+ this.index = await this.data.queueItems();
33
+ this.builtAt = Date.now();
34
+ }
35
+ return this.index;
36
+ }
37
+ invalidate() {
38
+ this.index = null;
39
+ }
40
+ /** A person's open items, newest first. */
41
+ async openFor(userId) {
42
+ return (await this.all()).filter((i) => i.assigneeUserId === userId && i.status === 'open').sort((a, b) => b.createdAt.localeCompare(a.createdAt));
43
+ }
44
+ async get(id) {
45
+ const raw = await this.store.get(COLLECTIONS.queueItems, id);
46
+ if (raw === null)
47
+ throw new ServiceError(404, `queue item ${id} not found`);
48
+ return queueItemSchema.parse(raw);
49
+ }
50
+ /**
51
+ * Open an item for the person the router picks (past reassignments first,
52
+ * the given assignee otherwise), unless they already have an open one about
53
+ * the same record; and tell them in their conversation, the one door.
54
+ */
55
+ async open(input, actor) {
56
+ const assignee = await this.router.assigneeFor(input.kind, input.projectIds ?? [], input.assigneeUserId);
57
+ const existing = (await this.all()).find((i) => i.status === 'open' && i.kind === input.kind && i.assigneeUserId === assignee && i.ref.kind === input.ref.kind && i.ref.id === input.ref.id);
58
+ if (existing)
59
+ return existing;
60
+ const ts = nowIso();
61
+ const item = {
62
+ id: newId(),
63
+ kind: input.kind,
64
+ status: 'open',
65
+ assigneeUserId: assignee,
66
+ title: input.title,
67
+ summary: input.summary ?? '',
68
+ ref: input.ref,
69
+ waitingOnRoleId: input.waitingOnRoleId ?? null,
70
+ projectIds: input.projectIds ?? [],
71
+ createdAt: ts,
72
+ updatedAt: ts,
73
+ };
74
+ await this.store.put(COLLECTIONS.queueItems, item.id, item, { message: `Queue ${item.kind}: ${item.title}`, ...(actor.author ? { author: actor.author } : {}) });
75
+ this.invalidate();
76
+ await this.conversations.notify(assignee, `**${KIND_LABEL[item.kind]} for you:** ${item.title}${item.summary ? ` — ${item.summary}` : ''}`, actor);
77
+ return item;
78
+ }
79
+ /** Hand an item to someone else, and remember it for the next one of its kind (documentation/agents.md §3.7). */
80
+ async reassign(id, toUserId, actor) {
81
+ const item = await this.get(id);
82
+ if (item.status !== 'open')
83
+ throw new ServiceError(409, 'only an open item can be reassigned');
84
+ if ((await this.store.get(COLLECTIONS.users, toUserId)) === null)
85
+ throw new ServiceError(404, `user ${toUserId} not found`);
86
+ if (toUserId === item.assigneeUserId)
87
+ return item;
88
+ const ts = nowIso();
89
+ const record = { id: newId(), queueItemId: id, kind: item.kind, projectIds: item.projectIds, fromUserId: item.assigneeUserId, toUserId, byUserId: actor.userId, createdAt: ts, updatedAt: ts };
90
+ await this.store.put(COLLECTIONS.reassignments, record.id, record, { message: `Reassign ${item.kind} to ${toUserId}`, ...(actor.author ? { author: actor.author } : {}) });
91
+ const next = { ...item, assigneeUserId: toUserId, updatedAt: ts };
92
+ await this.store.put(COLLECTIONS.queueItems, id, next, { message: `${item.kind} ${item.title} now with ${toUserId}`, ...(actor.author ? { author: actor.author } : {}) });
93
+ this.invalidate();
94
+ await this.conversations.notify(toUserId, `**${KIND_LABEL[item.kind]} for you** (from ${item.assigneeUserId}): ${item.title}${item.summary ? ` — ${item.summary}` : ''}`, actor);
95
+ return next;
96
+ }
97
+ /** Mark every open item about a record done (the conflict was resolved, the question answered). */
98
+ async closeAbout(ref, actor) {
99
+ const open = (await this.all()).filter((i) => i.status === 'open' && i.ref.kind === ref.kind && i.ref.id === ref.id);
100
+ for (const item of open) {
101
+ await this.store.put(COLLECTIONS.queueItems, item.id, { ...item, status: 'done', updatedAt: nowIso() }, { message: `Done ${item.kind}: ${item.title}`, ...(actor.author ? { author: actor.author } : {}) });
102
+ }
103
+ if (open.length > 0)
104
+ this.invalidate();
105
+ return open.length;
106
+ }
107
+ }
108
+ //# sourceMappingURL=queue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAc,YAAY,EAAE,MAAM,eAAe,CAAC;AAEzD,MAAM,UAAU,GAA8B,EAAE,QAAQ,EAAE,YAAY,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,aAAa,EAAE,CAAC;AAYvL;;;;;;GAMG;AACH,MAAM,OAAO,YAAY;IAQJ;IACA;IARF,IAAI,CAAa;IACjB,aAAa,CAAsB;IACnC,MAAM,CAAS;IACxB,KAAK,GAAuB,IAAI,CAAC;IACjC,OAAO,GAAG,CAAC,CAAC;IAEpB,YACmB,KAAgB,EAChB,WAAW,KAAK;QADhB,UAAK,GAAL,KAAK,CAAW;QAChB,aAAQ,GAAR,QAAQ,CAAQ;QAEjC,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;QAClC,IAAI,CAAC,aAAa,GAAG,IAAI,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACpD,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,CAA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AAI,GAAG,CAAC,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,CAAC,EAAE,CAAC,CAAC;QACrH,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE,CAAC;YACxB,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,QAAQ,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9M,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC;YAAE,IAAI,CAAC,UAAU,EAAE,CAAC;QACvC,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ import type { DataStore, Review, ReviewStatus } from '@aigile/core';
2
+ import { type Actor } from './services.js';
3
+ /** The review ledger: one Review per reading of a build; the person's decision moves its state. */
4
+ export declare class ReviewService {
5
+ private readonly store;
6
+ private readonly data;
7
+ constructor(store: DataStore);
8
+ get(id: string): Promise<Review>;
9
+ /** A build's reviews, newest first. */
10
+ forBuild(buildId: string): Promise<Review[]>;
11
+ create(input: Omit<Review, 'id' | 'createdAt' | 'updatedAt' | 'status' | 'decidedBy'>, actor: Actor): Promise<Review>;
12
+ /** What the person did with it. */
13
+ setStatus(id: string, status: ReviewStatus, actor: Actor): Promise<Review>;
14
+ /** Every reported review of a build moves on (the person decided the build). */
15
+ settleForBuild(buildId: string, status: ReviewStatus, actor: Actor): Promise<void>;
16
+ }
17
+ //# sourceMappingURL=reviews.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviews.d.ts","sourceRoot":"","sources":["../src/reviews.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAGpE,OAAO,EAAE,KAAK,KAAK,EAAgB,MAAM,eAAe,CAAC;AAEzD,mGAAmG;AACnG,qBAAa,aAAa;IAEZ,OAAO,CAAC,QAAQ,CAAC,KAAK;IADlC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;gBACL,KAAK,EAAE,SAAS;IAIvC,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAMtC,uCAAuC;IACjC,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAI5C,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,GAAG,WAAW,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAO3H,mCAAmC;IAC7B,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,MAAM,CAAC;IAOhF,gFAAgF;IAC1E,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;CAGzF"}
@@ -0,0 +1,42 @@
1
+ import { COLLECTIONS, newId, nowIso, reviewSchema } from '@aigile/core';
2
+ import { DataAccess } from './data-access.js';
3
+ import { ServiceError } from './services.js';
4
+ /** The review ledger: one Review per reading of a build; the person's decision moves its state. */
5
+ export class ReviewService {
6
+ store;
7
+ data;
8
+ constructor(store) {
9
+ this.store = store;
10
+ this.data = new DataAccess(store);
11
+ }
12
+ async get(id) {
13
+ const raw = await this.store.get(COLLECTIONS.reviews, id);
14
+ if (raw === null)
15
+ throw new ServiceError(404, `review ${id} not found`);
16
+ return reviewSchema.parse(raw);
17
+ }
18
+ /** A build's reviews, newest first. */
19
+ async forBuild(buildId) {
20
+ return (await this.data.reviews()).filter((r) => r.buildId === buildId).sort((a, b) => b.createdAt.localeCompare(a.createdAt));
21
+ }
22
+ async create(input, actor) {
23
+ const ts = nowIso();
24
+ const review = reviewSchema.parse({ ...input, id: newId(), status: 'reported', decidedBy: null, createdAt: ts, updatedAt: ts });
25
+ await this.store.put(COLLECTIONS.reviews, review.id, review, { message: `Review of build ${review.buildId.slice(0, 8)}: ${review.verdict}${review.worst !== 'none' ? ` (${review.worst})` : ''}`, ...(actor.author ? { author: actor.author } : {}) });
26
+ return review;
27
+ }
28
+ /** What the person did with it. */
29
+ async setStatus(id, status, actor) {
30
+ const current = await this.get(id);
31
+ const next = { ...current, status, decidedBy: actor.userId, updatedAt: nowIso() };
32
+ await this.store.put(COLLECTIONS.reviews, id, next, { message: `Review of build ${current.buildId.slice(0, 8)}: ${status}`, ...(actor.author ? { author: actor.author } : {}) });
33
+ return next;
34
+ }
35
+ /** Every reported review of a build moves on (the person decided the build). */
36
+ async settleForBuild(buildId, status, actor) {
37
+ for (const review of await this.forBuild(buildId))
38
+ if (review.status === 'reported')
39
+ await this.setStatus(review.id, status, actor);
40
+ }
41
+ }
42
+ //# sourceMappingURL=reviews.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reviews.js","sourceRoot":"","sources":["../src/reviews.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AACxE,OAAO,EAAE,UAAU,EAA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EAAE,KAAY;QACtE,KAAK,MAAM,MAAM,IAAI,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC;YAAE,IAAI,MAAM,CAAC,MAAM,KAAK,UAAU;gBAAE,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IACtI,CAAC;CACF"}
@@ -0,0 +1,13 @@
1
+ import type { DataStore, QueueKind } from '@aigile/core';
2
+ /**
3
+ * Whom an item goes to (documentation/agents.md §3.7): a past reassignment of
4
+ * the same kind for the same project wins, newest first; otherwise the
5
+ * caller's default (the highest-ranked author, the requester). People teach
6
+ * it by reassigning; nobody configures it.
7
+ */
8
+ export declare class Router {
9
+ private readonly data;
10
+ constructor(store: DataStore);
11
+ assigneeFor(kind: QueueKind, projectIds: string[], fallback: string): Promise<string>;
12
+ }
13
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzD;;;;;GAKG;AACH,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAa;gBACtB,KAAK,EAAE,SAAS;IAItB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;CAQ5F"}
package/dist/router.js ADDED
@@ -0,0 +1,22 @@
1
+ import { DataAccess } from './data-access.js';
2
+ /**
3
+ * Whom an item goes to (documentation/agents.md §3.7): a past reassignment of
4
+ * the same kind for the same project wins, newest first; otherwise the
5
+ * caller's default (the highest-ranked author, the requester). People teach
6
+ * it by reassigning; nobody configures it.
7
+ */
8
+ export class Router {
9
+ data;
10
+ constructor(store) {
11
+ this.data = new DataAccess(store);
12
+ }
13
+ async assigneeFor(kind, projectIds, fallback) {
14
+ const past = (await this.data.reassignments())
15
+ .filter((r) => r.kind === kind && (projectIds.length === 0 ? r.projectIds.length === 0 : r.projectIds.some((p) => projectIds.includes(p))))
16
+ .sort((a, b) => b.createdAt.localeCompare(a.createdAt));
17
+ // The most recent reassignment away from the default, for this kind and project, names the person to use instead.
18
+ const learned = past.find((r) => r.fromUserId === fallback);
19
+ return learned?.toUserId ?? fallback;
20
+ }
21
+ }
22
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,OAAO,MAAM;IACA,IAAI,CAAa;IAClC,YAAY,KAAgB;QAC1B,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,IAAe,EAAE,UAAoB,EAAE,QAAgB;QACvE,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;aAC3C,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aAC1I,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;QAC1D,kHAAkH;QAClH,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,QAAQ,CAAC,CAAC;QAC5D,OAAO,OAAO,EAAE,QAAQ,IAAI,QAAQ,CAAC;IACvC,CAAC;CACF"}
@@ -0,0 +1,57 @@
1
+ import type { AppConfig, Build, DataStore, Project } from '@aigile/core';
2
+ import type { PullRequestSync } from './pull-request-sync.js';
3
+ import type { Monitor } from './agents/monitor.js';
4
+ import type { Actor } from './services.js';
5
+ export interface SchedulerDeps {
6
+ sync: Pick<PullRequestSync, 'now' | 'lastMerged'>;
7
+ /** The Monitor, when the installation has probes or audits to run. */
8
+ monitor?: Pick<Monitor, 'sweep' | 'scheduleAudits' | 'runDueAudits' | 'lastSweep'> | null;
9
+ installRoot?: string;
10
+ /** Start the Engineer on a project; the build runs on its own. */
11
+ startBuild: (projectId: string, actor: Actor) => Promise<Pick<Build, 'id' | 'status'>>;
12
+ now?: () => number;
13
+ }
14
+ export interface TickReport {
15
+ at: string;
16
+ synced: number;
17
+ /** Sweeps the Monitor ran this tick (cadence and audits). */
18
+ swept: number;
19
+ auditsScheduled: number;
20
+ started: Array<{
21
+ projectId: string;
22
+ buildId: string;
23
+ }>;
24
+ /** Projects with changes still inside the quiet period. */
25
+ settling: string[];
26
+ }
27
+ /**
28
+ * The Orchestrator's clock (documentation/agents.md §3.5 step 3): every tick
29
+ * runs the merge sync and, with `engineer.autoBuild` on, starts a build for
30
+ * each project with a repository, no build in flight, and resolved spec
31
+ * revisions that differ from its latest build's, once the newest of those
32
+ * revisions is older than the quiet period. A rejected or failed last build
33
+ * is not retried until a spec changes again. One process ticks on an
34
+ * interval; `aigile tick` runs one tick for cron.
35
+ */
36
+ export declare class Scheduler {
37
+ private readonly config;
38
+ private readonly deps;
39
+ private readonly data;
40
+ private readonly builds;
41
+ private readonly resolver;
42
+ private readonly milestones;
43
+ private timer;
44
+ private running;
45
+ lastTick: TickReport | null;
46
+ constructor(store: DataStore, config: AppConfig, deps: SchedulerDeps);
47
+ get enabled(): boolean;
48
+ /** Tick on the configured interval; the timer never keeps the process alive. */
49
+ start(): void;
50
+ stop(): void;
51
+ nextTickAt(): string | null;
52
+ tick(): Promise<TickReport>;
53
+ private run;
54
+ /** Whether a project wants a build now: 'build', 'settling' (changes too fresh), or null. */
55
+ pending(project: Project, now: number): Promise<'build' | 'settling' | null>;
56
+ }
57
+ //# sourceMappingURL=scheduler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler.d.ts","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAKzE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAG3C,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,IAAI,CAAC,eAAe,EAAE,KAAK,GAAG,YAAY,CAAC,CAAC;IAClD,sEAAsE;IACtE,OAAO,CAAC,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,gBAAgB,GAAG,cAAc,GAAG,WAAW,CAAC,GAAG,IAAI,CAAC;IAC1F,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,kEAAkE;IAClE,UAAU,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC;IACvF,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IACd,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