@treeseed/agent 0.8.5

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 (138) hide show
  1. package/Dockerfile +7 -0
  2. package/README.md +198 -0
  3. package/dist/agent-runtime.d.ts +17 -0
  4. package/dist/agent-runtime.js +117 -0
  5. package/dist/agents/adapters/execution.d.ts +41 -0
  6. package/dist/agents/adapters/execution.js +73 -0
  7. package/dist/agents/adapters/mutations.d.ts +22 -0
  8. package/dist/agents/adapters/mutations.js +30 -0
  9. package/dist/agents/adapters/notification.d.ts +26 -0
  10. package/dist/agents/adapters/notification.js +46 -0
  11. package/dist/agents/adapters/repository.d.ts +28 -0
  12. package/dist/agents/adapters/repository.js +61 -0
  13. package/dist/agents/adapters/research.d.ts +26 -0
  14. package/dist/agents/adapters/research.js +59 -0
  15. package/dist/agents/adapters/verification.d.ts +36 -0
  16. package/dist/agents/adapters/verification.js +62 -0
  17. package/dist/agents/cli-tools.d.ts +1 -0
  18. package/dist/agents/cli-tools.js +5 -0
  19. package/dist/agents/cli.d.ts +15 -0
  20. package/dist/agents/cli.js +109 -0
  21. package/dist/agents/contracts/messages.d.ts +88 -0
  22. package/dist/agents/contracts/messages.js +138 -0
  23. package/dist/agents/contracts/run.d.ts +21 -0
  24. package/dist/agents/contracts/run.js +0 -0
  25. package/dist/agents/index.d.ts +1 -0
  26. package/dist/agents/index.js +5 -0
  27. package/dist/agents/kernel/agent-kernel.d.ts +63 -0
  28. package/dist/agents/kernel/agent-kernel.js +291 -0
  29. package/dist/agents/kernel/trigger-resolver.d.ts +19 -0
  30. package/dist/agents/kernel/trigger-resolver.js +157 -0
  31. package/dist/agents/registry-helper.d.ts +4 -0
  32. package/dist/agents/registry-helper.js +14 -0
  33. package/dist/agents/registry.d.ts +6 -0
  34. package/dist/agents/registry.js +98 -0
  35. package/dist/agents/runtime-types.d.ts +118 -0
  36. package/dist/agents/runtime-types.js +0 -0
  37. package/dist/agents/spec-loader.d.ts +18 -0
  38. package/dist/agents/spec-loader.js +54 -0
  39. package/dist/agents/spec-normalizer.d.ts +2 -0
  40. package/dist/agents/spec-normalizer.js +327 -0
  41. package/dist/agents/spec-types.d.ts +64 -0
  42. package/dist/agents/spec-types.js +0 -0
  43. package/dist/agents/testing/agents-smoke.d.ts +1 -0
  44. package/dist/agents/testing/agents-smoke.js +32 -0
  45. package/dist/agents/testing/e2e-harness.d.ts +44 -0
  46. package/dist/agents/testing/e2e-harness.js +503 -0
  47. package/dist/api/agent-routes.d.ts +13 -0
  48. package/dist/api/agent-routes.js +327 -0
  49. package/dist/api/app.d.ts +8 -0
  50. package/dist/api/app.js +444 -0
  51. package/dist/api/auth/d1-database.d.ts +3 -0
  52. package/dist/api/auth/d1-database.js +20 -0
  53. package/dist/api/auth/d1-provider.d.ts +79 -0
  54. package/dist/api/auth/d1-provider.js +92 -0
  55. package/dist/api/auth/d1-store.d.ts +114 -0
  56. package/dist/api/auth/d1-store.js +895 -0
  57. package/dist/api/auth/memory-provider.d.ts +77 -0
  58. package/dist/api/auth/memory-provider.js +249 -0
  59. package/dist/api/auth/rbac.d.ts +22 -0
  60. package/dist/api/auth/rbac.js +162 -0
  61. package/dist/api/auth/tokens.d.ts +18 -0
  62. package/dist/api/auth/tokens.js +56 -0
  63. package/dist/api/capabilities.d.ts +9 -0
  64. package/dist/api/capabilities.js +33 -0
  65. package/dist/api/config.d.ts +2 -0
  66. package/dist/api/config.js +77 -0
  67. package/dist/api/http.d.ts +28 -0
  68. package/dist/api/http.js +51 -0
  69. package/dist/api/index.d.ts +9 -0
  70. package/dist/api/index.js +20 -0
  71. package/dist/api/operations-routes.d.ts +11 -0
  72. package/dist/api/operations-routes.js +87 -0
  73. package/dist/api/operations.d.ts +3 -0
  74. package/dist/api/operations.js +26 -0
  75. package/dist/api/project-routes.d.ts +8 -0
  76. package/dist/api/project-routes.js +585 -0
  77. package/dist/api/providers.d.ts +2 -0
  78. package/dist/api/providers.js +62 -0
  79. package/dist/api/railway.d.ts +51 -0
  80. package/dist/api/railway.js +71 -0
  81. package/dist/api/sdk-dispatch.d.ts +5 -0
  82. package/dist/api/sdk-dispatch.js +13 -0
  83. package/dist/api/sdk-routes.d.ts +11 -0
  84. package/dist/api/sdk-routes.js +29 -0
  85. package/dist/api/server.d.ts +2 -0
  86. package/dist/api/server.js +10 -0
  87. package/dist/api/templates.d.ts +3 -0
  88. package/dist/api/templates.js +31 -0
  89. package/dist/api/types.d.ts +237 -0
  90. package/dist/api/types.js +0 -0
  91. package/dist/env.yaml +957 -0
  92. package/dist/index.d.ts +14 -0
  93. package/dist/index.js +41 -0
  94. package/dist/scripts/assert-release-tag-version.d.ts +1 -0
  95. package/dist/scripts/assert-release-tag-version.js +20 -0
  96. package/dist/scripts/build-dist.d.ts +1 -0
  97. package/dist/scripts/build-dist.js +106 -0
  98. package/dist/scripts/package-tools.d.ts +1 -0
  99. package/dist/scripts/package-tools.js +7 -0
  100. package/dist/scripts/publish-package.d.ts +1 -0
  101. package/dist/scripts/publish-package.js +24 -0
  102. package/dist/scripts/release-verify.d.ts +1 -0
  103. package/dist/scripts/release-verify.js +152 -0
  104. package/dist/scripts/test-smoke.d.ts +1 -0
  105. package/dist/scripts/test-smoke.js +23 -0
  106. package/dist/scripts/treeseed-agent-api.d.ts +2 -0
  107. package/dist/scripts/treeseed-agent-api.js +25 -0
  108. package/dist/scripts/treeseed-agent-service.d.ts +2 -0
  109. package/dist/scripts/treeseed-agent-service.js +36 -0
  110. package/dist/scripts/treeseed-agents.d.ts +2 -0
  111. package/dist/scripts/treeseed-agents.js +13 -0
  112. package/dist/services/agents.d.ts +17 -0
  113. package/dist/services/agents.js +48 -0
  114. package/dist/services/common.d.ts +66 -0
  115. package/dist/services/common.js +212 -0
  116. package/dist/services/index.d.ts +6 -0
  117. package/dist/services/index.js +19 -0
  118. package/dist/services/manager.d.ts +333 -0
  119. package/dist/services/manager.js +1368 -0
  120. package/dist/services/remote-runner.d.ts +30 -0
  121. package/dist/services/remote-runner.js +230 -0
  122. package/dist/services/workday-content.d.ts +53 -0
  123. package/dist/services/workday-content.js +190 -0
  124. package/dist/services/workday-manager.d.ts +391 -0
  125. package/dist/services/workday-manager.js +163 -0
  126. package/dist/services/workday-report.d.ts +238 -0
  127. package/dist/services/workday-report.js +17 -0
  128. package/dist/services/workday-start.d.ts +238 -0
  129. package/dist/services/workday-start.js +17 -0
  130. package/dist/services/worker-capacity.d.ts +58 -0
  131. package/dist/services/worker-capacity.js +208 -0
  132. package/dist/services/worker-pool-scaler.d.ts +27 -0
  133. package/dist/services/worker-pool-scaler.js +127 -0
  134. package/dist/services/worker.d.ts +19 -0
  135. package/dist/services/worker.js +436 -0
  136. package/dist/templates/github/deploy-processing.workflow.yml +119 -0
  137. package/package.json +136 -0
  138. package/templates/github/deploy-processing.workflow.yml +119 -0
@@ -0,0 +1,26 @@
1
+ import type { AgentResearchAdapter } from '../runtime-types.ts';
2
+ export declare class StubResearchAdapter implements AgentResearchAdapter {
3
+ research(input: {
4
+ questionId: string;
5
+ reason: string | null;
6
+ runId: string;
7
+ }): Promise<{
8
+ status: "completed";
9
+ summary: string;
10
+ markdown: string;
11
+ sources: never[];
12
+ }>;
13
+ }
14
+ export declare class ProjectGraphResearchAdapter implements AgentResearchAdapter {
15
+ research(input: {
16
+ questionId: string;
17
+ reason: string | null;
18
+ runId: string;
19
+ }): Promise<{
20
+ status: "completed";
21
+ summary: string;
22
+ markdown: string;
23
+ sources: any;
24
+ }>;
25
+ }
26
+ export declare function createResearchAdapter(): StubResearchAdapter | ProjectGraphResearchAdapter;
@@ -0,0 +1,59 @@
1
+ import { AgentSdk } from "@treeseed/sdk";
2
+ import { resolveTreeseedTenantRoot } from "@treeseed/sdk/platform/tenant-config";
3
+ import { getTreeseedAgentProviderSelections } from "@treeseed/sdk/platform/deploy-runtime";
4
+ class StubResearchAdapter {
5
+ async research(input) {
6
+ return {
7
+ status: "completed",
8
+ summary: `Research prepared for ${input.questionId}.`,
9
+ markdown: [
10
+ "# Research Summary",
11
+ "",
12
+ `Question: ${input.questionId}`,
13
+ `Reason: ${input.reason ?? "not provided"}`,
14
+ `Run: ${input.runId}`,
15
+ "",
16
+ "This is a stub research summary produced by the runtime adapter."
17
+ ].join("\n"),
18
+ sources: []
19
+ };
20
+ }
21
+ }
22
+ class ProjectGraphResearchAdapter {
23
+ async research(input) {
24
+ const repoRoot = resolveTreeseedTenantRoot();
25
+ const sdk = AgentSdk.createLocal({ repoRoot });
26
+ const graphResult = await sdk.queryGraph({
27
+ query: input.questionId,
28
+ options: {
29
+ limit: 5
30
+ }
31
+ }).catch(() => null);
32
+ const items = Array.isArray(graphResult?.items) ? graphResult.items : [];
33
+ return {
34
+ status: "completed",
35
+ summary: `Graph-backed research prepared for ${input.questionId}.`,
36
+ markdown: [
37
+ "# Research Summary",
38
+ "",
39
+ `Question: ${input.questionId}`,
40
+ `Reason: ${input.reason ?? "not provided"}`,
41
+ `Run: ${input.runId}`,
42
+ "",
43
+ items.length ? "Relevant graph context:" : "No ranked graph context was available. The question is still recorded for follow-up.",
44
+ ...items.map((item) => `- ${String(item.title ?? item.id ?? "context")}`)
45
+ ].join("\n"),
46
+ sources: items.map((item) => String(item.id ?? item.title ?? "")).filter(Boolean)
47
+ };
48
+ }
49
+ }
50
+ function createResearchAdapter() {
51
+ return String(
52
+ process.env.TREESEED_AGENT_RESEARCH_PROVIDER ?? getTreeseedAgentProviderSelections().research
53
+ ).toLowerCase() === "project_graph" ? new ProjectGraphResearchAdapter() : new StubResearchAdapter();
54
+ }
55
+ export {
56
+ ProjectGraphResearchAdapter,
57
+ StubResearchAdapter,
58
+ createResearchAdapter
59
+ };
@@ -0,0 +1,36 @@
1
+ import type { AgentVerificationAdapter } from '../runtime-types.ts';
2
+ export declare class StubVerificationAdapter implements AgentVerificationAdapter {
3
+ runChecks(input: {
4
+ commands: string[];
5
+ runId: string;
6
+ }): Promise<{
7
+ status: "completed";
8
+ summary: string;
9
+ stdout: string;
10
+ stderr: string;
11
+ }>;
12
+ }
13
+ export declare class LocalVerificationAdapter implements AgentVerificationAdapter {
14
+ runChecks(input: {
15
+ commands: string[];
16
+ }): Promise<{
17
+ status: "waiting";
18
+ summary: string;
19
+ stdout: string;
20
+ stderr: string;
21
+ errorCategory?: undefined;
22
+ } | {
23
+ status: "failed";
24
+ summary: string;
25
+ stdout: string;
26
+ stderr: string;
27
+ errorCategory: "execution_error";
28
+ } | {
29
+ status: "completed";
30
+ summary: string;
31
+ stdout: string;
32
+ stderr: string;
33
+ errorCategory?: undefined;
34
+ }>;
35
+ }
36
+ export declare function createVerificationAdapter(): StubVerificationAdapter | LocalVerificationAdapter;
@@ -0,0 +1,62 @@
1
+ import { execFile } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import { getTreeseedAgentProviderSelections } from "@treeseed/sdk/platform/deploy-runtime";
4
+ const execFileAsync = promisify(execFile);
5
+ class StubVerificationAdapter {
6
+ async runChecks(input) {
7
+ return {
8
+ status: "completed",
9
+ summary: input.commands.length ? `Stub verification completed for ${input.runId}.` : "No verification commands configured.",
10
+ stdout: input.commands.join("\n"),
11
+ stderr: ""
12
+ };
13
+ }
14
+ }
15
+ class LocalVerificationAdapter {
16
+ async runChecks(input) {
17
+ if (!input.commands.length) {
18
+ return {
19
+ status: "waiting",
20
+ summary: "No verification commands configured.",
21
+ stdout: "",
22
+ stderr: ""
23
+ };
24
+ }
25
+ const stdoutChunks = [];
26
+ const stderrChunks = [];
27
+ for (const command of input.commands) {
28
+ try {
29
+ const { stdout, stderr } = await execFileAsync("/bin/bash", ["-lc", command], {
30
+ env: process.env,
31
+ maxBuffer: 10 * 1024 * 1024
32
+ });
33
+ stdoutChunks.push(stdout);
34
+ stderrChunks.push(stderr);
35
+ } catch (error) {
36
+ return {
37
+ status: "failed",
38
+ summary: `Verification command failed: ${command}`,
39
+ stdout: stdoutChunks.join("\n"),
40
+ stderr: error && typeof error === "object" && "stderr" in error ? String(error.stderr ?? "") : String(error),
41
+ errorCategory: "execution_error"
42
+ };
43
+ }
44
+ }
45
+ return {
46
+ status: "completed",
47
+ summary: `Verification completed for ${input.commands.length} command(s).`,
48
+ stdout: stdoutChunks.join("\n"),
49
+ stderr: stderrChunks.join("\n")
50
+ };
51
+ }
52
+ }
53
+ function createVerificationAdapter() {
54
+ return String(
55
+ process.env.TREESEED_AGENT_VERIFICATION_PROVIDER ?? getTreeseedAgentProviderSelections().verification
56
+ ).toLowerCase() !== "local" ? new StubVerificationAdapter() : new LocalVerificationAdapter();
57
+ }
58
+ export {
59
+ LocalVerificationAdapter,
60
+ StubVerificationAdapter,
61
+ createVerificationAdapter
62
+ };
@@ -0,0 +1 @@
1
+ export { normalizeAgentCliOptions, buildCopilotAllowToolArgs } from '@treeseed/sdk/cli-tools';
@@ -0,0 +1,5 @@
1
+ import { normalizeAgentCliOptions, buildCopilotAllowToolArgs } from "@treeseed/sdk/cli-tools";
2
+ export {
3
+ buildCopilotAllowToolArgs,
4
+ normalizeAgentCliOptions
5
+ };
@@ -0,0 +1,15 @@
1
+ export type TreeseedAgentCliCommandName = 'doctor' | 'run-agent' | 'drain-messages' | 'release-leases' | 'replay-message' | 'start';
2
+ export type TreeseedAgentCliCommandSpec = {
3
+ name: TreeseedAgentCliCommandName;
4
+ usage: string;
5
+ summary: string;
6
+ };
7
+ export type TreeseedAgentCliContext = {
8
+ cwd?: string;
9
+ env?: NodeJS.ProcessEnv;
10
+ write?: (output: string, stream?: 'stdout' | 'stderr') => void;
11
+ outputFormat?: 'human' | 'json';
12
+ };
13
+ export declare function listTreeseedAgentCommands(): TreeseedAgentCliCommandSpec[];
14
+ export declare function renderTreeseedAgentHelp(): string;
15
+ export declare function runTreeseedAgentCli(argv: string[], context?: TreeseedAgentCliContext): Promise<number>;
@@ -0,0 +1,109 @@
1
+ import { realpathSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ const AGENT_COMMAND_SPECS = [
5
+ { name: "doctor", usage: "doctor", summary: "Inspect agent runtime readiness for the current tenant." },
6
+ { name: "run-agent", usage: "run-agent <slug>", summary: "Run one registered agent handler by slug." },
7
+ { name: "drain-messages", usage: "drain-messages", summary: "Drain queued agent messages through the local kernel." },
8
+ { name: "release-leases", usage: "release-leases", summary: "Release active task leases held by the local kernel." },
9
+ { name: "replay-message", usage: "replay-message <id>", summary: "Replay one message by numeric id." },
10
+ { name: "start", usage: "start", summary: "Start the local agent kernel loop." }
11
+ ];
12
+ function parseArgs(argv) {
13
+ const [command = "doctor", ...rest] = argv;
14
+ return {
15
+ command,
16
+ args: rest
17
+ };
18
+ }
19
+ function listTreeseedAgentCommands() {
20
+ return [...AGENT_COMMAND_SPECS];
21
+ }
22
+ function renderTreeseedAgentHelp() {
23
+ return [
24
+ "treeseed agents <command>",
25
+ "",
26
+ "Commands:",
27
+ ...AGENT_COMMAND_SPECS.map((command) => ` ${command.usage.padEnd(24)}${command.summary}`)
28
+ ].join("\n");
29
+ }
30
+ function defaultWrite(output, stream = "stdout") {
31
+ if (!output) return;
32
+ (stream === "stderr" ? process.stderr : process.stdout).write(`${output}
33
+ `);
34
+ }
35
+ function resolveExecutablePath(path) {
36
+ try {
37
+ return realpathSync(path);
38
+ } catch {
39
+ return resolve(path);
40
+ }
41
+ }
42
+ async function runTreeseedAgentCli(argv, context = {}) {
43
+ const { command, args } = parseArgs(argv);
44
+ const write = context.write ?? defaultWrite;
45
+ if (command === "--help" || command === "-h" || command === "help") {
46
+ write(renderTreeseedAgentHelp(), "stdout");
47
+ return 0;
48
+ }
49
+ const [{ AgentKernel }, { AgentSdk }] = await Promise.all([
50
+ import("./kernel/agent-kernel.js"),
51
+ import("@treeseed/sdk/sdk")
52
+ ]);
53
+ const repoRoot = context.cwd ?? process.cwd();
54
+ const env = { ...process.env, ...context.env ?? {} };
55
+ const sdk = AgentSdk.createLocal({
56
+ repoRoot,
57
+ databaseName: env.TREESEED_AGENT_D1_DATABASE ?? "karyon-docs-site-data",
58
+ persistTo: env.TREESEED_AGENT_D1_PERSIST_TO ?? void 0
59
+ });
60
+ const kernel = new AgentKernel(sdk, repoRoot);
61
+ const emitPayload = async (payload) => {
62
+ write(JSON.stringify(await payload, null, 2), "stdout");
63
+ return 0;
64
+ };
65
+ if (command === "doctor") {
66
+ return emitPayload({ ok: true, command, ...await kernel.doctor() });
67
+ }
68
+ if (command === "run-agent") {
69
+ return emitPayload({ ok: true, command, slug: args[0], result: await kernel.runAgent(args[0]) });
70
+ }
71
+ if (command === "drain-messages") {
72
+ return emitPayload({ ok: true, command, results: await kernel.drainMessages() });
73
+ }
74
+ if (command === "release-leases") {
75
+ return emitPayload({ ok: true, command, result: await kernel.releaseLeases() });
76
+ }
77
+ if (command === "replay-message") {
78
+ return emitPayload({ ok: true, command, result: await kernel.replayMessage(Number(args[0])) });
79
+ }
80
+ if (command === "start") {
81
+ write(JSON.stringify({ ok: true, command, status: "starting" }, null, 2), "stdout");
82
+ await kernel.start();
83
+ return 0;
84
+ }
85
+ throw new Error(`Unknown Treeseed command "${command}".`);
86
+ }
87
+ const currentFile = resolveExecutablePath(fileURLToPath(import.meta.url));
88
+ const entryFile = resolveExecutablePath(process.argv[1] ?? "");
89
+ if (entryFile === currentFile) {
90
+ runTreeseedAgentCli(process.argv.slice(2)).catch((error) => {
91
+ defaultWrite(
92
+ JSON.stringify(
93
+ {
94
+ ok: false,
95
+ error: error instanceof Error ? error.message : String(error)
96
+ },
97
+ null,
98
+ 2
99
+ ),
100
+ "stderr"
101
+ );
102
+ process.exit(1);
103
+ });
104
+ }
105
+ export {
106
+ listTreeseedAgentCommands,
107
+ renderTreeseedAgentHelp,
108
+ runTreeseedAgentCli
109
+ };
@@ -0,0 +1,88 @@
1
+ export interface QuestionPriorityUpdatedMessage {
2
+ questionId: string;
3
+ reason: string;
4
+ plannerRunId: string;
5
+ }
6
+ export interface ObjectivePriorityUpdatedMessage {
7
+ objectiveId: string;
8
+ reason: string;
9
+ plannerRunId: string;
10
+ }
11
+ export interface ArchitectureUpdatedMessage {
12
+ objectiveId: string;
13
+ knowledgeId: string;
14
+ architectRunId: string;
15
+ }
16
+ export interface SubscriberNotifiedMessage {
17
+ email: string;
18
+ itemCount: number;
19
+ notifierRunId: string;
20
+ }
21
+ export interface ResearchStartedMessage {
22
+ questionId: string;
23
+ researcherRunId: string;
24
+ }
25
+ export interface ResearchCompletedMessage {
26
+ questionId: string;
27
+ knowledgeId: string | null;
28
+ researcherRunId: string;
29
+ }
30
+ export interface TaskCompleteMessage {
31
+ branchName: string | null;
32
+ changedTargets: string[];
33
+ engineerRunId: string;
34
+ }
35
+ export interface TaskWaitingMessage {
36
+ blockingReason: string;
37
+ engineerRunId: string;
38
+ }
39
+ export interface TaskFailedMessage {
40
+ failureSummary: string;
41
+ engineerRunId: string;
42
+ }
43
+ export interface TaskVerifiedMessage {
44
+ branchName: string | null;
45
+ reviewerRunId: string;
46
+ }
47
+ export interface ReviewFailedMessage {
48
+ failureSummary: string;
49
+ reviewerRunId: string;
50
+ }
51
+ export interface ReviewWaitingMessage {
52
+ blockingReason: string;
53
+ reviewerRunId: string;
54
+ }
55
+ export interface ReleaseStartedMessage {
56
+ taskRunId: string | null;
57
+ releaserRunId: string;
58
+ }
59
+ export interface ReleaseCompletedMessage {
60
+ releaseSummary: string;
61
+ releaserRunId: string;
62
+ }
63
+ export interface ReleaseFailedMessage {
64
+ failureSummary: string;
65
+ releaserRunId: string;
66
+ }
67
+ export interface AgentMessageContracts {
68
+ question_priority_updated: QuestionPriorityUpdatedMessage;
69
+ objective_priority_updated: ObjectivePriorityUpdatedMessage;
70
+ architecture_updated: ArchitectureUpdatedMessage;
71
+ subscriber_notified: SubscriberNotifiedMessage;
72
+ research_started: ResearchStartedMessage;
73
+ research_completed: ResearchCompletedMessage;
74
+ task_complete: TaskCompleteMessage;
75
+ task_waiting: TaskWaitingMessage;
76
+ task_failed: TaskFailedMessage;
77
+ task_verified: TaskVerifiedMessage;
78
+ review_failed: ReviewFailedMessage;
79
+ review_waiting: ReviewWaitingMessage;
80
+ release_started: ReleaseStartedMessage;
81
+ release_completed: ReleaseCompletedMessage;
82
+ release_failed: ReleaseFailedMessage;
83
+ }
84
+ export type AgentMessageType = keyof AgentMessageContracts;
85
+ export type AgentMessagePayload<TType extends AgentMessageType> = AgentMessageContracts[TType];
86
+ export declare const AGENT_MESSAGE_TYPES: readonly ["question_priority_updated", "objective_priority_updated", "architecture_updated", "subscriber_notified", "research_started", "research_completed", "task_complete", "task_waiting", "task_failed", "task_verified", "review_failed", "review_waiting", "release_started", "release_completed", "release_failed"];
87
+ export declare function parseAgentMessagePayload<TType extends AgentMessageType>(type: TType, payloadJson: string): AgentMessagePayload<TType>;
88
+ export declare function serializeAgentMessagePayload<TType extends AgentMessageType>(type: TType, payload: AgentMessagePayload<TType>): Record<string, unknown>;
@@ -0,0 +1,138 @@
1
+ const AGENT_MESSAGE_TYPES = [
2
+ "question_priority_updated",
3
+ "objective_priority_updated",
4
+ "architecture_updated",
5
+ "subscriber_notified",
6
+ "research_started",
7
+ "research_completed",
8
+ "task_complete",
9
+ "task_waiting",
10
+ "task_failed",
11
+ "task_verified",
12
+ "review_failed",
13
+ "review_waiting",
14
+ "release_started",
15
+ "release_completed",
16
+ "release_failed"
17
+ ];
18
+ function ensureString(value, label) {
19
+ if (typeof value !== "string" || value.trim().length === 0) {
20
+ throw new Error(`Invalid ${label}: expected non-empty string.`);
21
+ }
22
+ return value;
23
+ }
24
+ function ensureOptionalString(value, label) {
25
+ if (value === null || value === void 0) {
26
+ return null;
27
+ }
28
+ return ensureString(value, label);
29
+ }
30
+ function ensureStringArray(value, label) {
31
+ if (!Array.isArray(value)) {
32
+ throw new Error(`Invalid ${label}: expected array.`);
33
+ }
34
+ return value.map((entry, index) => ensureString(entry, `${label}[${index}]`));
35
+ }
36
+ function ensureNumber(value, label) {
37
+ if (typeof value !== "number" || Number.isNaN(value)) {
38
+ throw new Error(`Invalid ${label}: expected number.`);
39
+ }
40
+ return value;
41
+ }
42
+ function parseAgentMessagePayload(type, payloadJson) {
43
+ const parsed = JSON.parse(payloadJson);
44
+ switch (type) {
45
+ case "question_priority_updated":
46
+ return {
47
+ questionId: ensureString(parsed.questionId, "questionId"),
48
+ reason: ensureString(parsed.reason, "reason"),
49
+ plannerRunId: ensureString(parsed.plannerRunId, "plannerRunId")
50
+ };
51
+ case "objective_priority_updated":
52
+ return {
53
+ objectiveId: ensureString(parsed.objectiveId, "objectiveId"),
54
+ reason: ensureString(parsed.reason, "reason"),
55
+ plannerRunId: ensureString(parsed.plannerRunId, "plannerRunId")
56
+ };
57
+ case "architecture_updated":
58
+ return {
59
+ objectiveId: ensureString(parsed.objectiveId, "objectiveId"),
60
+ knowledgeId: ensureString(parsed.knowledgeId, "knowledgeId"),
61
+ architectRunId: ensureString(parsed.architectRunId, "architectRunId")
62
+ };
63
+ case "subscriber_notified":
64
+ return {
65
+ email: ensureString(parsed.email, "email"),
66
+ itemCount: ensureNumber(parsed.itemCount, "itemCount"),
67
+ notifierRunId: ensureString(parsed.notifierRunId, "notifierRunId")
68
+ };
69
+ case "research_started":
70
+ return {
71
+ questionId: ensureString(parsed.questionId, "questionId"),
72
+ researcherRunId: ensureString(parsed.researcherRunId, "researcherRunId")
73
+ };
74
+ case "research_completed":
75
+ return {
76
+ questionId: ensureString(parsed.questionId, "questionId"),
77
+ knowledgeId: ensureOptionalString(parsed.knowledgeId, "knowledgeId"),
78
+ researcherRunId: ensureString(parsed.researcherRunId, "researcherRunId")
79
+ };
80
+ case "task_complete":
81
+ return {
82
+ branchName: ensureOptionalString(parsed.branchName, "branchName"),
83
+ changedTargets: ensureStringArray(parsed.changedTargets, "changedTargets"),
84
+ engineerRunId: ensureString(parsed.engineerRunId, "engineerRunId")
85
+ };
86
+ case "task_waiting":
87
+ return {
88
+ blockingReason: ensureString(parsed.blockingReason, "blockingReason"),
89
+ engineerRunId: ensureString(parsed.engineerRunId, "engineerRunId")
90
+ };
91
+ case "task_failed":
92
+ return {
93
+ failureSummary: ensureString(parsed.failureSummary, "failureSummary"),
94
+ engineerRunId: ensureString(parsed.engineerRunId, "engineerRunId")
95
+ };
96
+ case "task_verified":
97
+ return {
98
+ branchName: ensureOptionalString(parsed.branchName, "branchName"),
99
+ reviewerRunId: ensureString(parsed.reviewerRunId, "reviewerRunId")
100
+ };
101
+ case "review_failed":
102
+ return {
103
+ failureSummary: ensureString(parsed.failureSummary, "failureSummary"),
104
+ reviewerRunId: ensureString(parsed.reviewerRunId, "reviewerRunId")
105
+ };
106
+ case "review_waiting":
107
+ return {
108
+ blockingReason: ensureString(parsed.blockingReason, "blockingReason"),
109
+ reviewerRunId: ensureString(parsed.reviewerRunId, "reviewerRunId")
110
+ };
111
+ case "release_started":
112
+ return {
113
+ taskRunId: ensureOptionalString(parsed.taskRunId, "taskRunId"),
114
+ releaserRunId: ensureString(parsed.releaserRunId, "releaserRunId")
115
+ };
116
+ case "release_completed":
117
+ return {
118
+ releaseSummary: ensureString(parsed.releaseSummary, "releaseSummary"),
119
+ releaserRunId: ensureString(parsed.releaserRunId, "releaserRunId")
120
+ };
121
+ case "release_failed":
122
+ return {
123
+ failureSummary: ensureString(parsed.failureSummary, "failureSummary"),
124
+ releaserRunId: ensureString(parsed.releaserRunId, "releaserRunId")
125
+ };
126
+ default:
127
+ throw new Error(`Unsupported message type "${type}".`);
128
+ }
129
+ }
130
+ function serializeAgentMessagePayload(type, payload) {
131
+ parseAgentMessagePayload(type, JSON.stringify(payload));
132
+ return payload;
133
+ }
134
+ export {
135
+ AGENT_MESSAGE_TYPES,
136
+ parseAgentMessagePayload,
137
+ serializeAgentMessagePayload
138
+ };
@@ -0,0 +1,21 @@
1
+ export type AgentErrorCategory = 'trigger_resolution_error' | 'permission_error' | 'message_claim_error' | 'lease_error' | 'execution_error' | 'mutation_error' | 'sdk_error';
2
+ export interface AgentRunTrace {
3
+ [key: string]: unknown;
4
+ runId: string;
5
+ agentSlug: string;
6
+ handlerKind: string;
7
+ triggerKind: string;
8
+ triggerSource: string;
9
+ claimedMessageId: number | null;
10
+ selectedItemKey: string | null;
11
+ branchName: string | null;
12
+ commitSha: string | null;
13
+ changedPaths: string[];
14
+ summary: string | null;
15
+ error: string | null;
16
+ errorCategory: AgentErrorCategory | null;
17
+ startedAt: string;
18
+ finishedAt: string | null;
19
+ status: string;
20
+ }
21
+ export {};
File without changes
@@ -0,0 +1 @@
1
+ export { listRegisteredAgentHandlers, resolveAgentHandler } from './registry.ts';
@@ -0,0 +1,5 @@
1
+ import { listRegisteredAgentHandlers, resolveAgentHandler } from "./registry.js";
2
+ export {
3
+ listRegisteredAgentHandlers,
4
+ resolveAgentHandler
5
+ };
@@ -0,0 +1,63 @@
1
+ import type { AgentExecutionAdapter, AgentMutationAdapter, AgentNotificationAdapter, AgentRepositoryInspectionAdapter, AgentResearchAdapter, AgentTriggerInvocation, AgentVerificationAdapter } from '../runtime-types.ts';
2
+ import { AgentSdk } from '@treeseed/sdk/sdk';
3
+ export declare class AgentKernel {
4
+ private readonly sdk;
5
+ private readonly repoRoot;
6
+ private readonly execution;
7
+ private readonly mutations;
8
+ private readonly repository;
9
+ private readonly verification;
10
+ private readonly notifications;
11
+ private readonly research;
12
+ private readonly activeRuns;
13
+ private readonly lastRunAt;
14
+ constructor(sdk: AgentSdk, repoRoot: string, options?: {
15
+ execution?: AgentExecutionAdapter;
16
+ mutations?: AgentMutationAdapter;
17
+ repository?: AgentRepositoryInspectionAdapter;
18
+ verification?: AgentVerificationAdapter;
19
+ notifications?: AgentNotificationAdapter;
20
+ research?: AgentResearchAdapter;
21
+ });
22
+ doctor(): Promise<{
23
+ agents: {
24
+ slug: string;
25
+ handler: string;
26
+ enabled: boolean;
27
+ triggers: ("message" | "follow" | "schedule" | "startup")[];
28
+ }[];
29
+ diagnostics: import("../spec-types.ts").AgentSpecDiagnostic[];
30
+ }>;
31
+ private sortAgents;
32
+ private resolveTrigger;
33
+ private recordRunTrace;
34
+ private buildTrace;
35
+ private categorizeError;
36
+ private executeAgent;
37
+ runAgent(slug: string, mode?: 'auto' | 'manual', invocation?: AgentTriggerInvocation | null): Promise<{
38
+ status: string;
39
+ summary: string;
40
+ }>;
41
+ runCycle(): Promise<{
42
+ slug: string;
43
+ result: import("../runtime-types.ts").AgentExecutionResult | {
44
+ status: string;
45
+ summary: string;
46
+ };
47
+ }[]>;
48
+ start(intervalMs?: number): Promise<void>;
49
+ drainMessages(): Promise<{
50
+ slug: string;
51
+ result: {
52
+ status: string;
53
+ summary: string;
54
+ };
55
+ }[]>;
56
+ releaseLeases(): Promise<import("@treeseed/sdk").SdkJsonEnvelope<{
57
+ count: number;
58
+ }>>;
59
+ replayMessage(id: number): Promise<{
60
+ id: number;
61
+ status: string;
62
+ }>;
63
+ }