@treeseed/core 0.8.3 → 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.
- package/README.md +7 -11
- package/dist/dev-watch.js +1 -1
- package/dist/dev.d.ts +2 -4
- package/dist/dev.js +4 -124
- package/dist/env.yaml +23 -175
- package/dist/index.d.ts +0 -4
- package/dist/index.js +0 -6
- package/dist/scripts/build-dist.js +3 -3
- package/dist/scripts/dev-platform.js +1 -7
- package/dist/scripts/run-fixture-astro-command.js +25 -51
- package/dist/scripts/test-smoke.js +50 -7
- package/package.json +5 -78
- package/templates/github/deploy-web.workflow.yml +111 -0
- package/templates/github/hosted-project.workflow.yml +4 -4
- package/dist/agent-runtime.d.ts +0 -17
- package/dist/agent-runtime.js +0 -117
- package/dist/agent.d.ts +0 -11
- package/dist/agent.js +0 -25
- package/dist/agents/adapters/execution.d.ts +0 -41
- package/dist/agents/adapters/execution.js +0 -73
- package/dist/agents/adapters/mutations.d.ts +0 -22
- package/dist/agents/adapters/mutations.js +0 -30
- package/dist/agents/adapters/notification.d.ts +0 -26
- package/dist/agents/adapters/notification.js +0 -46
- package/dist/agents/adapters/repository.d.ts +0 -23
- package/dist/agents/adapters/repository.js +0 -61
- package/dist/agents/adapters/research.d.ts +0 -26
- package/dist/agents/adapters/research.js +0 -59
- package/dist/agents/adapters/verification.d.ts +0 -36
- package/dist/agents/adapters/verification.js +0 -62
- package/dist/agents/cli-tools.d.ts +0 -1
- package/dist/agents/cli-tools.js +0 -5
- package/dist/agents/cli.d.ts +0 -15
- package/dist/agents/cli.js +0 -109
- package/dist/agents/contracts/messages.d.ts +0 -88
- package/dist/agents/contracts/messages.js +0 -138
- package/dist/agents/contracts/run.d.ts +0 -21
- package/dist/agents/contracts/run.js +0 -0
- package/dist/agents/index.d.ts +0 -1
- package/dist/agents/index.js +0 -5
- package/dist/agents/kernel/agent-kernel.d.ts +0 -51
- package/dist/agents/kernel/agent-kernel.js +0 -292
- package/dist/agents/kernel/trigger-resolver.d.ts +0 -19
- package/dist/agents/kernel/trigger-resolver.js +0 -157
- package/dist/agents/registry-helper.d.ts +0 -4
- package/dist/agents/registry-helper.js +0 -14
- package/dist/agents/registry.d.ts +0 -6
- package/dist/agents/registry.js +0 -98
- package/dist/agents/runtime-types.d.ts +0 -118
- package/dist/agents/runtime-types.js +0 -0
- package/dist/agents/spec-loader.d.ts +0 -18
- package/dist/agents/spec-loader.js +0 -55
- package/dist/agents/spec-normalizer.d.ts +0 -2
- package/dist/agents/spec-normalizer.js +0 -327
- package/dist/agents/spec-types.d.ts +0 -64
- package/dist/agents/spec-types.js +0 -0
- package/dist/agents/testing/agents-smoke.d.ts +0 -1
- package/dist/agents/testing/agents-smoke.js +0 -32
- package/dist/agents/testing/e2e-harness.d.ts +0 -44
- package/dist/agents/testing/e2e-harness.js +0 -504
- package/dist/api/agent-routes.d.ts +0 -13
- package/dist/api/agent-routes.js +0 -327
- package/dist/api/app.d.ts +0 -5
- package/dist/api/app.js +0 -361
- package/dist/api/auth/d1-database.d.ts +0 -3
- package/dist/api/auth/d1-database.js +0 -20
- package/dist/api/auth/d1-provider.d.ts +0 -79
- package/dist/api/auth/d1-provider.js +0 -92
- package/dist/api/auth/d1-store.d.ts +0 -114
- package/dist/api/auth/d1-store.js +0 -895
- package/dist/api/auth/memory-provider.d.ts +0 -77
- package/dist/api/auth/memory-provider.js +0 -249
- package/dist/api/auth/rbac.d.ts +0 -22
- package/dist/api/auth/rbac.js +0 -162
- package/dist/api/auth/tokens.d.ts +0 -18
- package/dist/api/auth/tokens.js +0 -56
- package/dist/api/capabilities.d.ts +0 -9
- package/dist/api/capabilities.js +0 -33
- package/dist/api/config.d.ts +0 -2
- package/dist/api/config.js +0 -77
- package/dist/api/http.d.ts +0 -28
- package/dist/api/http.js +0 -51
- package/dist/api/index.d.ts +0 -9
- package/dist/api/index.js +0 -18
- package/dist/api/operations-routes.d.ts +0 -11
- package/dist/api/operations-routes.js +0 -87
- package/dist/api/operations.d.ts +0 -3
- package/dist/api/operations.js +0 -26
- package/dist/api/project-routes.d.ts +0 -8
- package/dist/api/project-routes.js +0 -586
- package/dist/api/providers.d.ts +0 -2
- package/dist/api/providers.js +0 -62
- package/dist/api/railway.d.ts +0 -50
- package/dist/api/railway.js +0 -69
- package/dist/api/sdk-dispatch.d.ts +0 -5
- package/dist/api/sdk-dispatch.js +0 -13
- package/dist/api/sdk-routes.d.ts +0 -11
- package/dist/api/sdk-routes.js +0 -29
- package/dist/api/server.d.ts +0 -2
- package/dist/api/server.js +0 -10
- package/dist/api/templates.d.ts +0 -3
- package/dist/api/templates.js +0 -31
- package/dist/api/types.d.ts +0 -231
- package/dist/api/types.js +0 -0
- package/dist/api.d.ts +0 -1
- package/dist/api.js +0 -1
- package/dist/railway.d.ts +0 -1
- package/dist/railway.js +0 -4
- package/dist/services/agents.d.ts +0 -11
- package/dist/services/agents.js +0 -48
- package/dist/services/common.d.ts +0 -66
- package/dist/services/common.js +0 -212
- package/dist/services/index.d.ts +0 -6
- package/dist/services/index.js +0 -19
- package/dist/services/manager.d.ts +0 -267
- package/dist/services/manager.js +0 -1368
- package/dist/services/remote-runner.d.ts +0 -30
- package/dist/services/remote-runner.js +0 -230
- package/dist/services/workday-content.d.ts +0 -53
- package/dist/services/workday-content.js +0 -190
- package/dist/services/workday-manager.d.ts +0 -279
- package/dist/services/workday-manager.js +0 -163
- package/dist/services/workday-report.d.ts +0 -195
- package/dist/services/workday-report.js +0 -17
- package/dist/services/workday-start.d.ts +0 -195
- package/dist/services/workday-start.js +0 -17
- package/dist/services/worker-capacity.d.ts +0 -58
- package/dist/services/worker-capacity.js +0 -208
- package/dist/services/worker-pool-scaler.d.ts +0 -27
- package/dist/services/worker-pool-scaler.js +0 -127
- package/dist/services/worker.d.ts +0 -19
- package/dist/services/worker.js +0 -436
- package/templates/github/deploy.workflow.yml +0 -577
|
@@ -1,88 +0,0 @@
|
|
|
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>;
|
|
@@ -1,138 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
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
|
package/dist/agents/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { listRegisteredAgentHandlers, resolveAgentHandler } from './registry.ts';
|
package/dist/agents/index.js
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
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: ("startup" | "schedule" | "message" | "follow")[];
|
|
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<any[]>;
|
|
42
|
-
start(intervalMs?: number): Promise<void>;
|
|
43
|
-
drainMessages(): Promise<any[]>;
|
|
44
|
-
releaseLeases(): Promise<import("@treeseed/sdk").SdkJsonEnvelope<{
|
|
45
|
-
count: number;
|
|
46
|
-
}>>;
|
|
47
|
-
replayMessage(id: number): Promise<{
|
|
48
|
-
id: number;
|
|
49
|
-
status: string;
|
|
50
|
-
}>;
|
|
51
|
-
}
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { createExecutionAdapter } from "../adapters/execution.js";
|
|
2
|
-
import { LocalBranchMutationAdapter } from "../adapters/mutations.js";
|
|
3
|
-
import { createNotificationAdapter } from "../adapters/notification.js";
|
|
4
|
-
import { createRepositoryInspectionAdapter } from "../adapters/repository.js";
|
|
5
|
-
import { createResearchAdapter } from "../adapters/research.js";
|
|
6
|
-
import { createVerificationAdapter } from "../adapters/verification.js";
|
|
7
|
-
import { resolveAgentHandler } from "../registry.js";
|
|
8
|
-
import { AgentSdk } from "@treeseed/sdk/sdk";
|
|
9
|
-
import { followCursorKey, resolveTriggerDecision } from "./trigger-resolver.js";
|
|
10
|
-
import { loadActiveAgentSpecs, loadAllAgentSpecs, summarizeAgentSpec } from "../spec-loader.js";
|
|
11
|
-
import { getTreeseedAgentProviderSelections } from "@treeseed/sdk/platform/deploy-runtime";
|
|
12
|
-
import { resolveAgentRuntimeProviders } from "../../agent-runtime.js";
|
|
13
|
-
function nowIso() {
|
|
14
|
-
return (/* @__PURE__ */ new Date()).toISOString();
|
|
15
|
-
}
|
|
16
|
-
class AgentKernel {
|
|
17
|
-
constructor(sdk, repoRoot, options) {
|
|
18
|
-
this.sdk = sdk;
|
|
19
|
-
this.repoRoot = repoRoot;
|
|
20
|
-
const runtimeProviders = resolveAgentRuntimeProviders(repoRoot, getTreeseedAgentProviderSelections());
|
|
21
|
-
this.execution = options?.execution ?? runtimeProviders.execution ?? createExecutionAdapter();
|
|
22
|
-
this.mutations = options?.mutations ?? runtimeProviders.mutations ?? new LocalBranchMutationAdapter(repoRoot);
|
|
23
|
-
this.repository = options?.repository ?? runtimeProviders.repository ?? createRepositoryInspectionAdapter();
|
|
24
|
-
this.verification = options?.verification ?? runtimeProviders.verification ?? createVerificationAdapter();
|
|
25
|
-
this.notifications = options?.notifications ?? runtimeProviders.notifications ?? createNotificationAdapter();
|
|
26
|
-
this.research = options?.research ?? runtimeProviders.research ?? createResearchAdapter();
|
|
27
|
-
}
|
|
28
|
-
sdk;
|
|
29
|
-
repoRoot;
|
|
30
|
-
execution;
|
|
31
|
-
mutations;
|
|
32
|
-
repository;
|
|
33
|
-
verification;
|
|
34
|
-
notifications;
|
|
35
|
-
research;
|
|
36
|
-
activeRuns = /* @__PURE__ */ new Set();
|
|
37
|
-
lastRunAt = /* @__PURE__ */ new Map();
|
|
38
|
-
async doctor() {
|
|
39
|
-
const { specs, diagnostics } = await loadAllAgentSpecs(this.sdk);
|
|
40
|
-
for (const agent of specs.filter((entry) => entry.enabled)) {
|
|
41
|
-
await resolveAgentHandler(agent.handler);
|
|
42
|
-
}
|
|
43
|
-
const errors = diagnostics.filter((entry) => entry.severity === "error");
|
|
44
|
-
if (errors.length) {
|
|
45
|
-
throw new Error(
|
|
46
|
-
`Agent spec validation failed: ${errors.map((entry) => `${entry.slug}:${entry.field}:${entry.message}`).join(" | ")}`
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
return {
|
|
50
|
-
agents: specs.map(summarizeAgentSpec),
|
|
51
|
-
diagnostics
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
sortAgents(agents) {
|
|
55
|
-
const priority = {
|
|
56
|
-
planner: 10,
|
|
57
|
-
researcher: 20,
|
|
58
|
-
architect: 30,
|
|
59
|
-
engineer: 40,
|
|
60
|
-
reviewer: 50,
|
|
61
|
-
releaser: 60,
|
|
62
|
-
notifier: 70
|
|
63
|
-
};
|
|
64
|
-
return [...agents].sort(
|
|
65
|
-
(left, right) => (priority[left.handler] ?? 100) - (priority[right.handler] ?? 100)
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
async resolveTrigger(agent, mode = "auto") {
|
|
69
|
-
const decision = await resolveTriggerDecision({
|
|
70
|
-
agent,
|
|
71
|
-
mode,
|
|
72
|
-
isRunning: this.activeRuns.has(agent.slug),
|
|
73
|
-
lastRunAt: this.lastRunAt.get(agent.slug),
|
|
74
|
-
sdk: this.sdk.scopeForAgent(agent)
|
|
75
|
-
});
|
|
76
|
-
return decision.kind === "ready" ? decision.invocation ?? null : null;
|
|
77
|
-
}
|
|
78
|
-
async recordRunTrace(trace) {
|
|
79
|
-
await this.sdk.recordRun({ run: trace });
|
|
80
|
-
}
|
|
81
|
-
buildTrace(agent, runId, trigger, overrides) {
|
|
82
|
-
return {
|
|
83
|
-
runId,
|
|
84
|
-
agentSlug: agent.slug,
|
|
85
|
-
handlerKind: agent.handler,
|
|
86
|
-
triggerKind: trigger.kind,
|
|
87
|
-
triggerSource: trigger.source,
|
|
88
|
-
claimedMessageId: trigger.message?.id ?? null,
|
|
89
|
-
selectedItemKey: null,
|
|
90
|
-
branchName: null,
|
|
91
|
-
commitSha: null,
|
|
92
|
-
changedPaths: [],
|
|
93
|
-
summary: null,
|
|
94
|
-
error: null,
|
|
95
|
-
errorCategory: null,
|
|
96
|
-
startedAt: nowIso(),
|
|
97
|
-
finishedAt: null,
|
|
98
|
-
status: "running",
|
|
99
|
-
...overrides
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
categorizeError(error) {
|
|
103
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
104
|
-
if (message.includes("not allowed")) {
|
|
105
|
-
return "permission_error";
|
|
106
|
-
}
|
|
107
|
-
if (message.includes("message")) {
|
|
108
|
-
return "message_claim_error";
|
|
109
|
-
}
|
|
110
|
-
if (message.includes("lease")) {
|
|
111
|
-
return "lease_error";
|
|
112
|
-
}
|
|
113
|
-
if (message.includes("commit") || message.includes("worktree") || message.includes("artifact")) {
|
|
114
|
-
return "mutation_error";
|
|
115
|
-
}
|
|
116
|
-
if (message.includes("Copilot") || message.includes("execution")) {
|
|
117
|
-
return "execution_error";
|
|
118
|
-
}
|
|
119
|
-
return "sdk_error";
|
|
120
|
-
}
|
|
121
|
-
async executeAgent(agent, trigger) {
|
|
122
|
-
if (this.activeRuns.has(agent.slug)) {
|
|
123
|
-
return {
|
|
124
|
-
status: "waiting",
|
|
125
|
-
summary: `Agent ${agent.slug} is already running.`
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
this.activeRuns.add(agent.slug);
|
|
129
|
-
const runId = crypto.randomUUID();
|
|
130
|
-
const handler = await resolveAgentHandler(agent.handler);
|
|
131
|
-
const scopedSdk = this.sdk.scopeForAgent(agent);
|
|
132
|
-
const context = {
|
|
133
|
-
runId,
|
|
134
|
-
repoRoot: this.repoRoot,
|
|
135
|
-
agent,
|
|
136
|
-
sdk: scopedSdk,
|
|
137
|
-
trigger,
|
|
138
|
-
execution: this.execution,
|
|
139
|
-
mutations: this.mutations,
|
|
140
|
-
repository: this.repository,
|
|
141
|
-
verification: this.verification,
|
|
142
|
-
notifications: this.notifications,
|
|
143
|
-
research: this.research
|
|
144
|
-
};
|
|
145
|
-
await this.recordRunTrace(this.buildTrace(agent, runId, trigger, {}));
|
|
146
|
-
try {
|
|
147
|
-
const inputs = await handler.resolveInputs(context);
|
|
148
|
-
const result = await handler.execute(context, inputs);
|
|
149
|
-
const output = await handler.emitOutputs(context, result);
|
|
150
|
-
if (trigger.message) {
|
|
151
|
-
await scopedSdk.ackMessage({
|
|
152
|
-
id: trigger.message.id,
|
|
153
|
-
status: output.status === "completed" ? "completed" : output.status === "waiting" ? "pending" : "failed"
|
|
154
|
-
});
|
|
155
|
-
}
|
|
156
|
-
await this.recordRunTrace(
|
|
157
|
-
this.buildTrace(agent, runId, trigger, {
|
|
158
|
-
status: output.status,
|
|
159
|
-
branchName: output.metadata?.branchName ?? null,
|
|
160
|
-
commitSha: output.metadata?.commitSha ?? null,
|
|
161
|
-
changedPaths: output.metadata?.changedPaths ?? [],
|
|
162
|
-
summary: output.summary,
|
|
163
|
-
error: output.status === "failed" ? output.stderr ?? output.summary : null,
|
|
164
|
-
errorCategory: output.status === "failed" ? output.errorCategory ?? "execution_error" : null,
|
|
165
|
-
finishedAt: nowIso()
|
|
166
|
-
})
|
|
167
|
-
);
|
|
168
|
-
await this.sdk.upsertCursor({
|
|
169
|
-
agentSlug: agent.slug,
|
|
170
|
-
cursorKey: "last_run_at",
|
|
171
|
-
cursorValue: nowIso()
|
|
172
|
-
});
|
|
173
|
-
if (trigger.kind === "follow") {
|
|
174
|
-
await this.sdk.upsertCursor({
|
|
175
|
-
agentSlug: agent.slug,
|
|
176
|
-
cursorKey: followCursorKey(trigger.followModels),
|
|
177
|
-
cursorValue: nowIso()
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
this.lastRunAt.set(agent.slug, Date.now());
|
|
181
|
-
return output;
|
|
182
|
-
} catch (error) {
|
|
183
|
-
if (trigger.message) {
|
|
184
|
-
await scopedSdk.ackMessage({
|
|
185
|
-
id: trigger.message.id,
|
|
186
|
-
status: "failed"
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
await this.recordRunTrace(
|
|
190
|
-
this.buildTrace(agent, runId, trigger, {
|
|
191
|
-
status: "failed",
|
|
192
|
-
error: error instanceof Error ? error.message : String(error),
|
|
193
|
-
errorCategory: this.categorizeError(error),
|
|
194
|
-
finishedAt: nowIso()
|
|
195
|
-
})
|
|
196
|
-
);
|
|
197
|
-
throw error;
|
|
198
|
-
} finally {
|
|
199
|
-
this.activeRuns.delete(agent.slug);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
async runAgent(slug, mode = "manual", invocation) {
|
|
203
|
-
const { specs, diagnostics } = await loadActiveAgentSpecs(this.sdk);
|
|
204
|
-
const errors = diagnostics.filter((entry) => entry.severity === "error");
|
|
205
|
-
if (errors.length) {
|
|
206
|
-
throw new Error(
|
|
207
|
-
`Agent spec validation failed: ${errors.map((entry) => `${entry.slug}:${entry.field}:${entry.message}`).join(" | ")}`
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
const agents = this.sortAgents(specs);
|
|
211
|
-
const agent = agents.find((entry) => entry.slug === slug);
|
|
212
|
-
if (!agent) {
|
|
213
|
-
throw new Error(`Unknown or disabled agent "${slug}".`);
|
|
214
|
-
}
|
|
215
|
-
const trigger = invocation ?? await this.resolveTrigger(agent, mode);
|
|
216
|
-
if (!trigger) {
|
|
217
|
-
return {
|
|
218
|
-
status: "waiting",
|
|
219
|
-
summary: `No runnable trigger found for ${slug}.`
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
return this.executeAgent(agent, trigger);
|
|
223
|
-
}
|
|
224
|
-
async runCycle() {
|
|
225
|
-
const { specs, diagnostics } = await loadActiveAgentSpecs(this.sdk);
|
|
226
|
-
const errors = diagnostics.filter((entry) => entry.severity === "error");
|
|
227
|
-
if (errors.length) {
|
|
228
|
-
throw new Error(
|
|
229
|
-
`Agent spec validation failed: ${errors.map((entry) => `${entry.slug}:${entry.field}:${entry.message}`).join(" | ")}`
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
const agents = this.sortAgents(specs);
|
|
233
|
-
const results = [];
|
|
234
|
-
for (const agent of agents) {
|
|
235
|
-
const runsThisCycle = agent.triggerPolicy?.maxRunsPerCycle ?? 1;
|
|
236
|
-
for (let index = 0; index < runsThisCycle; index += 1) {
|
|
237
|
-
const trigger = await this.resolveTrigger(agent, "auto");
|
|
238
|
-
if (!trigger) {
|
|
239
|
-
break;
|
|
240
|
-
}
|
|
241
|
-
results.push({
|
|
242
|
-
slug: agent.slug,
|
|
243
|
-
result: await this.executeAgent(agent, trigger)
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return results;
|
|
248
|
-
}
|
|
249
|
-
async start(intervalMs = Number(process.env.TREESEED_AGENT_SUPERVISOR_INTERVAL_MS ?? 6e4)) {
|
|
250
|
-
await this.runCycle();
|
|
251
|
-
setInterval(() => {
|
|
252
|
-
void this.runCycle();
|
|
253
|
-
}, intervalMs);
|
|
254
|
-
}
|
|
255
|
-
async drainMessages() {
|
|
256
|
-
const { specs, diagnostics } = await loadActiveAgentSpecs(this.sdk);
|
|
257
|
-
const errors = diagnostics.filter((entry) => entry.severity === "error");
|
|
258
|
-
if (errors.length) {
|
|
259
|
-
throw new Error(
|
|
260
|
-
`Agent spec validation failed: ${errors.map((entry) => `${entry.slug}:${entry.field}:${entry.message}`).join(" | ")}`
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
const agents = this.sortAgents(specs);
|
|
264
|
-
const messageAgents = agents.filter(
|
|
265
|
-
(agent) => agent.triggers.some((trigger) => trigger.type === "message")
|
|
266
|
-
);
|
|
267
|
-
const results = [];
|
|
268
|
-
for (const agent of messageAgents) {
|
|
269
|
-
results.push({
|
|
270
|
-
slug: agent.slug,
|
|
271
|
-
result: await this.runAgent(agent.slug, "auto")
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
return results;
|
|
275
|
-
}
|
|
276
|
-
releaseLeases() {
|
|
277
|
-
return this.sdk.releaseAllLeases();
|
|
278
|
-
}
|
|
279
|
-
async replayMessage(id) {
|
|
280
|
-
await this.sdk.ackMessage({
|
|
281
|
-
id,
|
|
282
|
-
status: "pending"
|
|
283
|
-
});
|
|
284
|
-
return {
|
|
285
|
-
id,
|
|
286
|
-
status: "pending"
|
|
287
|
-
};
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
export {
|
|
291
|
-
AgentKernel
|
|
292
|
-
};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { AgentRuntimeSpec, AgentTriggerConfig } from '@treeseed/sdk/types/agents';
|
|
2
|
-
import type { ScopedAgentSdk } from '@treeseed/sdk/sdk';
|
|
3
|
-
import type { AgentTriggerInvocation } from '../runtime-types.ts';
|
|
4
|
-
export type TriggerDecisionKind = 'ready' | 'skip' | 'blocked_by_cooldown' | 'blocked_by_concurrency' | 'no_message_available' | 'no_follow_activity' | 'no_trigger_available';
|
|
5
|
-
export interface TriggerDecision {
|
|
6
|
-
kind: TriggerDecisionKind;
|
|
7
|
-
invocation?: AgentTriggerInvocation;
|
|
8
|
-
reason?: string;
|
|
9
|
-
selectedTrigger?: AgentTriggerConfig;
|
|
10
|
-
}
|
|
11
|
-
export interface TriggerResolverInput {
|
|
12
|
-
agent: AgentRuntimeSpec;
|
|
13
|
-
mode?: 'auto' | 'manual';
|
|
14
|
-
isRunning: boolean;
|
|
15
|
-
lastRunAt?: number;
|
|
16
|
-
sdk: ScopedAgentSdk;
|
|
17
|
-
}
|
|
18
|
-
export declare function followCursorKey(models: string[] | undefined): string;
|
|
19
|
-
export declare function resolveTriggerDecision(input: TriggerResolverInput): Promise<TriggerDecision>;
|