@oh-my-dsh/auto-team 0.1.4 → 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.
- package/README.md +155 -129
- package/README.zh.md +110 -123
- package/cordis.patch.yml +1 -1
- package/lib/client.js +616 -0
- package/lib/index.d.ts +12 -78
- package/lib/index.js +322 -739
- package/package.json +58 -26
- package/src/assets/icon.svg +13 -9
- package/src/assets/locale/en.json +1 -1
- package/src/assets/locale/zh.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,787 +1,370 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const MIN_FACTOR = 1;
|
|
9
|
-
const MAX_FACTOR = 5;
|
|
10
|
-
const FACTOR_RANGE = 4;
|
|
11
|
-
/** Clamp one finite factor to 1..5 and normalize it to 0..1. */
|
|
12
|
-
function normalizeFactor(name, value) {
|
|
13
|
-
if (!Number.isFinite(value)) throw new TypeError(`difficulty factor "${name}" must be a finite number`);
|
|
14
|
-
return (Math.min(MAX_FACTOR, Math.max(MIN_FACTOR, value)) - MIN_FACTOR) / FACTOR_RANGE;
|
|
1
|
+
import Schema from "@deepseek-ai/schemastery";
|
|
2
|
+
import paths from "node:path";
|
|
3
|
+
//#region src/worktree-path.ts
|
|
4
|
+
function filePath(args) {
|
|
5
|
+
if (args === null || typeof args !== "object" || !("file_path" in args)) return;
|
|
6
|
+
const { file_path: path } = args;
|
|
7
|
+
if (typeof path === "string" && path.trim() !== "") return path;
|
|
15
8
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
total += value;
|
|
22
|
-
}
|
|
23
|
-
if (total <= 0) throw new TypeError("score weights must have a positive total");
|
|
24
|
-
}
|
|
25
|
-
/** Weighted 0..1 difficulty score. */
|
|
26
|
-
function scoreAssessment(assessment, weights) {
|
|
27
|
-
validateWeights(weights);
|
|
28
|
-
const total = weights.scope + weights.parallelism + weights.ambiguity + weights.risk + weights.expectedSteps;
|
|
29
|
-
return (normalizeFactor("scope", assessment.scope) * weights.scope + normalizeFactor("parallelism", assessment.parallelism) * weights.parallelism + normalizeFactor("ambiguity", assessment.ambiguity) * weights.ambiguity + normalizeFactor("risk", assessment.risk) * weights.risk + normalizeFactor("expectedSteps", assessment.expectedSteps) * weights.expectedSteps) / total;
|
|
9
|
+
function absoluteFilePath(args) {
|
|
10
|
+
const path = filePath(args);
|
|
11
|
+
if (path === void 0 || !paths.isAbsolute(path)) return;
|
|
12
|
+
if (process.platform === "win32" && paths.win32.parse(path).root.length <= 1) return;
|
|
13
|
+
return path;
|
|
30
14
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return
|
|
15
|
+
async function insideWorktree(fs, file, options) {
|
|
16
|
+
const { cwd, signal } = options;
|
|
17
|
+
const [root, marker, target] = await Promise.all([
|
|
18
|
+
fs.resolve(cwd, options),
|
|
19
|
+
fs.resolve(".git", options),
|
|
20
|
+
fs.resolve(file, options)
|
|
21
|
+
]);
|
|
22
|
+
if (paths.relative(cwd, fs.processPath(root)) !== "" || !fs.contains(root, target) || !fs.contains(root, marker) || fs.contains(marker, target)) return false;
|
|
23
|
+
const [directory, gitLink] = await Promise.all([fs.lstat(cwd, options, signal), fs.lstat(".git", options, signal)]);
|
|
24
|
+
return directory?.type === "directory" && gitLink?.type === "file" && !fs.contains(target, root);
|
|
41
25
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
26
|
+
function instructionPath(cwd, file) {
|
|
27
|
+
if (file === void 0) return;
|
|
28
|
+
const { root } = paths.parse(file);
|
|
29
|
+
if (process.platform === "win32" && root !== "" && (root.length <= 1 || !paths.isAbsolute(file))) return;
|
|
30
|
+
const target = paths.resolve(cwd, file);
|
|
31
|
+
const parts = paths.relative(cwd, target).split(paths.sep);
|
|
32
|
+
if (process.platform === "win32" && parts.some((part) => /[ .:]$|:/u.test(part))) return;
|
|
33
|
+
const [first, second] = parts.map((part) => {
|
|
34
|
+
if (process.platform === "win32") return part.toLowerCase();
|
|
35
|
+
return part;
|
|
36
|
+
});
|
|
37
|
+
if (parts.length === 1) {
|
|
38
|
+
const instructions = paths.join(cwd, "AGENTS.md");
|
|
39
|
+
if (paths.relative(instructions, target) === "") return target;
|
|
40
|
+
}
|
|
41
|
+
if (first === ".agents" && second !== void 0 && second !== "worktrees") return target;
|
|
46
42
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
manualGoal: options.manualGoal,
|
|
55
|
-
decision: decideTeam(score, threshold)
|
|
56
|
-
};
|
|
43
|
+
async function resolvesToInstruction(fs, { rawPath, candidate }, options) {
|
|
44
|
+
try {
|
|
45
|
+
const [root, target] = await Promise.all([fs.resolve(options.cwd, options), fs.resolve(rawPath, options)]);
|
|
46
|
+
return paths.relative(options.cwd, fs.processPath(root)) === "" && fs.contains(root, target) && paths.relative(candidate, fs.processPath(target)) === "";
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
57
50
|
}
|
|
58
51
|
//#endregion
|
|
59
|
-
//#region src/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
const Config = schema.object({
|
|
86
|
-
message: schema.string().default("auto-team loaded"),
|
|
87
|
-
threshold: schema.number().min(0).max(1).default(DEFAULT_THRESHOLD),
|
|
88
|
-
manualGoalFactor: schema.number().min(0).max(1).default(DEFAULT_MANUAL_GOAL_FACTOR),
|
|
89
|
-
weights: schema.object({
|
|
90
|
-
scope: schema.number().min(0).max(1).default(DEFAULT_WEIGHTS.scope),
|
|
91
|
-
parallelism: schema.number().min(0).max(1).default(DEFAULT_WEIGHTS.parallelism),
|
|
92
|
-
ambiguity: schema.number().min(0).max(1).default(DEFAULT_WEIGHTS.ambiguity),
|
|
93
|
-
risk: schema.number().min(0).max(1).default(DEFAULT_WEIGHTS.risk),
|
|
94
|
-
expectedSteps: schema.number().min(0).max(1).default(DEFAULT_WEIGHTS.expectedSteps)
|
|
95
|
-
}),
|
|
96
|
-
reportingAgentName: schema.string().pattern(REPORTER_NAME_PATTERN).default(DEFAULT_REPORTING_AGENT_NAME),
|
|
97
|
-
reportingProvider: schema.string().default(DEFAULT_REPORTING_PROVIDER),
|
|
98
|
-
goalMaxRounds: schema.natural().min(1).default(DEFAULT_GOAL_MAX_ROUNDS),
|
|
99
|
-
enforceLeadNoCode: schema.boolean().default(DEFAULT_ENFORCE_LEAD_NO_CODE),
|
|
100
|
-
leadDeniedTools: schema.array(schema.string()).default([...DEFAULT_LEAD_DENIED_TOOLS])
|
|
101
|
-
});
|
|
102
|
-
/** Validate one finite number against an inclusive range. */
|
|
103
|
-
function numberInRange(name, value, range) {
|
|
104
|
-
if (!Number.isFinite(value) || value < range.min || value > range.max) throw new TypeError(`${name} must be between ${range.min} and ${range.max}`);
|
|
105
|
-
return value;
|
|
52
|
+
//#region src/execution.ts
|
|
53
|
+
const leadDenied = "Auto Team: Lead coordinates, reviews, and integrates. Delegate implementation to local execution agents.";
|
|
54
|
+
const worktreeRequired = "Auto Team: use the official Worktree tool in this agent session to create and enter its own worktree before writing. If unavailable, stop writes and ask the Lead to check the profile or arrange a separate workspace.";
|
|
55
|
+
const pathDenied = "Auto Team: write or edit an absolute file_path inside this session’s verified worktree; do not write to the Git worktree marker.";
|
|
56
|
+
const instructionGuidance = "The current workspace’s root AGENTS.md and .agents/ guidance files are exempt from Auto Team’s write checks; .agents/worktrees/ is not. Native permissions still apply.";
|
|
57
|
+
const stateChanged = "Auto Team: the execution or worktree state changed before this write. Recheck the current team, goal, and worktree before retrying.";
|
|
58
|
+
function executionOf(ctx, agent) {
|
|
59
|
+
if (agent === void 0) return;
|
|
60
|
+
try {
|
|
61
|
+
const root = ctx.subagents.rootOf(agent);
|
|
62
|
+
if (!ctx.agentTeams.isEnabled(root)) return;
|
|
63
|
+
const goal = ctx.goals.get(root);
|
|
64
|
+
if (goal?.phase !== "active" || goal.activation !== "armed") return;
|
|
65
|
+
if (root === agent) return {
|
|
66
|
+
root,
|
|
67
|
+
goal,
|
|
68
|
+
role: "lead"
|
|
69
|
+
};
|
|
70
|
+
return {
|
|
71
|
+
root,
|
|
72
|
+
goal,
|
|
73
|
+
role: "worker"
|
|
74
|
+
};
|
|
75
|
+
} catch {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
106
78
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
expectedSteps: config.weights?.expectedSteps ?? DEFAULT_WEIGHTS.expectedSteps
|
|
115
|
-
};
|
|
116
|
-
validateWeights(weights);
|
|
117
|
-
return weights;
|
|
79
|
+
function worktreeOf(ctx, { session }) {
|
|
80
|
+
try {
|
|
81
|
+
const cwd = ctx.workingDirectory.get(session);
|
|
82
|
+
const { worktree = [] } = ctx.sessionProjections.snapshot(session, ["worktree"]).values;
|
|
83
|
+
const matches = worktree.filter((entry) => entry.owned && entry.worktree.path === cwd);
|
|
84
|
+
if (matches.length === 1) return matches[0]?.worktree;
|
|
85
|
+
} catch {}
|
|
118
86
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
123
|
-
return
|
|
87
|
+
function worktreeGuidance(ctx, agent) {
|
|
88
|
+
if (worktreeOf(ctx, agent) !== void 0) return "Use your current owned worktree.";
|
|
89
|
+
if (ctx.tools.get("create_worktree", agent) !== void 0) return "Use create_worktree in your own session with a unique branch name and the agreed local base commit.";
|
|
90
|
+
if (ctx.tools.get("enter_worktree", agent) !== void 0) return "Use enter_worktree in your own session with a unique name and an explicit local from commit; do not enter an existing checkout.";
|
|
91
|
+
return "The official worktree tool is unavailable. Stop before writing implementation files and tell the Lead.";
|
|
124
92
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
93
|
+
function guidance(ctx, agent, restrictWrites) {
|
|
94
|
+
const execution = executionOf(ctx, agent);
|
|
95
|
+
if (execution === void 0 || agent === void 0) return "";
|
|
96
|
+
const condition = "Auto Team applies only while the root session has native Agent Teams enabled and a live, active goal.";
|
|
97
|
+
if (!restrictWrites(execution.root)) {
|
|
98
|
+
const nativeOnly = "Auto Team write restrictions are off; native permissions still apply.";
|
|
99
|
+
if (execution.role === "lead") return `${condition} Coordinate independent tasks, review results, and integrate only as authorized. ${nativeOnly}`;
|
|
100
|
+
return `Coordinate changes with the Lead, avoid overwriting other agents’ work, and report results through native team communication. ${nativeOnly}`;
|
|
101
|
+
}
|
|
102
|
+
if (execution.role === "lead") return `${condition} As Lead, assign independent tasks to local execution agents with separate worktrees, a base commit, and acceptance criteria. Coordinate, review their diffs and tests, and integrate only as authorized; do not implement changes yourself or bypass write restrictions with other tools. Do not force parallelism for inseparable work. ${instructionGuidance}`;
|
|
103
|
+
return [
|
|
104
|
+
condition,
|
|
105
|
+
worktreeGuidance(ctx, agent),
|
|
106
|
+
instructionGuidance,
|
|
107
|
+
"Implement and verify only in your own worktree, using absolute file paths; do not bypass write restrictions with shell or other tools. Report the branch, changes, test results, and unresolved issues to the Lead using native team communication."
|
|
108
|
+
].join(" ");
|
|
130
109
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return {
|
|
134
|
-
threshold: numberInRange("threshold", config.threshold ?? DEFAULT_THRESHOLD, UNIT_RANGE),
|
|
135
|
-
manualGoalFactor: numberInRange("manualGoalFactor", config.manualGoalFactor ?? DEFAULT_MANUAL_GOAL_FACTOR, UNIT_RANGE)
|
|
136
|
-
};
|
|
110
|
+
function isProtected(name) {
|
|
111
|
+
return name === "write" || name === "edit";
|
|
137
112
|
}
|
|
138
|
-
|
|
139
|
-
function resolveConfig(config = {}) {
|
|
113
|
+
function deny(reason) {
|
|
140
114
|
return {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
enforceLeadNoCode: config.enforceLeadNoCode ?? DEFAULT_ENFORCE_LEAD_NO_CODE,
|
|
148
|
-
leadDeniedTools: [...config.leadDeniedTools ?? DEFAULT_LEAD_DENIED_TOOLS]
|
|
115
|
+
isError: true,
|
|
116
|
+
content: [{
|
|
117
|
+
type: "text",
|
|
118
|
+
text: reason
|
|
119
|
+
}],
|
|
120
|
+
error: { message: reason }
|
|
149
121
|
};
|
|
150
122
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
score: z.number().min(0).max(1),
|
|
157
|
-
threshold: z.number().min(0).max(1),
|
|
158
|
-
manualGoal: z.boolean(),
|
|
159
|
-
decision: z.enum(["team", "solo"]),
|
|
160
|
-
goal: z.enum([
|
|
161
|
-
"started",
|
|
162
|
-
"reused",
|
|
163
|
-
"none"
|
|
164
|
-
])
|
|
165
|
-
});
|
|
166
|
-
const autoTeamProjectionStateSchema = z.object({
|
|
167
|
-
score: scoreRecordSchema.optional(),
|
|
168
|
-
failure: z.string().optional()
|
|
169
|
-
});
|
|
170
|
-
/** Fold the first score after the latest reset into one durable decision. */
|
|
171
|
-
function applyAutoTeamProjection(state, event) {
|
|
172
|
-
const record = pluginRecordOf(event);
|
|
173
|
-
if (record === void 0) return state;
|
|
174
|
-
if (record.type === RESET_RECORD_TYPE) {
|
|
175
|
-
if (state.score === void 0) return state;
|
|
176
|
-
return {
|
|
177
|
-
...state,
|
|
178
|
-
score: void 0
|
|
179
|
-
};
|
|
123
|
+
function currentDirectory(ctx, agent) {
|
|
124
|
+
try {
|
|
125
|
+
return ctx.workingDirectory.get(agent.session);
|
|
126
|
+
} catch {
|
|
127
|
+
return;
|
|
180
128
|
}
|
|
181
|
-
if (record.type !== SCORE_RECORD_TYPE) return state;
|
|
182
|
-
if (state.score !== void 0) return state;
|
|
183
|
-
const parsed = scoreRecordSchema.safeParse(record.data);
|
|
184
|
-
if (!parsed.success) return {
|
|
185
|
-
...state,
|
|
186
|
-
failure: parsed.error.message
|
|
187
|
-
};
|
|
188
|
-
return {
|
|
189
|
-
...state,
|
|
190
|
-
score: parsed.data
|
|
191
|
-
};
|
|
192
129
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
//#endregion
|
|
202
|
-
//#region src/prompt.ts
|
|
203
|
-
/**
|
|
204
|
-
* Model-facing policy and teammate prompts for auto-team.
|
|
205
|
-
*
|
|
206
|
-
* @module @oh-my-dsh/auto-team/prompt
|
|
207
|
-
*/
|
|
208
|
-
/** Steering text used whenever no score is recorded, including after a reset. */
|
|
209
|
-
const NO_SCORE_STEER_TEXT = `Auto Team: no score is recorded. Call auto_team_score now with the current task's difficulty factors and objective; the turn stays open until the decision is recorded.`;
|
|
210
|
-
/** System prompt section that states the Lead's auto-team obligations. */
|
|
211
|
-
function policyText(reportingAgentName, leadDeniedTools) {
|
|
212
|
-
return `Auto Team policy
|
|
213
|
-
|
|
214
|
-
You are the Team Lead for a long task. Call auto_team_score before anything else in the first round. The call takes:
|
|
215
|
-
- scope, parallelism, ambiguity, risk, expected_steps: integers from 1 (low) to 5 (high)
|
|
216
|
-
- objective: the task goal in its ordinary, universal meaning
|
|
217
|
-
|
|
218
|
-
The first turn stays open until the tool records a decision. The result carries the team or solo decision and the goal and reporter status. The numeric score and threshold stay host-side; treat them as unavailable and act on the returned decision.
|
|
219
|
-
|
|
220
|
-
If the decision is solo, continue as a normal single agent.
|
|
221
|
-
|
|
222
|
-
If the decision is team:
|
|
223
|
-
- Your role is the Main Git repository and the team. Code changes belong to execution agents. The Lead's ${leadDeniedTools.join(", ")} calls are denied in Team mode. Treat that gate as a policy check: use pwsh, run_code, and other tools for review, tests, and inspection only.
|
|
224
|
-
- The plugin starts or reuses the goal and ensures a reporting agent named "${reportingAgentName}".
|
|
225
|
-
- The reporter writes directly to the user on its own cadence. Monitor the team on your own schedule, and keep execution moving while details are resolved.
|
|
226
|
-
- Create shared tasks with disjoint write scopes, then spawn execution agents. Each execution agent creates its own worktree for its task before editing; the Lead works in the main checkout.
|
|
227
|
-
- Let the goal runtime drive multi-round continuation; follow its rounds.
|
|
228
|
-
- After the workers finish, review the final diff and run the tests in the main checkout.`;
|
|
130
|
+
function writeDenial(ctx, { name, agent, arguments: args }, restrictWrites) {
|
|
131
|
+
if (!isProtected(name) || agent === void 0) return;
|
|
132
|
+
const cwd = currentDirectory(ctx, agent);
|
|
133
|
+
if (cwd !== void 0 && instructionPath(cwd, filePath(args)) !== void 0) return;
|
|
134
|
+
const execution = executionOf(ctx, agent);
|
|
135
|
+
if (execution === void 0 || !restrictWrites(execution.root)) return;
|
|
136
|
+
if (execution.role === "lead") return leadDenied;
|
|
137
|
+
if (worktreeOf(ctx, agent) === void 0) return worktreeRequired;
|
|
229
138
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
139
|
+
async function verifiedInstructionDirectory(ctx, { agent, arguments: args }, signal) {
|
|
140
|
+
const cwd = currentDirectory(ctx, agent);
|
|
141
|
+
const rawPath = filePath(args);
|
|
142
|
+
if (cwd === void 0 || rawPath === void 0) return;
|
|
143
|
+
const candidate = instructionPath(cwd, rawPath);
|
|
144
|
+
if (candidate !== void 0 && await resolvesToInstruction(ctx.fs, {
|
|
145
|
+
rawPath,
|
|
146
|
+
candidate
|
|
147
|
+
}, {
|
|
148
|
+
cwd,
|
|
149
|
+
signal
|
|
150
|
+
})) return cwd;
|
|
151
|
+
}
|
|
152
|
+
function sameExecution(previous, current) {
|
|
153
|
+
return current?.root === previous.root && current.goal.id === previous.goal.id && current.goal.revision === previous.goal.revision;
|
|
154
|
+
}
|
|
155
|
+
function sameWorktree(previous, current) {
|
|
156
|
+
return current?.path === previous.path && current.branch === previous.branch && current.baseCommit === previous.baseCommit;
|
|
240
157
|
}
|
|
241
|
-
//#endregion
|
|
242
|
-
//#region src/tool.ts
|
|
243
158
|
/**
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
* @module @oh-my-dsh/auto-team/tool
|
|
159
|
+
* Share one live execution decision between prompt assembly and the native tool
|
|
160
|
+
* pipeline.
|
|
248
161
|
*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
4,
|
|
287
|
-
5
|
|
288
|
-
],
|
|
289
|
-
description: "How much requirements or design uncertainty remains, from 1 low to 5 high."
|
|
290
|
-
},
|
|
291
|
-
risk: {
|
|
292
|
-
type: "integer",
|
|
293
|
-
required: true,
|
|
294
|
-
enum: [
|
|
295
|
-
1,
|
|
296
|
-
2,
|
|
297
|
-
3,
|
|
298
|
-
4,
|
|
299
|
-
5
|
|
300
|
-
],
|
|
301
|
-
description: "How costly a wrong change would be, from 1 low to 5 high."
|
|
302
|
-
},
|
|
303
|
-
expected_steps: {
|
|
304
|
-
type: "integer",
|
|
305
|
-
required: true,
|
|
306
|
-
enum: [
|
|
307
|
-
1,
|
|
308
|
-
2,
|
|
309
|
-
3,
|
|
310
|
-
4,
|
|
311
|
-
5
|
|
312
|
-
],
|
|
313
|
-
description: "Expected length of the task, from 1 short to 5 long."
|
|
314
|
-
},
|
|
315
|
-
objective: {
|
|
316
|
-
type: "string",
|
|
317
|
-
required: true,
|
|
318
|
-
description: "The task goal in its ordinary, universal meaning. Used only when auto-team starts a goal."
|
|
319
|
-
}
|
|
320
|
-
},
|
|
321
|
-
output: {
|
|
322
|
-
schema: {
|
|
323
|
-
type: "object",
|
|
324
|
-
additionalProperties: false,
|
|
325
|
-
properties: {
|
|
326
|
-
decision: {
|
|
327
|
-
type: "string",
|
|
328
|
-
required: true,
|
|
329
|
-
enum: ["team", "solo"]
|
|
330
|
-
},
|
|
331
|
-
goal: {
|
|
332
|
-
type: "string",
|
|
333
|
-
required: true,
|
|
334
|
-
enum: [
|
|
335
|
-
"started",
|
|
336
|
-
"reused",
|
|
337
|
-
"none"
|
|
338
|
-
]
|
|
339
|
-
},
|
|
340
|
-
reporter: { type: "string" }
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
render: (_args, value) => [{
|
|
344
|
-
type: "text",
|
|
345
|
-
text: JSON.stringify(value)
|
|
346
|
-
}]
|
|
347
|
-
},
|
|
348
|
-
async execute(args, exec) {
|
|
349
|
-
const { agent } = exec;
|
|
350
|
-
if (agent === void 0) throw new Error("auto_team_score requires a calling Agent");
|
|
351
|
-
const result = await autoTeam.score(agent, {
|
|
352
|
-
assessment: {
|
|
353
|
-
scope: args.scope,
|
|
354
|
-
parallelism: args.parallelism,
|
|
355
|
-
ambiguity: args.ambiguity,
|
|
356
|
-
risk: args.risk,
|
|
357
|
-
expectedSteps: args.expected_steps
|
|
358
|
-
},
|
|
359
|
-
objective: args.objective,
|
|
360
|
-
signal: exec.signal
|
|
162
|
+
function installExecution(ctx, restrictWrites) {
|
|
163
|
+
const lifetime = new AbortController();
|
|
164
|
+
ctx.effect(() => () => {
|
|
165
|
+
lifetime.abort();
|
|
166
|
+
});
|
|
167
|
+
ctx.effect(() => ctx.systemPrompt.section({
|
|
168
|
+
name: "auto-team:execution",
|
|
169
|
+
order: ctx.systemPrompt.getSectionOrder("TEAM_POLICY"),
|
|
170
|
+
text: ({ agent }) => guidance(ctx, agent, restrictWrites)
|
|
171
|
+
}));
|
|
172
|
+
ctx.effect(() => ctx.tools.guard((exec) => writeDenial(ctx, exec, restrictWrites)));
|
|
173
|
+
ctx.on("tools/execute", async (exec, next) => {
|
|
174
|
+
const { agent, name, signal } = exec;
|
|
175
|
+
if (!isProtected(name) || agent === void 0 || signal.aborted) return next();
|
|
176
|
+
const execution = executionOf(ctx, agent);
|
|
177
|
+
if (execution === void 0 || !restrictWrites(execution.root)) return next();
|
|
178
|
+
const checkSignal = AbortSignal.any([signal, lifetime.signal]);
|
|
179
|
+
const worktree = worktreeOf(ctx, agent);
|
|
180
|
+
const instructionCwd = await verifiedInstructionDirectory(ctx, {
|
|
181
|
+
agent,
|
|
182
|
+
arguments: exec.arguments
|
|
183
|
+
}, checkSignal);
|
|
184
|
+
if (signal.aborted) return next();
|
|
185
|
+
if (lifetime.signal.aborted) return deny(stateChanged);
|
|
186
|
+
if (instructionCwd !== void 0) {
|
|
187
|
+
if (currentDirectory(ctx, agent) !== instructionCwd) return deny(stateChanged);
|
|
188
|
+
return next();
|
|
189
|
+
}
|
|
190
|
+
if (execution.role === "lead") return deny(leadDenied);
|
|
191
|
+
if (worktree === void 0) return deny(worktreeRequired);
|
|
192
|
+
const file = absoluteFilePath(exec.arguments);
|
|
193
|
+
if (file === void 0) return deny(pathDenied);
|
|
194
|
+
let inside = false;
|
|
195
|
+
try {
|
|
196
|
+
inside = await insideWorktree(ctx.fs, file, {
|
|
197
|
+
cwd: worktree.path,
|
|
198
|
+
signal: checkSignal
|
|
361
199
|
});
|
|
362
|
-
|
|
363
|
-
|
|
200
|
+
} catch {
|
|
201
|
+
inside = false;
|
|
364
202
|
}
|
|
203
|
+
if (signal.aborted) return next();
|
|
204
|
+
if (lifetime.signal.aborted) return deny(stateChanged);
|
|
205
|
+
const current = executionOf(ctx, agent);
|
|
206
|
+
const currentTree = worktreeOf(ctx, agent);
|
|
207
|
+
if (!sameExecution(execution, current) || !restrictWrites(execution.root) || !sameWorktree(worktree, currentTree)) return deny(stateChanged);
|
|
208
|
+
if (!inside) return deny(pathDenied);
|
|
209
|
+
return next();
|
|
365
210
|
});
|
|
366
211
|
}
|
|
367
|
-
function registerScoreTool(tools, autoTeam) {
|
|
368
|
-
const holder = { dispose: () => void 0 };
|
|
369
|
-
const dispose = () => {
|
|
370
|
-
holder.dispose();
|
|
371
|
-
};
|
|
372
|
-
holder.dispose = tools.register(scoreTool(autoTeam, dispose));
|
|
373
|
-
return holder.dispose;
|
|
374
|
-
}
|
|
375
|
-
//#endregion
|
|
376
|
-
//#region src/reset-command.ts
|
|
377
|
-
/** Build the user-facing score reset command. */
|
|
378
|
-
function createResetCommand(autoTeam) {
|
|
379
|
-
return {
|
|
380
|
-
name: "auto-team-reset",
|
|
381
|
-
description: "Clear the frozen Auto Team score for this session.",
|
|
382
|
-
handler: (invocation) => {
|
|
383
|
-
if (autoTeam.decisionOf(invocation.agent) === void 0) return {
|
|
384
|
-
kind: "error",
|
|
385
|
-
text: "No frozen Auto Team score exists in this session."
|
|
386
|
-
};
|
|
387
|
-
autoTeam.reset(invocation.agent);
|
|
388
|
-
registerScoreTool(invocation.agent.ctx.tools, autoTeam);
|
|
389
|
-
const message = invocation.rawInput.trim();
|
|
390
|
-
if (message.length > 0) invocation.agent.steer(createMessage({
|
|
391
|
-
role: "user",
|
|
392
|
-
content: [{
|
|
393
|
-
type: "text",
|
|
394
|
-
text: message
|
|
395
|
-
}],
|
|
396
|
-
source: { kind: "user" }
|
|
397
|
-
}));
|
|
398
|
-
return { kind: "success" };
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
}
|
|
402
|
-
/** Structural guard for the optional host commands service. */
|
|
403
|
-
function isCommandRuntime(value) {
|
|
404
|
-
if (typeof value !== "object" || value === null || !("register" in value)) return false;
|
|
405
|
-
return typeof value.register === "function";
|
|
406
|
-
}
|
|
407
212
|
//#endregion
|
|
408
|
-
//#region src/
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
this.deps = deps;
|
|
417
|
-
this.config = config;
|
|
418
|
-
}
|
|
419
|
-
/** Whether this agent already has a frozen score. */
|
|
420
|
-
hasScore(agent) {
|
|
421
|
-
return !this.resets.has(agent) && this.records.has(agent);
|
|
422
|
-
}
|
|
423
|
-
/** Seed a record restored from durable storage without scoring again. */
|
|
424
|
-
restore(agent, record) {
|
|
425
|
-
if (!this.resets.has(agent) && !this.records.has(agent)) this.records.set(agent, record);
|
|
426
|
-
}
|
|
427
|
-
/** The frozen team decision, when this agent has one. */
|
|
428
|
-
decisionOf(agent) {
|
|
429
|
-
if (this.resets.has(agent)) return;
|
|
430
|
-
return (this.records.get(agent) ?? this.deps.store.read(agent))?.decision;
|
|
431
|
-
}
|
|
432
|
-
/** Clear the frozen score after a user-triggered reset. */
|
|
433
|
-
reset(agent) {
|
|
434
|
-
this.deps.store.reset(agent);
|
|
435
|
-
this.records.delete(agent);
|
|
436
|
-
this.resets.add(agent);
|
|
437
|
-
}
|
|
438
|
-
/**
|
|
439
|
-
* Score one task, freeze the decision, then start or reuse its goal and
|
|
440
|
-
* ensure the reporting teammate.
|
|
441
|
-
*/
|
|
442
|
-
async score(agent, request) {
|
|
443
|
-
let existing = this.records.get(agent) ?? this.deps.store.read(agent);
|
|
444
|
-
if (this.resets.has(agent)) existing = void 0;
|
|
445
|
-
if (existing !== void 0) {
|
|
446
|
-
this.records.set(agent, existing);
|
|
447
|
-
return await this.finish(agent, existing, request.signal);
|
|
448
|
-
}
|
|
449
|
-
const currentGoal = this.deps.goals.get(agent);
|
|
450
|
-
let existingGoal = currentGoal;
|
|
451
|
-
if (currentGoal?.phase === "complete") existingGoal = void 0;
|
|
452
|
-
const manualGoal = existingGoal !== void 0;
|
|
453
|
-
const decision = createScoreDecision(request.assessment, {
|
|
454
|
-
weights: this.config.weights,
|
|
455
|
-
threshold: this.config.threshold,
|
|
456
|
-
manualGoal,
|
|
457
|
-
manualGoalFactor: this.config.manualGoalFactor
|
|
458
|
-
});
|
|
459
|
-
let goal = "none";
|
|
460
|
-
if (decision.decision === "team" && existingGoal === void 0) goal = this.startGoal(agent, request.objective);
|
|
461
|
-
else if (existingGoal !== void 0) goal = "reused";
|
|
462
|
-
const record = {
|
|
463
|
-
score: decision.score,
|
|
464
|
-
threshold: decision.threshold,
|
|
465
|
-
manualGoal,
|
|
466
|
-
decision: decision.decision,
|
|
467
|
-
goal
|
|
468
|
-
};
|
|
469
|
-
this.deps.store.write(agent, record);
|
|
470
|
-
this.records.set(agent, record);
|
|
471
|
-
this.resets.delete(agent);
|
|
472
|
-
return await this.finish(agent, record, request.signal);
|
|
473
|
-
}
|
|
474
|
-
/** Create the auto-started goal and return the reported action. */
|
|
475
|
-
startGoal(agent, objective) {
|
|
476
|
-
const trimmed = objective.trim();
|
|
477
|
-
if (trimmed.length === 0) throw new TypeError("objective is required when auto-team starts a goal");
|
|
478
|
-
this.deps.goals.create(agent, {
|
|
479
|
-
objective: trimmed,
|
|
480
|
-
maxGoalRounds: this.config.goalMaxRounds
|
|
481
|
-
});
|
|
482
|
-
return "started";
|
|
483
|
-
}
|
|
484
|
-
/** Add the reporter result to a frozen record, provisioning it when needed. */
|
|
485
|
-
async finish(agent, record, signal) {
|
|
486
|
-
if (record.decision === "solo") return {
|
|
487
|
-
decision: "solo",
|
|
488
|
-
goal: record.goal
|
|
489
|
-
};
|
|
490
|
-
const reporter = await this.ensureReporter(agent, signal);
|
|
491
|
-
return {
|
|
492
|
-
decision: "team",
|
|
493
|
-
goal: record.goal,
|
|
494
|
-
reporter
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
/** Reuse an existing reporting teammate or spawn one. */
|
|
498
|
-
async ensureReporter(agent, signal) {
|
|
499
|
-
const name = this.config.reportingAgentName;
|
|
500
|
-
const existing = this.deps.team.listMembers(agent).find((member) => member.name === name);
|
|
501
|
-
if (existing !== void 0) return existing.name;
|
|
502
|
-
return (await this.deps.team.spawnReporter(agent, {
|
|
503
|
-
name,
|
|
504
|
-
description: "User-facing status reporter for the auto team",
|
|
505
|
-
prompt: reporterPrompt(),
|
|
506
|
-
provider: this.config.reportingProvider,
|
|
507
|
-
signal
|
|
508
|
-
})).name;
|
|
509
|
-
}
|
|
213
|
+
//#region src/parallelism.ts
|
|
214
|
+
const minParallelism = 0;
|
|
215
|
+
const maxParallelism = 8;
|
|
216
|
+
const defaults = {
|
|
217
|
+
enabled: false,
|
|
218
|
+
restrictWrites: true,
|
|
219
|
+
lower: minParallelism,
|
|
220
|
+
upper: maxParallelism
|
|
510
221
|
};
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
return service;
|
|
518
|
-
}
|
|
519
|
-
/** Read the Team service or fail with a plugin-specific message. */
|
|
520
|
-
function teamService(ctx) {
|
|
521
|
-
const service = ctx.get("agentTeams");
|
|
522
|
-
if (service === void 0) throw new Error("auto-team: agentTeams service is unavailable");
|
|
523
|
-
return service;
|
|
524
|
-
}
|
|
525
|
-
/** Build the goal, team, and durable score ports from Cordis services. */
|
|
526
|
-
function createAutoTeam(ctx, config) {
|
|
527
|
-
return new AutoTeam({
|
|
528
|
-
goals: {
|
|
529
|
-
get: (agent) => goalService(ctx).get(agent),
|
|
530
|
-
create: (agent, request) => goalService(ctx).create(agent, request)
|
|
531
|
-
},
|
|
532
|
-
team: {
|
|
533
|
-
listMembers: (agent) => teamService(ctx).listMembers(agent),
|
|
534
|
-
spawnReporter: async (agent, request) => {
|
|
535
|
-
return { name: (await teamService(ctx).spawnTeammate(agent, {
|
|
536
|
-
name: request.name,
|
|
537
|
-
description: request.description,
|
|
538
|
-
prompt: [{
|
|
539
|
-
type: "text",
|
|
540
|
-
text: request.prompt
|
|
541
|
-
}],
|
|
542
|
-
context: "fresh",
|
|
543
|
-
provider: request.provider,
|
|
544
|
-
signal: request.signal
|
|
545
|
-
})).member.name };
|
|
546
|
-
}
|
|
547
|
-
},
|
|
548
|
-
store: {
|
|
549
|
-
read: (agent) => ctx.get("sessionProjections")?.stateOf(agent.session, "autoTeam")?.score,
|
|
550
|
-
write: (agent, record) => {
|
|
551
|
-
appendPluginRecord(agent.session, "plugin:auto-team/score", record);
|
|
552
|
-
},
|
|
553
|
-
reset: (agent) => {
|
|
554
|
-
appendPluginRecord(agent.session, "plugin:auto-team/reset", { at: Date.now() });
|
|
555
|
-
}
|
|
556
|
-
}
|
|
557
|
-
}, config);
|
|
222
|
+
function rootOf(ctx, agent) {
|
|
223
|
+
try {
|
|
224
|
+
return ctx.subagents.rootOf(agent);
|
|
225
|
+
} catch {
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
558
228
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
* returns its path, edits must stay inside it.
|
|
564
|
-
*
|
|
565
|
-
* @module @oh-my-dsh/auto-team/worker-guard
|
|
566
|
-
*/
|
|
567
|
-
/** Read a write or edit file path from its tool arguments. */
|
|
568
|
-
function filePathOf(args) {
|
|
569
|
-
if (typeof args !== "object" || args === null || !("file_path" in args)) return;
|
|
570
|
-
const filePath = args.file_path;
|
|
571
|
-
if (typeof filePath === "string") return filePath;
|
|
229
|
+
function runningIn(ctx, root) {
|
|
230
|
+
let running = 0;
|
|
231
|
+
for (const member of ctx.agents.list()) if (member !== root && member.status === "running" && rootOf(ctx, member) === root) running += 1;
|
|
232
|
+
return running;
|
|
572
233
|
}
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
234
|
+
function leadHint(ctx, root, settings) {
|
|
235
|
+
if (!settings.enabled || rootOf(ctx, root) !== root || !ctx.agentTeams.isEnabled(root)) return "";
|
|
236
|
+
const goal = ctx.goals.get(root);
|
|
237
|
+
if (goal?.phase !== "active" || goal.activation !== "armed") return "";
|
|
238
|
+
const running = runningIn(ctx, root);
|
|
239
|
+
if (running < settings.lower) return [
|
|
240
|
+
`Auto Team parallelism: ${running} running local subagents, below the lower bound ${settings.lower}.`,
|
|
241
|
+
"If independent work can be split safely, consider delegating it to additional local subagents",
|
|
242
|
+
"through the native team workflow, within host limits and approvals. Do not force parallelism."
|
|
243
|
+
].join(" ");
|
|
244
|
+
if (running > settings.upper) return [
|
|
245
|
+
`Auto Team parallelism: ${running} running local subagents, above the upper bound ${settings.upper}.`,
|
|
246
|
+
"Let active work continue; do not stop, rush, or archive active tasks.",
|
|
247
|
+
"Review only already completed worktrees and branches for safe cleanup. First verify that no processes use them",
|
|
248
|
+
"and that no uncommitted, untracked, ignored, or unintegrated work would be lost. Retain anything uncertain",
|
|
249
|
+
"and require user authorization and native approvals before any destructive change."
|
|
250
|
+
].join(" ");
|
|
251
|
+
return "";
|
|
578
252
|
}
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
const relative = path.relative(path.resolve(root), path.resolve(target));
|
|
582
|
-
return relative === "" || !relative.startsWith("..") && !path.isAbsolute(relative);
|
|
253
|
+
function isRecord(value) {
|
|
254
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
583
255
|
}
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
let hasWorktree = false;
|
|
587
|
-
let worktreePath = void 0;
|
|
588
|
-
const disposers = [];
|
|
589
|
-
const register = (dispose) => {
|
|
590
|
-
disposers.push(dispose);
|
|
591
|
-
};
|
|
592
|
-
try {
|
|
593
|
-
const pre = agent.ctx.on("tools/pre-execute", async (exec, next) => {
|
|
594
|
-
if (exec.agent === agent && autoTeam.decisionOf(root) === "team" && (exec.name === "write" || exec.name === "edit")) {
|
|
595
|
-
if (!hasWorktree) return {
|
|
596
|
-
kind: "deny",
|
|
597
|
-
reason: "auto-team: create your own worktree with create_worktree before editing files"
|
|
598
|
-
};
|
|
599
|
-
if (worktreePath !== void 0) {
|
|
600
|
-
const filePath = filePathOf(exec.arguments);
|
|
601
|
-
if (filePath === void 0) return {
|
|
602
|
-
kind: "deny",
|
|
603
|
-
reason: "auto-team: write and edit require a file_path so the worktree guard can verify it"
|
|
604
|
-
};
|
|
605
|
-
if (!path.isAbsolute(filePath)) return {
|
|
606
|
-
kind: "deny",
|
|
607
|
-
reason: "auto-team: use an absolute file path inside your registered worktree"
|
|
608
|
-
};
|
|
609
|
-
if (!isInside(worktreePath, filePath)) return {
|
|
610
|
-
kind: "deny",
|
|
611
|
-
reason: `auto-team: edit path is outside your worktree: ${worktreePath}`
|
|
612
|
-
};
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
return await next();
|
|
616
|
-
});
|
|
617
|
-
register(() => {
|
|
618
|
-
pre();
|
|
619
|
-
});
|
|
620
|
-
const post = agent.ctx.on("tools/post-execute", async (exec, result, next) => {
|
|
621
|
-
if (exec.agent === agent && exec.name === "create_worktree" && !result.isError) {
|
|
622
|
-
hasWorktree = true;
|
|
623
|
-
const registered = worktreePathOf(result.value);
|
|
624
|
-
if (registered !== void 0) worktreePath = registered;
|
|
625
|
-
}
|
|
626
|
-
return await next();
|
|
627
|
-
});
|
|
628
|
-
register(() => {
|
|
629
|
-
post();
|
|
630
|
-
});
|
|
631
|
-
} catch (error) {
|
|
632
|
-
for (const dispose of disposers.toReversed()) dispose();
|
|
633
|
-
throw error;
|
|
634
|
-
}
|
|
635
|
-
return () => {
|
|
636
|
-
for (const dispose of disposers.toReversed()) dispose();
|
|
637
|
-
};
|
|
256
|
+
function isBound(value) {
|
|
257
|
+
return typeof value === "number" && Number.isInteger(value) && value >= minParallelism && value <= maxParallelism;
|
|
638
258
|
}
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
function createPluginRuntime(ctx) {
|
|
259
|
+
function settingsPatch(payload, current) {
|
|
260
|
+
const { enabled = current.enabled, restrictWrites = current.restrictWrites, lower = current.lower, upper = current.upper } = payload;
|
|
261
|
+
if (typeof enabled !== "boolean" || typeof restrictWrites !== "boolean" || !isBound(lower) || !isBound(upper) || lower > upper) return;
|
|
643
262
|
return {
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
ctx.logger.warn(message);
|
|
649
|
-
}
|
|
263
|
+
enabled,
|
|
264
|
+
restrictWrites,
|
|
265
|
+
lower,
|
|
266
|
+
upper
|
|
650
267
|
};
|
|
651
268
|
}
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
disposers.push(dispose);
|
|
660
|
-
};
|
|
661
|
-
try {
|
|
662
|
-
register(systemPrompt.section({
|
|
663
|
-
name: "auto-team:policy",
|
|
664
|
-
order: systemPrompt.getSectionOrder("TEAM_POLICY"),
|
|
665
|
-
text: policyText(config.reportingAgentName, config.leadDeniedTools)
|
|
666
|
-
}));
|
|
667
|
-
if (!autoTeam.hasScore(agent)) register(registerScoreTool(tools, autoTeam));
|
|
668
|
-
const stop = agent.ctx.on("agent/turn-stopping", () => {
|
|
669
|
-
if (autoTeam.hasScore(agent)) return;
|
|
670
|
-
agent.steer(createMessage({
|
|
671
|
-
role: "user",
|
|
672
|
-
content: [{
|
|
673
|
-
type: "text",
|
|
674
|
-
text: NO_SCORE_STEER_TEXT
|
|
675
|
-
}],
|
|
676
|
-
source: { kind: "user" }
|
|
677
|
-
}));
|
|
678
|
-
});
|
|
679
|
-
register(() => {
|
|
680
|
-
stop();
|
|
681
|
-
});
|
|
682
|
-
if (config.enforceLeadNoCode) {
|
|
683
|
-
const guard = agent.ctx.on("tools/pre-execute", async (exec, next) => {
|
|
684
|
-
if (exec.agent !== agent || autoTeam.decisionOf(agent) !== "team" || !config.leadDeniedTools.includes(exec.name)) return await next();
|
|
685
|
-
return {
|
|
686
|
-
kind: "deny",
|
|
687
|
-
reason: "auto-team: the Lead must delegate code changes to an execution agent"
|
|
688
|
-
};
|
|
689
|
-
});
|
|
690
|
-
register(() => {
|
|
691
|
-
guard();
|
|
692
|
-
});
|
|
269
|
+
function failure(code, message) {
|
|
270
|
+
return {
|
|
271
|
+
ok: false,
|
|
272
|
+
error: {
|
|
273
|
+
code,
|
|
274
|
+
message,
|
|
275
|
+
details: {}
|
|
693
276
|
}
|
|
694
|
-
} catch (error) {
|
|
695
|
-
for (const dispose of disposers.toReversed()) dispose();
|
|
696
|
-
throw error;
|
|
697
|
-
}
|
|
698
|
-
return () => {
|
|
699
|
-
for (const dispose of disposers.toReversed()) dispose();
|
|
700
277
|
};
|
|
701
278
|
}
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
projectionRegistered = true;
|
|
722
|
-
};
|
|
723
|
-
ensureProjection();
|
|
724
|
-
const ensureResetCommand = () => {
|
|
725
|
-
if (resetCommandRegistered) return;
|
|
726
|
-
const commands = ctx.get("commands");
|
|
727
|
-
if (!isCommandRuntime(commands)) return;
|
|
728
|
-
ctx.effect(() => commands.register(createResetCommand(autoTeam)), "auto-team.reset-command()");
|
|
729
|
-
resetCommandRegistered = true;
|
|
730
|
-
};
|
|
731
|
-
ensureResetCommand();
|
|
732
|
-
const install = (agent) => {
|
|
733
|
-
if (installed.has(agent)) return;
|
|
734
|
-
ensureProjection();
|
|
735
|
-
if (!servicesReady(ctx)) {
|
|
736
|
-
if (!warned) {
|
|
737
|
-
runtime.warn("auto-team: host services are unavailable; waiting for agent and goal services");
|
|
738
|
-
warned = true;
|
|
739
|
-
}
|
|
740
|
-
return;
|
|
279
|
+
const getEndpoint = "auto-team/parallelism/get";
|
|
280
|
+
const updateEndpoint = "auto-team/parallelism/update";
|
|
281
|
+
const getFields = /* @__PURE__ */ new Set(["sessionId"]);
|
|
282
|
+
const updateFields = /* @__PURE__ */ new Set([
|
|
283
|
+
"sessionId",
|
|
284
|
+
"enabled",
|
|
285
|
+
"restrictWrites",
|
|
286
|
+
"lower",
|
|
287
|
+
"upper"
|
|
288
|
+
]);
|
|
289
|
+
/** Register the root-only advisory and the optional native browser RPC channel. */
|
|
290
|
+
function installParallelism(ctx) {
|
|
291
|
+
const settings = /* @__PURE__ */ new WeakMap();
|
|
292
|
+
ctx.effect(() => ctx.systemPrompt.section({
|
|
293
|
+
name: "auto-team:parallelism",
|
|
294
|
+
order: ctx.systemPrompt.getSectionOrder("TEAM_POLICY"),
|
|
295
|
+
text: ({ agent }) => {
|
|
296
|
+
if (agent === void 0) return "";
|
|
297
|
+
return leadHint(ctx, agent, settings.get(agent.session) ?? defaults);
|
|
741
298
|
}
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
if (
|
|
745
|
-
|
|
746
|
-
|
|
299
|
+
}));
|
|
300
|
+
const dispatch = (endpoint, payload, signal) => {
|
|
301
|
+
if (signal.aborted) return failure("gateway/cancelled", "Parallelism request cancelled.");
|
|
302
|
+
const update = endpoint === updateEndpoint;
|
|
303
|
+
if (!update && endpoint !== getEndpoint) return failure("gateway/not-found", "Unknown parallelism operation.");
|
|
304
|
+
let fields = getFields;
|
|
305
|
+
if (update) fields = updateFields;
|
|
306
|
+
if (!isRecord(payload) || typeof payload.sessionId !== "string" || payload.sessionId === "" || Object.keys(payload).some((key) => !fields.has(key))) return failure("gateway/bad-request", "Expected an explicit session ID and valid parallelism fields.");
|
|
307
|
+
const root = ctx.agents.list().find((agent) => agent.id === payload.sessionId);
|
|
308
|
+
if (root === void 0 || rootOf(ctx, root) !== root) return failure("auto-team/session-unavailable", "The requested session is not a live local root.");
|
|
309
|
+
let next = settings.get(root.session) ?? defaults;
|
|
310
|
+
const running = runningIn(ctx, root);
|
|
311
|
+
if (update) {
|
|
312
|
+
const patch = settingsPatch(payload, next);
|
|
313
|
+
if (patch === void 0) return failure("gateway/bad-request", "Expected boolean switches and ordered integer bounds from 0 to 8.");
|
|
314
|
+
settings.set(root.session, patch);
|
|
315
|
+
next = patch;
|
|
747
316
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
}
|
|
317
|
+
return {
|
|
318
|
+
ok: true,
|
|
319
|
+
value: {
|
|
320
|
+
...next,
|
|
321
|
+
running
|
|
322
|
+
}
|
|
323
|
+
};
|
|
755
324
|
};
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
325
|
+
ctx.inject(["connection"], (web) => {
|
|
326
|
+
for (const endpoint of [getEndpoint, updateEndpoint]) web.connection.fetch.register({
|
|
327
|
+
path: `/api/${endpoint}`,
|
|
328
|
+
methods: ["POST"],
|
|
329
|
+
requestBody: "buffered",
|
|
330
|
+
async fetch(request) {
|
|
331
|
+
const body = await request.json().catch(() => false);
|
|
332
|
+
if (!isRecord(body) || body.type !== "client-request" || body.method !== endpoint || typeof body.rpcId !== "string") return new Response("Invalid request", { status: 400 });
|
|
333
|
+
const result = dispatch(endpoint, body.payload, request.signal);
|
|
334
|
+
return Response.json({
|
|
335
|
+
type: "server-response",
|
|
336
|
+
rpcId: body.rpcId,
|
|
337
|
+
result
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
});
|
|
769
341
|
});
|
|
770
|
-
|
|
771
|
-
for (const dispose of installed.values()) dispose();
|
|
772
|
-
installed.clear();
|
|
773
|
-
}, "auto-team.install()");
|
|
342
|
+
return (root) => (settings.get(root.session) ?? defaults).restrictWrites;
|
|
774
343
|
}
|
|
775
344
|
//#endregion
|
|
776
345
|
//#region src/index.ts
|
|
346
|
+
/** Existing Cordis row identity. */
|
|
347
|
+
const name = "auto-team";
|
|
348
|
+
/** Services supplied by the native DSH profile, never started by this plugin. */
|
|
349
|
+
const inject = [
|
|
350
|
+
"agentTeams",
|
|
351
|
+
"agents",
|
|
352
|
+
"goals",
|
|
353
|
+
"subagents",
|
|
354
|
+
"systemPrompt",
|
|
355
|
+
"tools",
|
|
356
|
+
"sessionProjections",
|
|
357
|
+
"workingDirectory",
|
|
358
|
+
"fs"
|
|
359
|
+
];
|
|
360
|
+
const Config = Schema.object({ message: Schema.string().default("auto-team loaded") });
|
|
777
361
|
/**
|
|
778
|
-
*
|
|
779
|
-
*
|
|
780
|
-
* @module @oh-my-dsh/auto-team
|
|
362
|
+
* Install fiber-owned execution rules without changing native team or goal
|
|
363
|
+
* state.
|
|
781
364
|
*/
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
365
|
+
function apply(ctx, config) {
|
|
366
|
+
installExecution(ctx, installParallelism(ctx));
|
|
367
|
+
ctx.logger.info(config.message);
|
|
368
|
+
}
|
|
786
369
|
//#endregion
|
|
787
370
|
export { Config, apply, inject, name };
|