@geminixiang/mikan 1.0.0-beta.51 → 1.0.0-beta.53
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/CHANGELOG.md +24 -0
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +9 -1
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/slack/update-diagnostics.d.ts +14 -0
- package/dist/adapters/slack/update-diagnostics.d.ts.map +1 -0
- package/dist/adapters/slack/update-diagnostics.js +150 -0
- package/dist/adapters/slack/update-diagnostics.js.map +1 -0
- package/dist/harness/subagent-profiles.d.ts.map +1 -1
- package/dist/harness/subagent-profiles.js +0 -19
- package/dist/harness/subagent-profiles.js.map +1 -1
- package/dist/harness/subagent-runner.d.ts.map +1 -1
- package/dist/harness/subagent-runner.js +2 -41
- package/dist/harness/subagent-runner.js.map +1 -1
- package/dist/harness/types.d.ts +0 -3
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/harness/types.js.map +1 -1
- package/dist/main.js +8 -4
- package/dist/main.js.map +1 -1
- package/dist/observability/sentry.d.ts +16 -2
- package/dist/observability/sentry.d.ts.map +1 -1
- package/dist/observability/sentry.js +95 -1
- package/dist/observability/sentry.js.map +1 -1
- package/dist/observability/types.d.ts +17 -1
- package/dist/observability/types.d.ts.map +1 -1
- package/dist/observability/types.js.map +1 -1
- package/dist/platform-messages.d.ts +1 -0
- package/dist/platform-messages.d.ts.map +1 -1
- package/dist/platform-messages.js +3 -0
- package/dist/platform-messages.js.map +1 -1
- package/dist/process-lifecycle.d.ts.map +1 -1
- package/dist/process-lifecycle.js +8 -1
- package/dist/process-lifecycle.js.map +1 -1
- package/dist/runtime/conversation-runtime.d.ts.map +1 -1
- package/dist/runtime/conversation-runtime.js +21 -9
- package/dist/runtime/conversation-runtime.js.map +1 -1
- package/dist/runtime/session-lifecycle.d.ts.map +1 -1
- package/dist/runtime/session-lifecycle.js +3 -1
- package/dist/runtime/session-lifecycle.js.map +1 -1
- package/dist/runtime/types.d.ts +2 -0
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/runtime/types.js.map +1 -1
- package/dist/tools/subagent.d.ts.map +1 -1
- package/dist/tools/subagent.js +34 -3
- package/dist/tools/subagent.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { KnownBlock } from "@slack/types";
|
|
2
|
+
/** Best-effort telemetry: must not mask an API error or fail a successful update. */
|
|
3
|
+
export declare function recordSlackUpdate(owner: object, target: {
|
|
4
|
+
channel: string;
|
|
5
|
+
ts: string;
|
|
6
|
+
}, source: string, payload: {
|
|
7
|
+
text: string;
|
|
8
|
+
blocks: KnownBlock[];
|
|
9
|
+
}, outcome: {
|
|
10
|
+
error: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
success: true;
|
|
13
|
+
}): void;
|
|
14
|
+
//# sourceMappingURL=update-diagnostics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-diagnostics.d.ts","sourceRoot":"","sources":["../../../src/adapters/slack/update-diagnostics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAqG/C,qFAAqF;AACrF,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,EACvC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAA;CAAE,EAC/C,OAAO,EAAE;IAAE,KAAK,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,GAC9C,IAAI,CAmDN"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import * as Sentry from "@sentry/node";
|
|
2
|
+
// Diagnostic correlation only: eviction never changes transport behavior.
|
|
3
|
+
const pending = new WeakMap();
|
|
4
|
+
const MAX_PENDING = 128;
|
|
5
|
+
const RETENTION_MS = 10 * 60_000;
|
|
6
|
+
const ERROR_CODES = new Set([
|
|
7
|
+
"block_mismatch",
|
|
8
|
+
"invalid_blocks",
|
|
9
|
+
"msg_too_long",
|
|
10
|
+
"ratelimited",
|
|
11
|
+
"rate_limited",
|
|
12
|
+
]);
|
|
13
|
+
const BLOCK_TYPES = new Set([
|
|
14
|
+
"markdown",
|
|
15
|
+
"table",
|
|
16
|
+
"section",
|
|
17
|
+
"context",
|
|
18
|
+
"divider",
|
|
19
|
+
"actions",
|
|
20
|
+
"rich_text",
|
|
21
|
+
]);
|
|
22
|
+
function record(value) {
|
|
23
|
+
return value !== null && typeof value === "object" ? value : {};
|
|
24
|
+
}
|
|
25
|
+
function syntax(source) {
|
|
26
|
+
const trimmed = source.trimStart();
|
|
27
|
+
const fences = source.split("\n").filter((line) => /^\s*(`{3,}|~{3,})/.test(line));
|
|
28
|
+
return {
|
|
29
|
+
leadingConstruct: /^(?:`{3,}|~{3,})/.test(trimmed)
|
|
30
|
+
? "fence"
|
|
31
|
+
: trimmed.startsWith("|")
|
|
32
|
+
? "table_like"
|
|
33
|
+
: /^#{1,6}(?:\s|$)/.test(trimmed)
|
|
34
|
+
? "heading"
|
|
35
|
+
: /^[*_-]/.test(trimmed)
|
|
36
|
+
? "list_or_emphasis"
|
|
37
|
+
: /^[[<]/.test(trimmed)
|
|
38
|
+
? "link_like"
|
|
39
|
+
: "other",
|
|
40
|
+
fenceLineCount: fences.length,
|
|
41
|
+
fenceWithWorkingSuffix: fences.some((line) => /^\s*(?:`{3,}|~{3,}) +\.\.\.\s*$/.test(line)),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function shape(source, payload) {
|
|
45
|
+
return {
|
|
46
|
+
sourceLength: source.length,
|
|
47
|
+
fallbackLength: payload.text.length,
|
|
48
|
+
blockCount: payload.blocks.length,
|
|
49
|
+
...syntax(source),
|
|
50
|
+
// Flat arrays survive the existing Sentry depth limit. No text or identifiers.
|
|
51
|
+
blockTypes: payload.blocks
|
|
52
|
+
.slice(0, 50)
|
|
53
|
+
.map((block) => (BLOCK_TYPES.has(block.type) ? block.type : "other")),
|
|
54
|
+
markdownLengths: payload.blocks
|
|
55
|
+
.filter((block) => block.type === "markdown")
|
|
56
|
+
.slice(0, 50)
|
|
57
|
+
.map((block) => block.text.length),
|
|
58
|
+
tableRows: payload.blocks
|
|
59
|
+
.filter((block) => block.type === "table")
|
|
60
|
+
.slice(0, 50)
|
|
61
|
+
.map((block) => block.rows.length),
|
|
62
|
+
tableMaxColumns: payload.blocks
|
|
63
|
+
.filter((block) => block.type === "table")
|
|
64
|
+
.slice(0, 50)
|
|
65
|
+
.map((block) => Math.max(0, ...block.rows.map((row) => row.length))),
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
function validation(error) {
|
|
69
|
+
const data = record(record(error).data);
|
|
70
|
+
const messages = record(data.response_metadata).messages;
|
|
71
|
+
const details = Array.isArray(messages)
|
|
72
|
+
? messages.slice(0, 10).filter((item) => typeof item === "string")
|
|
73
|
+
: [];
|
|
74
|
+
return {
|
|
75
|
+
errorCode: typeof data.error === "string" && ERROR_CODES.has(data.error) ? data.error : "other",
|
|
76
|
+
validationCount: Array.isArray(messages) ? messages.length : 0,
|
|
77
|
+
// Never copy a free-form Slack validation message: it can quote user content.
|
|
78
|
+
validationCategories: details.map((message) => /must be less than|maximum|too long/i.test(message)
|
|
79
|
+
? "limit"
|
|
80
|
+
: /missing|required/i.test(message)
|
|
81
|
+
? "required"
|
|
82
|
+
: /invalid|unsupported|not allowed/i.test(message)
|
|
83
|
+
? "invalid"
|
|
84
|
+
: "other"),
|
|
85
|
+
blockIndices: details
|
|
86
|
+
.flatMap((message) => [...message.matchAll(/\/blocks\/(\d{1,3})(?=\/|\]|\s|$)/g)]
|
|
87
|
+
.slice(0, 10)
|
|
88
|
+
.map((match) => Number(match[1])))
|
|
89
|
+
.slice(0, 10),
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/** Best-effort telemetry: must not mask an API error or fail a successful update. */
|
|
93
|
+
export function recordSlackUpdate(owner, target, source, payload, outcome) {
|
|
94
|
+
try {
|
|
95
|
+
const { channel, ts } = target;
|
|
96
|
+
const now = Date.now();
|
|
97
|
+
let failures = pending.get(owner);
|
|
98
|
+
if (failures)
|
|
99
|
+
for (const [key, value] of failures) {
|
|
100
|
+
if (now - value.at >= RETENTION_MS)
|
|
101
|
+
failures.delete(key);
|
|
102
|
+
}
|
|
103
|
+
const key = `${channel}:${ts}`;
|
|
104
|
+
const previous = failures?.get(key);
|
|
105
|
+
if ("success" in outcome && !previous)
|
|
106
|
+
return;
|
|
107
|
+
const attempts = (previous?.attempts ?? 0) + ("error" in outcome ? 1 : 0);
|
|
108
|
+
if ("error" in outcome) {
|
|
109
|
+
if (!failures) {
|
|
110
|
+
failures = new Map();
|
|
111
|
+
pending.set(owner, failures);
|
|
112
|
+
}
|
|
113
|
+
failures.delete(key);
|
|
114
|
+
failures.set(key, { at: now, attempts });
|
|
115
|
+
if (failures.size > MAX_PENDING)
|
|
116
|
+
failures.delete(failures.keys().next().value);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
failures?.delete(key);
|
|
120
|
+
}
|
|
121
|
+
if ("success" in outcome) {
|
|
122
|
+
// Successful runs may emit no later error event to retain breadcrumbs.
|
|
123
|
+
Sentry.logger.info("Slack update recovered", {
|
|
124
|
+
channelId: channel,
|
|
125
|
+
responseMessageId: ts,
|
|
126
|
+
failedAttempts: attempts,
|
|
127
|
+
sourceLength: source.length,
|
|
128
|
+
blockCount: payload.blocks.length,
|
|
129
|
+
...syntax(source),
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
Sentry.addBreadcrumb({
|
|
133
|
+
category: "slack.update",
|
|
134
|
+
level: "error" in outcome ? "warning" : "info",
|
|
135
|
+
message: "error" in outcome ? "Slack update rejected" : "Slack update recovered",
|
|
136
|
+
data: {
|
|
137
|
+
operation: "chat.update",
|
|
138
|
+
channelId: channel,
|
|
139
|
+
responseMessageId: ts,
|
|
140
|
+
failedAttempts: attempts,
|
|
141
|
+
...shape(source, payload),
|
|
142
|
+
...("error" in outcome ? validation(outcome.error) : {}),
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
catch {
|
|
147
|
+
// Observability must never change delivery or retry semantics.
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=update-diagnostics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"update-diagnostics.js","sourceRoot":"","sources":["../../../src/adapters/slack/update-diagnostics.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,cAAc,CAAC;AAGvC,0EAA0E;AAC1E,MAAM,OAAO,GAAG,IAAI,OAAO,EAAyD,CAAC;AACrF,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,YAAY,GAAG,EAAE,GAAG,MAAM,CAAC;AACjC,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,gBAAgB;IAChB,gBAAgB;IAChB,cAAc;IACd,aAAa;IACb,cAAc;CACf,CAAC,CAAC;AACH,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,UAAU;IACV,OAAO;IACP,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,WAAW;CACZ,CAAC,CAAC;AAEH,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAE,KAAiC,CAAC,CAAC,CAAC,EAAE,CAAC;AAC/F,CAAC;AAED,SAAS,MAAM,CAAC,MAAc;IAC5B,MAAM,OAAO,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IACnC,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI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GAAG,CAAC,CAAC;QACxB,CAAC;QACD,IAAI,SAAS,IAAI,OAAO,EAAE,CAAC;YACzB,uEAAuE;YACvE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,wBAAwB,EAAE;gBAC3C,SAAS,EAAE,OAAO;gBAClB,iBAAiB,EAAE,EAAE;gBACrB,cAAc,EAAE,QAAQ;gBACxB,YAAY,EAAE,MAAM,CAAC,MAAM;gBAC3B,UAAU,EAAE,OAAO,CAAC,MAAM,CAAC,MAAM;gBACjC,GAAG,MAAM,CAAC,MAAM,CAAC;aAClB,CAAC,CAAC;QACL,CAAC;QACD,MAAM,CAAC,aAAa,CAAC;YACnB,QAAQ,EAAE,cAAc;YACxB,KAAK,EAAE,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM;YAC9C,OAAO,EAAE,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC,CAAC,wBAAwB;YAChF,IAAI,EAAE;gBACJ,SAAS,EAAE,aAAa;gBACxB,SAAS,EAAE,OAAO;gBAClB,iBAAiB,EAAE,EAAE;gBACrB,cAAc,EAAE,QAAQ;gBACxB,GAAG,KAAK,CAAC,MAAM,EAAE,OAAO,CAAC;gBACzB,GAAG,CAAC,OAAO,IAAI,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;aACzD;SACF,CAAC,CAAC;IACL,CAAC;IAAC,MAAM,CAAC;QACP,+DAA+D;IACjE,CAAC;AACH,CAAC","sourcesContent":["import * as Sentry from \"@sentry/node\";\nimport type { KnownBlock } from \"@slack/types\";\n\n// Diagnostic correlation only: eviction never changes transport behavior.\nconst pending = new WeakMap<object, Map<string, { at: number; attempts: number }>>();\nconst MAX_PENDING = 128;\nconst RETENTION_MS = 10 * 60_000;\nconst ERROR_CODES = new Set([\n \"block_mismatch\",\n \"invalid_blocks\",\n \"msg_too_long\",\n \"ratelimited\",\n \"rate_limited\",\n]);\nconst BLOCK_TYPES = new Set([\n \"markdown\",\n \"table\",\n \"section\",\n \"context\",\n \"divider\",\n \"actions\",\n \"rich_text\",\n]);\n\nfunction record(value: unknown): Record<string, unknown> {\n return value !== null && typeof value === \"object\" ? (value as Record<string, unknown>) : {};\n}\n\nfunction syntax(source: string) {\n const trimmed = source.trimStart();\n const fences = source.split(\"\\n\").filter((line) => /^\\s*(`{3,}|~{3,})/.test(line));\n return {\n leadingConstruct: /^(?:`{3,}|~{3,})/.test(trimmed)\n ? \"fence\"\n : trimmed.startsWith(\"|\")\n ? \"table_like\"\n : /^#{1,6}(?:\\s|$)/.test(trimmed)\n ? \"heading\"\n : /^[*_-]/.test(trimmed)\n ? \"list_or_emphasis\"\n : /^[[<]/.test(trimmed)\n ? \"link_like\"\n : \"other\",\n fenceLineCount: fences.length,\n fenceWithWorkingSuffix: fences.some((line) => /^\\s*(?:`{3,}|~{3,}) +\\.\\.\\.\\s*$/.test(line)),\n };\n}\n\nfunction shape(source: string, payload: { text: string; blocks: KnownBlock[] }) {\n return {\n sourceLength: source.length,\n fallbackLength: payload.text.length,\n blockCount: payload.blocks.length,\n ...syntax(source),\n // Flat arrays survive the existing Sentry depth limit. No text or identifiers.\n blockTypes: payload.blocks\n .slice(0, 50)\n .map((block) => (BLOCK_TYPES.has(block.type) ? block.type : \"other\")),\n markdownLengths: payload.blocks\n .filter((block) => block.type === \"markdown\")\n .slice(0, 50)\n .map((block) => block.text.length),\n tableRows: payload.blocks\n .filter((block) => block.type === \"table\")\n .slice(0, 50)\n .map((block) => block.rows.length),\n tableMaxColumns: payload.blocks\n .filter((block) => block.type === \"table\")\n .slice(0, 50)\n .map((block) => Math.max(0, ...block.rows.map((row) => row.length))),\n };\n}\n\nfunction validation(error: unknown) {\n const data = record(record(error).data);\n const messages = record(data.response_metadata).messages;\n const details = Array.isArray(messages)\n ? messages.slice(0, 10).filter((item): item is string => typeof item === \"string\")\n : [];\n return {\n errorCode: typeof data.error === \"string\" && ERROR_CODES.has(data.error) ? data.error : \"other\",\n validationCount: Array.isArray(messages) ? messages.length : 0,\n // Never copy a free-form Slack validation message: it can quote user content.\n validationCategories: details.map((message) =>\n /must be less than|maximum|too long/i.test(message)\n ? \"limit\"\n : /missing|required/i.test(message)\n ? \"required\"\n : /invalid|unsupported|not allowed/i.test(message)\n ? \"invalid\"\n : \"other\",\n ),\n blockIndices: details\n .flatMap((message) =>\n [...message.matchAll(/\\/blocks\\/(\\d{1,3})(?=\\/|\\]|\\s|$)/g)]\n .slice(0, 10)\n .map((match) => Number(match[1])),\n )\n .slice(0, 10),\n };\n}\n\n/** Best-effort telemetry: must not mask an API error or fail a successful update. */\nexport function recordSlackUpdate(\n owner: object,\n target: { channel: string; ts: string },\n source: string,\n payload: { text: string; blocks: KnownBlock[] },\n outcome: { error: unknown } | { success: true },\n): void {\n try {\n const { channel, ts } = target;\n const now = Date.now();\n let failures = pending.get(owner);\n if (failures)\n for (const [key, value] of failures) {\n if (now - value.at >= RETENTION_MS) failures.delete(key);\n }\n const key = `${channel}:${ts}`;\n const previous = failures?.get(key);\n if (\"success\" in outcome && !previous) return;\n const attempts = (previous?.attempts ?? 0) + (\"error\" in outcome ? 1 : 0);\n if (\"error\" in outcome) {\n if (!failures) {\n failures = new Map();\n pending.set(owner, failures);\n }\n failures.delete(key);\n failures.set(key, { at: now, attempts });\n if (failures.size > MAX_PENDING) failures.delete(failures.keys().next().value!);\n } else {\n failures?.delete(key);\n }\n if (\"success\" in outcome) {\n // Successful runs may emit no later error event to retain breadcrumbs.\n Sentry.logger.info(\"Slack update recovered\", {\n channelId: channel,\n responseMessageId: ts,\n failedAttempts: attempts,\n sourceLength: source.length,\n blockCount: payload.blocks.length,\n ...syntax(source),\n });\n }\n Sentry.addBreadcrumb({\n category: \"slack.update\",\n level: \"error\" in outcome ? \"warning\" : \"info\",\n message: \"error\" in outcome ? \"Slack update rejected\" : \"Slack update recovered\",\n data: {\n operation: \"chat.update\",\n channelId: channel,\n responseMessageId: ts,\n failedAttempts: attempts,\n ...shape(source, payload),\n ...(\"error\" in outcome ? validation(outcome.error) : {}),\n },\n });\n } catch {\n // Observability must never change delivery or retry semantics.\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent-profiles.d.ts","sourceRoot":"","sources":["../../src/harness/subagent-profiles.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,0BAA0B,EAI3B,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"subagent-profiles.d.ts","sourceRoot":"","sources":["../../src/harness/subagent-profiles.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EACV,0BAA0B,EAI3B,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AA8PxF;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,MAAM,GAAG,0BAA0B,CAiCrF"}
|
|
@@ -20,10 +20,6 @@
|
|
|
20
20
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
21
21
|
import { basename, join } from "node:path";
|
|
22
22
|
import { parseFrontmatter } from "./skills.js";
|
|
23
|
-
// Built-ins carry no requiredTools. The check is a per-task evidence demand
|
|
24
|
-
// ("prove you actually inspected X") that only the caller can judge; as a
|
|
25
|
-
// profile default it fails every task that legitimately needs a subset of the
|
|
26
|
-
// granted tools, discarding a finished answer after the budget is spent.
|
|
27
23
|
const BUILTIN_PROFILES = [
|
|
28
24
|
{
|
|
29
25
|
name: "worker",
|
|
@@ -36,7 +32,6 @@ const BUILTIN_PROFILES = [
|
|
|
36
32
|
"Keep verbose discovery and command output in this isolated run. Return the completed result, files or artifacts changed, verification performed, and any unresolved blocker.",
|
|
37
33
|
].join("\n"),
|
|
38
34
|
tools: ["read", "bash", "edit", "write"],
|
|
39
|
-
requiredTools: [],
|
|
40
35
|
thinkingLevel: "high",
|
|
41
36
|
maxTurns: 30,
|
|
42
37
|
maxTokens: 100_000,
|
|
@@ -52,7 +47,6 @@ const BUILTIN_PROFILES = [
|
|
|
52
47
|
"Keep source discovery, build logs, browser traces, and repetitive diagnostics in this isolated run. Return the implemented or diagnosed outcome, decisive technical evidence, changed artifact paths when applicable, verification results, and remaining engineering risk.",
|
|
53
48
|
].join("\n"),
|
|
54
49
|
tools: ["read", "bash", "edit", "write"],
|
|
55
|
-
requiredTools: [],
|
|
56
50
|
thinkingLevel: "high",
|
|
57
51
|
maxTurns: 35,
|
|
58
52
|
maxTokens: 100_000,
|
|
@@ -68,7 +62,6 @@ const BUILTIN_PROFILES = [
|
|
|
68
62
|
"Keep verbose CLI, API, and job logs in this isolated run. Return the resulting state, affected resources or job identifiers, verification performed, and concrete follow-up or rollback information.",
|
|
69
63
|
].join("\n"),
|
|
70
64
|
tools: ["read", "bash", "edit", "write", "event", "sandbox"],
|
|
71
|
-
requiredTools: [],
|
|
72
65
|
thinkingLevel: "high",
|
|
73
66
|
maxTurns: 40,
|
|
74
67
|
maxTokens: 100_000,
|
|
@@ -84,7 +77,6 @@ const BUILTIN_PROFILES = [
|
|
|
84
77
|
"Keep verbose rows and query output in this isolated run. Return the conclusion, key figures with units and scope, methodology and checks, and limitations that affect confidence.",
|
|
85
78
|
].join("\n"),
|
|
86
79
|
tools: ["read", "bash", "write"],
|
|
87
|
-
requiredTools: [],
|
|
88
80
|
thinkingLevel: "high",
|
|
89
81
|
maxTurns: 35,
|
|
90
82
|
maxTokens: 100_000,
|
|
@@ -100,7 +92,6 @@ const BUILTIN_PROFILES = [
|
|
|
100
92
|
"Keep verbose records and operational output in this isolated run. Return the customer-facing outcome, account or artifact identifiers, decisions and blockers, and the next owner and action where follow-through remains.",
|
|
101
93
|
].join("\n"),
|
|
102
94
|
tools: ["read", "bash", "write", "event"],
|
|
103
|
-
requiredTools: [],
|
|
104
95
|
thinkingLevel: "high",
|
|
105
96
|
maxTurns: 30,
|
|
106
97
|
maxTokens: 100_000,
|
|
@@ -116,7 +107,6 @@ const BUILTIN_PROFILES = [
|
|
|
116
107
|
"Keep raw pages, candidate lists, and repetitive validation output in this isolated run. Return qualified opportunities, supporting evidence, confidence and disqualifiers, and a concise recommended next action.",
|
|
117
108
|
].join("\n"),
|
|
118
109
|
tools: ["read", "bash", "write"],
|
|
119
|
-
requiredTools: [],
|
|
120
110
|
thinkingLevel: "high",
|
|
121
111
|
maxTurns: 30,
|
|
122
112
|
maxTokens: 100_000,
|
|
@@ -132,7 +122,6 @@ const BUILTIN_PROFILES = [
|
|
|
132
122
|
"Keep generation logs, intermediate assets, and provider polling in this isolated run. Return deliverable paths or external identifiers, a concise production summary, verification results, and unresolved creative, quality, or rights constraints.",
|
|
133
123
|
].join("\n"),
|
|
134
124
|
tools: ["read", "bash", "write"],
|
|
135
|
-
requiredTools: [],
|
|
136
125
|
thinkingLevel: "high",
|
|
137
126
|
maxTurns: 40,
|
|
138
127
|
maxTokens: 100_000,
|
|
@@ -148,7 +137,6 @@ const BUILTIN_PROFILES = [
|
|
|
148
137
|
"Keep browser traces, HAR data, report rows, and repetitive diagnostics in this isolated run. Return the operational conclusion, decisive delivery evidence, affected inventory, remediation or escalation owner, and uncertainty that could change the diagnosis.",
|
|
149
138
|
].join("\n"),
|
|
150
139
|
tools: ["read", "bash", "write"],
|
|
151
|
-
requiredTools: [],
|
|
152
140
|
thinkingLevel: "high",
|
|
153
141
|
maxTurns: 35,
|
|
154
142
|
maxTokens: 100_000,
|
|
@@ -162,7 +150,6 @@ const BUILTIN_PROFILES = [
|
|
|
162
150
|
"Do not claim to have inspected files, executed commands, accessed URLs, or verified external state. Clearly distinguish dependency-provided facts from your own analysis. If the supplied evidence is insufficient, state the limitation instead of inventing details.",
|
|
163
151
|
].join("\n"),
|
|
164
152
|
tools: [],
|
|
165
|
-
requiredTools: [],
|
|
166
153
|
thinkingLevel: "high",
|
|
167
154
|
maxTurns: 20,
|
|
168
155
|
maxTokens: 100_000,
|
|
@@ -231,7 +218,6 @@ function parseProfilePatch(filePath, base) {
|
|
|
231
218
|
const patch = {};
|
|
232
219
|
applyField(patch, values, "description", "description", (value) => value.trim());
|
|
233
220
|
applyField(patch, values, "tools", "tools", csv);
|
|
234
|
-
applyField(patch, values, "required_tools", "requiredTools", csv);
|
|
235
221
|
applyField(patch, values, "model", "model", parseModel);
|
|
236
222
|
applyField(patch, values, "thinking", "thinkingLevel", parseThinking);
|
|
237
223
|
applyField(patch, values, "max_turns", "maxTurns", (v) => parsePositiveInteger(v, "max_turns"));
|
|
@@ -252,12 +238,7 @@ function parseProfilePatch(filePath, base) {
|
|
|
252
238
|
description: patch.description || base?.description || name,
|
|
253
239
|
systemPrompt,
|
|
254
240
|
tools: patch.tools ?? base?.tools ?? [],
|
|
255
|
-
requiredTools: patch.requiredTools ?? base?.requiredTools ?? [],
|
|
256
241
|
};
|
|
257
|
-
const ungranted = merged.requiredTools.filter((tool) => !merged.tools.includes(tool));
|
|
258
|
-
if (ungranted.length > 0) {
|
|
259
|
-
throw new Error(`required_tools must be included in tools: ${ungranted.join(", ")}`);
|
|
260
|
-
}
|
|
261
242
|
return merged;
|
|
262
243
|
}
|
|
263
244
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent-profiles.js","sourceRoot":"","sources":["../../src/harness/subagent-profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAU3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,4EAA4E;AAC5E,0EAA0E;AAC1E,8EAA8E;AAC9E,yEAAyE;AACzE,MAAM,gBAAgB,GAAsB;IAC1C;QACE,IAAI,EAAE,QA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CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,CAAC,IAAI,CAAC;gBACf,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC/D,IAAI,EAAE,QAAQ;aACf,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AACnC,CAAC","sourcesContent":["/**\n * Subagent profiles: the curated capability sets a subagent may be launched\n * with.\n *\n * Profiles exist because the two halves of a subagent definition have\n * different owners. What a profile *does* — its tools, required evidence,\n * prompt and budget — is portable, so it ships as a built-in below and is\n * versioned with the code. Which model runs it is per-installation, so it is\n * overridden by `<workspaceDir>/agents/<name>.md`.\n *\n * A workspace file therefore *patches* the built-in of the same name rather\n * than replacing it: overriding only `model:` must not force an operator to\n * restate the tools and prompt, because a restated copy silently drifts from\n * the built-in it was cloned from. A file whose name matches no built-in\n * defines a new profile and must supply `tools` itself.\n *\n * A malformed file is reported as a diagnostic and skipped, never thrown:\n * these are hand-edited, and one typo must not take the whole workspace down.\n */\nimport { existsSync, readFileSync, readdirSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type {\n LoadSubagentProfilesResult,\n SubagentModelSpec,\n SubagentProfile,\n SubagentProfileDiagnostic,\n} from \"./types.js\";\n\nexport type { LoadSubagentProfilesResult, SubagentProfileDiagnostic } from \"./types.js\";\nimport { parseFrontmatter } from \"./skills.js\";\n\n// Built-ins carry no requiredTools. The check is a per-task evidence demand\n// (\"prove you actually inspected X\") that only the caller can judge; as a\n// profile default it fails every task that legitimately needs a subset of the\n// granted tools, discarding a finished answer after the budget is spent.\nconst BUILTIN_PROFILES: SubagentProfile[] = [\n {\n name: \"worker\",\n description: \"Completes a bounded general-purpose task without adding domain assumptions\",\n systemPrompt: [\n \"You are a general-purpose worker responsible for one clearly bounded delegated task.\",\n \"\",\n \"Use `read` and `bash` to inspect the actual workspace state, and use `edit` or `write` only when the assignment requires changes. Follow applicable skill instructions, preserve behavior outside the stated scope, and do not invent requirements or broaden the task. Verify concrete outputs before reporting success; if the assignment lacks information or a required capability, state the limitation instead of guessing.\",\n \"\",\n \"Keep verbose discovery and command output in this isolated run. Return the completed result, files or artifacts changed, verification performed, and any unresolved blocker.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"edit\", \"write\"],\n requiredTools: [],\n thinkingLevel: \"high\",\n maxTurns: 30,\n maxTokens: 100_000,\n },\n {\n name: \"software-engineer\",\n description:\n \"Owns software investigation, implementation, integration, and technical verification\",\n systemPrompt: [\n \"You are the software engineer responsible for one delegated technical outcome.\",\n \"\",\n \"Apply the relevant engineering and vendor skill instructions. Use `bash` to inspect repositories, run development tools, diagnose browser or integration behavior, and make only changes explicitly included in the assignment. Trace failures to their technical cause, preserve existing contracts outside scope, and verify work with the narrowest meaningful checks. Do not treat plausible output as evidence of success.\",\n \"\",\n \"Keep source discovery, build logs, browser traces, and repetitive diagnostics in this isolated run. Return the implemented or diagnosed outcome, decisive technical evidence, changed artifact paths when applicable, verification results, and remaining engineering risk.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"edit\", \"write\"],\n requiredTools: [],\n thinkingLevel: \"high\",\n maxTurns: 35,\n maxTokens: 100_000,\n },\n {\n name: \"devops-engineer\",\n description:\n \"Owns cloud access, environments, deployments, and production workflow reliability\",\n systemPrompt: [\n \"You are the DevOps engineer responsible for one delegated infrastructure or production-operations outcome.\",\n \"\",\n \"Apply the relevant setup, GCP, repository-access, service-status, and production workflow skill instructions. Use `bash` to inspect current state before acting. Respect the named project, environment, principal, and resource scope; protect credentials; prefer least privilege; and check idempotency before writes, retries, or provisioning. Do not broaden access or repeat a non-idempotent operation without explicit authorization and evidence that it is needed.\",\n \"\",\n \"Keep verbose CLI, API, and job logs in this isolated run. Return the resulting state, affected resources or job identifiers, verification performed, and concrete follow-up or rollback information.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"edit\", \"write\", \"event\", \"sandbox\"],\n requiredTools: [],\n thinkingLevel: \"high\",\n maxTurns: 40,\n maxTokens: 100_000,\n },\n {\n name: \"data-scientist\",\n description:\n \"Owns metric definition, data analysis, reconciliation, and defensible conclusions\",\n systemPrompt: [\n \"You are the data scientist responsible for answering one delegated quantitative question.\",\n \"\",\n \"Apply the relevant Metabase, GAM, accounting, billing, reporting, and parser skill instructions. Use `bash` to run the prescribed queries and analysis tools. Establish the time range, timezone, filters, dimensions, population, and metric definitions before interpreting results. Reconcile totals and cross-check consequential figures when practical. Separate source values, derived calculations, and inference; never fill missing data with guesses.\",\n \"\",\n \"Keep verbose rows and query output in this isolated run. Return the conclusion, key figures with units and scope, methodology and checks, and limitations that affect confidence.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"write\"],\n requiredTools: [],\n thinkingLevel: \"high\",\n maxTurns: 35,\n maxTokens: 100_000,\n },\n {\n name: \"account-manager\",\n description:\n \"Owns existing-client onboarding, account coordination, and delivery follow-through\",\n systemPrompt: [\n \"You are the account manager responsible for one delegated existing-client outcome.\",\n \"\",\n \"Apply the relevant onboarding, publisher account, slot, workspace, meeting, and communication skill instructions. Use `bash` to inspect the current customer and account state before acting. Preserve supplied commercial and technical requirements, coordinate dependencies, avoid duplicate account changes, and clearly distinguish completed work from items awaiting another owner. Do not invent customer approval or make an external commitment beyond the assignment.\",\n \"\",\n \"Keep verbose records and operational output in this isolated run. Return the customer-facing outcome, account or artifact identifiers, decisions and blockers, and the next owner and action where follow-through remains.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"write\", \"event\"],\n requiredTools: [],\n thinkingLevel: \"high\",\n maxTurns: 30,\n maxTokens: 100_000,\n },\n {\n name: \"business-development\",\n description:\n \"Owns prospect research, qualification, contact discovery, and outreach preparation\",\n systemPrompt: [\n \"You are the business development specialist responsible for one delegated growth opportunity.\",\n \"\",\n \"Apply the relevant prospecting, website sampling, contact-finding, email-validation, and client-approach skill instructions. Use `bash` to gather and verify public evidence. Evaluate fit against the supplied criteria, distinguish verified contacts from inferred ones, and preserve source URLs. Do not contact prospects, submit forms, or represent that outreach occurred unless the assignment explicitly authorizes it.\",\n \"\",\n \"Keep raw pages, candidate lists, and repetitive validation output in this isolated run. Return qualified opportunities, supporting evidence, confidence and disqualifiers, and a concise recommended next action.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"write\"],\n requiredTools: [],\n thinkingLevel: \"high\",\n maxTurns: 30,\n maxTokens: 100_000,\n },\n {\n name: \"creative-producer\",\n description: \"Owns media deliverables from creative brief through verified production output\",\n systemPrompt: [\n \"You are the creative producer responsible for one delegated media deliverable.\",\n \"\",\n \"Apply the relevant source acquisition, storyboard, video, image, speech, lipsync, and generation-provider skill instructions. Use `bash` to run the prescribed production tools. Confirm the brief, audience, format, dimensions, duration, language, and source inputs; use discovery commands rather than guessing provider or model identifiers. Preserve provenance and generation parameters, and verify that claimed outputs exist and match the requested technical properties.\",\n \"\",\n \"Keep generation logs, intermediate assets, and provider polling in this isolated run. Return deliverable paths or external identifiers, a concise production summary, verification results, and unresolved creative, quality, or rights constraints.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"write\"],\n requiredTools: [],\n thinkingLevel: \"high\",\n maxTurns: 40,\n maxTokens: 100_000,\n },\n {\n name: \"ad-operations-specialist\",\n description:\n \"Owns ad serving setup, delivery diagnostics, policy checks, and operational health\",\n systemPrompt: [\n \"You are the ad operations specialist responsible for one delegated advertising-delivery outcome.\",\n \"\",\n \"Apply the relevant GAM, ads.txt, player detection, targeting, behavior, monitoring, and policy skill instructions. Use `bash` to run the prescribed browser and reporting tools. Establish the site, account, slot, time window, geography, device, and consent conditions; distinguish configuration, eligibility, request, impression, and playback evidence. Reproduce dynamic behavior when practical, and do not change live serving configuration unless explicitly authorized.\",\n \"\",\n \"Keep browser traces, HAR data, report rows, and repetitive diagnostics in this isolated run. Return the operational conclusion, decisive delivery evidence, affected inventory, remediation or escalation owner, and uncertainty that could change the diagnosis.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"write\"],\n requiredTools: [],\n thinkingLevel: \"high\",\n maxTurns: 35,\n maxTokens: 100_000,\n },\n {\n name: \"analysis-only\",\n description: \"Analyzes supplied task input without claiming external verification\",\n systemPrompt: [\n \"You analyze only the task text and structured dependency input supplied to this run.\",\n \"\",\n \"Do not claim to have inspected files, executed commands, accessed URLs, or verified external state. Clearly distinguish dependency-provided facts from your own analysis. If the supplied evidence is insufficient, state the limitation instead of inventing details.\",\n ].join(\"\\n\"),\n tools: [],\n requiredTools: [],\n thinkingLevel: \"high\",\n maxTurns: 20,\n maxTokens: 100_000,\n },\n];\n\nconst THINKING_LEVELS = new Set<ThinkingLevel>([\n \"off\",\n \"minimal\",\n \"low\",\n \"medium\",\n \"high\",\n \"xhigh\",\n]);\n\n/** Parse a comma-separated tool list. The literal `none` is an empty grant. */\nfunction csv(value: string): string[] {\n if (value.trim() === \"none\") return [];\n return [\n ...new Set(\n value\n .split(\",\")\n .map((item) => item.trim())\n .filter(Boolean),\n ),\n ];\n}\n\nfunction parseModel(value: string): SubagentModelSpec {\n const separator = value.indexOf(\"/\");\n if (separator <= 0 || separator === value.length - 1) {\n throw new Error(`model must be provider/id, got ${value}`);\n }\n return { provider: value.slice(0, separator), id: value.slice(separator + 1) };\n}\n\nfunction parseThinking(value: string): ThinkingLevel {\n if (!THINKING_LEVELS.has(value as ThinkingLevel)) {\n throw new Error(`unknown thinking level: ${value}`);\n }\n return value as ThinkingLevel;\n}\n\nfunction parsePositiveInteger(value: string, field: string): number {\n const parsed = Number(value);\n if (!Number.isInteger(parsed) || parsed <= 0) {\n throw new Error(`${field} must be a positive integer`);\n }\n return parsed;\n}\n\nfunction parseNonNegativeNumber(value: string, field: string): number {\n const parsed = Number(value);\n if (!Number.isFinite(parsed) || parsed < 0) {\n throw new Error(`${field} must be a non-negative number`);\n }\n return parsed;\n}\n\n/** Apply `field` from frontmatter onto `patch` only when the file sets it. */\nfunction applyField<K extends keyof SubagentProfile>(\n patch: Partial<SubagentProfile>,\n values: Record<string, string>,\n key: string,\n field: K,\n parse: (value: string) => SubagentProfile[K],\n): void {\n const raw = values[key];\n if (raw === undefined) return;\n patch[field] = parse(raw);\n}\n\n/**\n * Build the overlay a single file contributes. Throws with a human-readable\n * message on malformed input; the caller turns that into a diagnostic.\n */\nfunction parseProfilePatch(filePath: string, base: SubagentProfile | undefined): SubagentProfile {\n const { values, body } = parseFrontmatter(readFileSync(filePath, \"utf-8\"));\n const name = basename(filePath, \".md\");\n const patch: Partial<SubagentProfile> = {};\n\n applyField(patch, values, \"description\", \"description\", (value) => value.trim());\n applyField(patch, values, \"tools\", \"tools\", csv);\n applyField(patch, values, \"required_tools\", \"requiredTools\", csv);\n applyField(patch, values, \"model\", \"model\", parseModel);\n applyField(patch, values, \"thinking\", \"thinkingLevel\", parseThinking);\n applyField(patch, values, \"max_turns\", \"maxTurns\", (v) => parsePositiveInteger(v, \"max_turns\"));\n applyField(patch, values, \"max_tokens\", \"maxTokens\", (v) =>\n parsePositiveInteger(v, \"max_tokens\"),\n );\n applyField(patch, values, \"max_cost_usd\", \"maxCostUsd\", (v) =>\n parseNonNegativeNumber(v, \"max_cost_usd\"),\n );\n applyField(patch, values, \"max_duration_ms\", \"maxDurationMs\", (v) =>\n parsePositiveInteger(v, \"max_duration_ms\"),\n );\n\n const systemPrompt = body.trim() || base?.systemPrompt;\n if (!base && patch.tools === undefined) {\n throw new Error(`tools is required for a new profile (no built-in named ${name})`);\n }\n if (!systemPrompt) {\n throw new Error(`a new profile needs prompt text in the file body`);\n }\n\n const merged: SubagentProfile = {\n ...base,\n ...patch,\n name,\n description: patch.description || base?.description || name,\n systemPrompt,\n tools: patch.tools ?? base?.tools ?? [],\n requiredTools: patch.requiredTools ?? base?.requiredTools ?? [],\n };\n\n const ungranted = merged.requiredTools.filter((tool) => !merged.tools.includes(tool));\n if (ungranted.length > 0) {\n throw new Error(`required_tools must be included in tools: ${ungranted.join(\", \")}`);\n }\n return merged;\n}\n\n/**\n * Load the built-in profiles, then patch them with `<workspaceDir>/agents/*.md`.\n * Malformed files are reported and skipped, leaving the built-in in place.\n */\nexport function loadSubagentProfiles(workspaceDir: string): LoadSubagentProfilesResult {\n const dir = join(workspaceDir, \"agents\");\n const profiles = new Map(BUILTIN_PROFILES.map((profile) => [profile.name, profile]));\n const diagnostics: SubagentProfileDiagnostic[] = [];\n if (!existsSync(dir)) return { profiles, diagnostics };\n\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch (error) {\n diagnostics.push({\n type: \"warning\",\n message: error instanceof Error ? error.message : String(error),\n path: dir,\n });\n return { profiles, diagnostics };\n }\n\n for (const entry of entries) {\n if (!entry.isFile() || !entry.name.endsWith(\".md\")) continue;\n const filePath = join(dir, entry.name);\n try {\n const profile = parseProfilePatch(filePath, profiles.get(basename(entry.name, \".md\")));\n profiles.set(profile.name, profile);\n } catch (error) {\n diagnostics.push({\n type: \"warning\",\n message: error instanceof Error ? error.message : String(error),\n path: filePath,\n });\n }\n }\n return { profiles, diagnostics };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"subagent-profiles.js","sourceRoot":"","sources":["../../src/harness/subagent-profiles.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAU3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,gBAAgB,GAAsB;IAC1C;QACE,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,4EAA4E;QACzF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V,CAAC,CAAC;QACH,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;IACnC,CAAC;IAED,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,SAAS;QAC7D,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,CAAC;YACH,MAAM,OAAO,GAAG,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;YACvF,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,WAAW,CAAC,IAAI,CAAC;gBACf,IAAI,EAAE,SAAS;gBACf,OAAO,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;gBAC/D,IAAI,EAAE,QAAQ;aACf,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AACnC,CAAC","sourcesContent":["/**\n * Subagent profiles: the curated capability sets a subagent may be launched\n * with.\n *\n * Profiles exist because the two halves of a subagent definition have\n * different owners. What a profile *does* — its tools, required evidence,\n * prompt and budget — is portable, so it ships as a built-in below and is\n * versioned with the code. Which model runs it is per-installation, so it is\n * overridden by `<workspaceDir>/agents/<name>.md`.\n *\n * A workspace file therefore *patches* the built-in of the same name rather\n * than replacing it: overriding only `model:` must not force an operator to\n * restate the tools and prompt, because a restated copy silently drifts from\n * the built-in it was cloned from. A file whose name matches no built-in\n * defines a new profile and must supply `tools` itself.\n *\n * A malformed file is reported as a diagnostic and skipped, never thrown:\n * these are hand-edited, and one typo must not take the whole workspace down.\n */\nimport { existsSync, readFileSync, readdirSync } from \"node:fs\";\nimport { basename, join } from \"node:path\";\nimport type { ThinkingLevel } from \"@earendil-works/pi-agent-core\";\nimport type {\n LoadSubagentProfilesResult,\n SubagentModelSpec,\n SubagentProfile,\n SubagentProfileDiagnostic,\n} from \"./types.js\";\n\nexport type { LoadSubagentProfilesResult, SubagentProfileDiagnostic } from \"./types.js\";\nimport { parseFrontmatter } from \"./skills.js\";\n\nconst BUILTIN_PROFILES: SubagentProfile[] = [\n {\n name: \"worker\",\n description: \"Completes a bounded general-purpose task without adding domain assumptions\",\n systemPrompt: [\n \"You are a general-purpose worker responsible for one clearly bounded delegated task.\",\n \"\",\n \"Use `read` and `bash` to inspect the actual workspace state, and use `edit` or `write` only when the assignment requires changes. Follow applicable skill instructions, preserve behavior outside the stated scope, and do not invent requirements or broaden the task. Verify concrete outputs before reporting success; if the assignment lacks information or a required capability, state the limitation instead of guessing.\",\n \"\",\n \"Keep verbose discovery and command output in this isolated run. Return the completed result, files or artifacts changed, verification performed, and any unresolved blocker.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"edit\", \"write\"],\n thinkingLevel: \"high\",\n maxTurns: 30,\n maxTokens: 100_000,\n },\n {\n name: \"software-engineer\",\n description:\n \"Owns software investigation, implementation, integration, and technical verification\",\n systemPrompt: [\n \"You are the software engineer responsible for one delegated technical outcome.\",\n \"\",\n \"Apply the relevant engineering and vendor skill instructions. Use `bash` to inspect repositories, run development tools, diagnose browser or integration behavior, and make only changes explicitly included in the assignment. Trace failures to their technical cause, preserve existing contracts outside scope, and verify work with the narrowest meaningful checks. Do not treat plausible output as evidence of success.\",\n \"\",\n \"Keep source discovery, build logs, browser traces, and repetitive diagnostics in this isolated run. Return the implemented or diagnosed outcome, decisive technical evidence, changed artifact paths when applicable, verification results, and remaining engineering risk.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"edit\", \"write\"],\n thinkingLevel: \"high\",\n maxTurns: 35,\n maxTokens: 100_000,\n },\n {\n name: \"devops-engineer\",\n description:\n \"Owns cloud access, environments, deployments, and production workflow reliability\",\n systemPrompt: [\n \"You are the DevOps engineer responsible for one delegated infrastructure or production-operations outcome.\",\n \"\",\n \"Apply the relevant setup, GCP, repository-access, service-status, and production workflow skill instructions. Use `bash` to inspect current state before acting. Respect the named project, environment, principal, and resource scope; protect credentials; prefer least privilege; and check idempotency before writes, retries, or provisioning. Do not broaden access or repeat a non-idempotent operation without explicit authorization and evidence that it is needed.\",\n \"\",\n \"Keep verbose CLI, API, and job logs in this isolated run. Return the resulting state, affected resources or job identifiers, verification performed, and concrete follow-up or rollback information.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"edit\", \"write\", \"event\", \"sandbox\"],\n thinkingLevel: \"high\",\n maxTurns: 40,\n maxTokens: 100_000,\n },\n {\n name: \"data-scientist\",\n description:\n \"Owns metric definition, data analysis, reconciliation, and defensible conclusions\",\n systemPrompt: [\n \"You are the data scientist responsible for answering one delegated quantitative question.\",\n \"\",\n \"Apply the relevant Metabase, GAM, accounting, billing, reporting, and parser skill instructions. Use `bash` to run the prescribed queries and analysis tools. Establish the time range, timezone, filters, dimensions, population, and metric definitions before interpreting results. Reconcile totals and cross-check consequential figures when practical. Separate source values, derived calculations, and inference; never fill missing data with guesses.\",\n \"\",\n \"Keep verbose rows and query output in this isolated run. Return the conclusion, key figures with units and scope, methodology and checks, and limitations that affect confidence.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"write\"],\n thinkingLevel: \"high\",\n maxTurns: 35,\n maxTokens: 100_000,\n },\n {\n name: \"account-manager\",\n description:\n \"Owns existing-client onboarding, account coordination, and delivery follow-through\",\n systemPrompt: [\n \"You are the account manager responsible for one delegated existing-client outcome.\",\n \"\",\n \"Apply the relevant onboarding, publisher account, slot, workspace, meeting, and communication skill instructions. Use `bash` to inspect the current customer and account state before acting. Preserve supplied commercial and technical requirements, coordinate dependencies, avoid duplicate account changes, and clearly distinguish completed work from items awaiting another owner. Do not invent customer approval or make an external commitment beyond the assignment.\",\n \"\",\n \"Keep verbose records and operational output in this isolated run. Return the customer-facing outcome, account or artifact identifiers, decisions and blockers, and the next owner and action where follow-through remains.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"write\", \"event\"],\n thinkingLevel: \"high\",\n maxTurns: 30,\n maxTokens: 100_000,\n },\n {\n name: \"business-development\",\n description:\n \"Owns prospect research, qualification, contact discovery, and outreach preparation\",\n systemPrompt: [\n \"You are the business development specialist responsible for one delegated growth opportunity.\",\n \"\",\n \"Apply the relevant prospecting, website sampling, contact-finding, email-validation, and client-approach skill instructions. Use `bash` to gather and verify public evidence. Evaluate fit against the supplied criteria, distinguish verified contacts from inferred ones, and preserve source URLs. Do not contact prospects, submit forms, or represent that outreach occurred unless the assignment explicitly authorizes it.\",\n \"\",\n \"Keep raw pages, candidate lists, and repetitive validation output in this isolated run. Return qualified opportunities, supporting evidence, confidence and disqualifiers, and a concise recommended next action.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"write\"],\n thinkingLevel: \"high\",\n maxTurns: 30,\n maxTokens: 100_000,\n },\n {\n name: \"creative-producer\",\n description: \"Owns media deliverables from creative brief through verified production output\",\n systemPrompt: [\n \"You are the creative producer responsible for one delegated media deliverable.\",\n \"\",\n \"Apply the relevant source acquisition, storyboard, video, image, speech, lipsync, and generation-provider skill instructions. Use `bash` to run the prescribed production tools. Confirm the brief, audience, format, dimensions, duration, language, and source inputs; use discovery commands rather than guessing provider or model identifiers. Preserve provenance and generation parameters, and verify that claimed outputs exist and match the requested technical properties.\",\n \"\",\n \"Keep generation logs, intermediate assets, and provider polling in this isolated run. Return deliverable paths or external identifiers, a concise production summary, verification results, and unresolved creative, quality, or rights constraints.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"write\"],\n thinkingLevel: \"high\",\n maxTurns: 40,\n maxTokens: 100_000,\n },\n {\n name: \"ad-operations-specialist\",\n description:\n \"Owns ad serving setup, delivery diagnostics, policy checks, and operational health\",\n systemPrompt: [\n \"You are the ad operations specialist responsible for one delegated advertising-delivery outcome.\",\n \"\",\n \"Apply the relevant GAM, ads.txt, player detection, targeting, behavior, monitoring, and policy skill instructions. Use `bash` to run the prescribed browser and reporting tools. Establish the site, account, slot, time window, geography, device, and consent conditions; distinguish configuration, eligibility, request, impression, and playback evidence. Reproduce dynamic behavior when practical, and do not change live serving configuration unless explicitly authorized.\",\n \"\",\n \"Keep browser traces, HAR data, report rows, and repetitive diagnostics in this isolated run. Return the operational conclusion, decisive delivery evidence, affected inventory, remediation or escalation owner, and uncertainty that could change the diagnosis.\",\n ].join(\"\\n\"),\n tools: [\"read\", \"bash\", \"write\"],\n thinkingLevel: \"high\",\n maxTurns: 35,\n maxTokens: 100_000,\n },\n {\n name: \"analysis-only\",\n description: \"Analyzes supplied task input without claiming external verification\",\n systemPrompt: [\n \"You analyze only the task text and structured dependency input supplied to this run.\",\n \"\",\n \"Do not claim to have inspected files, executed commands, accessed URLs, or verified external state. Clearly distinguish dependency-provided facts from your own analysis. If the supplied evidence is insufficient, state the limitation instead of inventing details.\",\n ].join(\"\\n\"),\n tools: [],\n thinkingLevel: \"high\",\n maxTurns: 20,\n maxTokens: 100_000,\n },\n];\n\nconst THINKING_LEVELS = new Set<ThinkingLevel>([\n \"off\",\n \"minimal\",\n \"low\",\n \"medium\",\n \"high\",\n \"xhigh\",\n]);\n\n/** Parse a comma-separated tool list. The literal `none` is an empty grant. */\nfunction csv(value: string): string[] {\n if (value.trim() === \"none\") return [];\n return [\n ...new Set(\n value\n .split(\",\")\n .map((item) => item.trim())\n .filter(Boolean),\n ),\n ];\n}\n\nfunction parseModel(value: string): SubagentModelSpec {\n const separator = value.indexOf(\"/\");\n if (separator <= 0 || separator === value.length - 1) {\n throw new Error(`model must be provider/id, got ${value}`);\n }\n return { provider: value.slice(0, separator), id: value.slice(separator + 1) };\n}\n\nfunction parseThinking(value: string): ThinkingLevel {\n if (!THINKING_LEVELS.has(value as ThinkingLevel)) {\n throw new Error(`unknown thinking level: ${value}`);\n }\n return value as ThinkingLevel;\n}\n\nfunction parsePositiveInteger(value: string, field: string): number {\n const parsed = Number(value);\n if (!Number.isInteger(parsed) || parsed <= 0) {\n throw new Error(`${field} must be a positive integer`);\n }\n return parsed;\n}\n\nfunction parseNonNegativeNumber(value: string, field: string): number {\n const parsed = Number(value);\n if (!Number.isFinite(parsed) || parsed < 0) {\n throw new Error(`${field} must be a non-negative number`);\n }\n return parsed;\n}\n\n/** Apply `field` from frontmatter onto `patch` only when the file sets it. */\nfunction applyField<K extends keyof SubagentProfile>(\n patch: Partial<SubagentProfile>,\n values: Record<string, string>,\n key: string,\n field: K,\n parse: (value: string) => SubagentProfile[K],\n): void {\n const raw = values[key];\n if (raw === undefined) return;\n patch[field] = parse(raw);\n}\n\n/**\n * Build the overlay a single file contributes. Throws with a human-readable\n * message on malformed input; the caller turns that into a diagnostic.\n */\nfunction parseProfilePatch(filePath: string, base: SubagentProfile | undefined): SubagentProfile {\n const { values, body } = parseFrontmatter(readFileSync(filePath, \"utf-8\"));\n const name = basename(filePath, \".md\");\n const patch: Partial<SubagentProfile> = {};\n\n applyField(patch, values, \"description\", \"description\", (value) => value.trim());\n applyField(patch, values, \"tools\", \"tools\", csv);\n applyField(patch, values, \"model\", \"model\", parseModel);\n applyField(patch, values, \"thinking\", \"thinkingLevel\", parseThinking);\n applyField(patch, values, \"max_turns\", \"maxTurns\", (v) => parsePositiveInteger(v, \"max_turns\"));\n applyField(patch, values, \"max_tokens\", \"maxTokens\", (v) =>\n parsePositiveInteger(v, \"max_tokens\"),\n );\n applyField(patch, values, \"max_cost_usd\", \"maxCostUsd\", (v) =>\n parseNonNegativeNumber(v, \"max_cost_usd\"),\n );\n applyField(patch, values, \"max_duration_ms\", \"maxDurationMs\", (v) =>\n parsePositiveInteger(v, \"max_duration_ms\"),\n );\n\n const systemPrompt = body.trim() || base?.systemPrompt;\n if (!base && patch.tools === undefined) {\n throw new Error(`tools is required for a new profile (no built-in named ${name})`);\n }\n if (!systemPrompt) {\n throw new Error(`a new profile needs prompt text in the file body`);\n }\n\n const merged: SubagentProfile = {\n ...base,\n ...patch,\n name,\n description: patch.description || base?.description || name,\n systemPrompt,\n tools: patch.tools ?? base?.tools ?? [],\n };\n return merged;\n}\n\n/**\n * Load the built-in profiles, then patch them with `<workspaceDir>/agents/*.md`.\n * Malformed files are reported and skipped, leaving the built-in in place.\n */\nexport function loadSubagentProfiles(workspaceDir: string): LoadSubagentProfilesResult {\n const dir = join(workspaceDir, \"agents\");\n const profiles = new Map(BUILTIN_PROFILES.map((profile) => [profile.name, profile]));\n const diagnostics: SubagentProfileDiagnostic[] = [];\n if (!existsSync(dir)) return { profiles, diagnostics };\n\n let entries;\n try {\n entries = readdirSync(dir, { withFileTypes: true });\n } catch (error) {\n diagnostics.push({\n type: \"warning\",\n message: error instanceof Error ? error.message : String(error),\n path: dir,\n });\n return { profiles, diagnostics };\n }\n\n for (const entry of entries) {\n if (!entry.isFile() || !entry.name.endsWith(\".md\")) continue;\n const filePath = join(dir, entry.name);\n try {\n const profile = parseProfilePatch(filePath, profiles.get(basename(entry.name, \".md\")));\n profiles.set(profile.name, profile);\n } catch (error) {\n diagnostics.push({\n type: \"warning\",\n message: error instanceof Error ? error.message : String(error),\n path: filePath,\n });\n }\n }\n return { profiles, diagnostics };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subagent-runner.d.ts","sourceRoot":"","sources":["../../src/harness/subagent-runner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAe,KAAK,GAAG,EAAyB,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAC;AACjG,OAAO,EAAc,KAAK,OAAO,EAAE,MAAM,m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,OAAO,GAAG,SAAS,GAAG,SAAS,EACrF,OAAO,EAAE,kBAAkB,CAAC,aAAa,CAAC,GACzC,OAAO,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC,CAAC,CAc9D"}
|
|
@@ -206,28 +206,6 @@ function selectTools(requested, available) {
|
|
|
206
206
|
}
|
|
207
207
|
return selected;
|
|
208
208
|
}
|
|
209
|
-
/**
|
|
210
|
-
* Wrap a tool so the run can prove it was actually reached. Fields are listed
|
|
211
|
-
* explicitly rather than spread: `AgentTool` is a plain interface, and a
|
|
212
|
-
* structural copy would silently drop anything added to it later.
|
|
213
|
-
*/
|
|
214
|
-
function witnessToolUse(tool, invoked) {
|
|
215
|
-
return {
|
|
216
|
-
name: tool.name,
|
|
217
|
-
label: tool.label,
|
|
218
|
-
description: tool.description,
|
|
219
|
-
parameters: tool.parameters,
|
|
220
|
-
...(tool.constrainedSampling !== undefined
|
|
221
|
-
? { constrainedSampling: tool.constrainedSampling }
|
|
222
|
-
: {}),
|
|
223
|
-
...(tool.prepareArguments ? { prepareArguments: tool.prepareArguments.bind(tool) } : {}),
|
|
224
|
-
...(tool.executionMode ? { executionMode: tool.executionMode } : {}),
|
|
225
|
-
execute: (...args) => {
|
|
226
|
-
invoked.add(tool.name);
|
|
227
|
-
return tool.execute(...args);
|
|
228
|
-
},
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
209
|
function formatTask(task, input, parentContext) {
|
|
232
210
|
const trimmed = task.trim();
|
|
233
211
|
if (!trimmed)
|
|
@@ -468,9 +446,6 @@ function resolveProfile(request, options) {
|
|
|
468
446
|
...request,
|
|
469
447
|
systemPrompt: profile.systemPrompt,
|
|
470
448
|
tools: profile.tools,
|
|
471
|
-
// The guard above allows requiredTools to combine with a profile, so the
|
|
472
|
-
// caller's evidence requirements must survive alongside the profile's.
|
|
473
|
-
requiredTools: [...new Set([...(request.requiredTools ?? []), ...profile.requiredTools])],
|
|
474
449
|
...(profile.model ? { model: profile.model } : {}),
|
|
475
450
|
...(profile.thinkingLevel ? { thinkingLevel: profile.thinkingLevel } : {}),
|
|
476
451
|
...(Object.keys(budget).length > 0 ? { budget } : {}),
|
|
@@ -480,18 +455,13 @@ function prepareSubagentRun(options, request, runId, startedAt) {
|
|
|
480
455
|
const model = request.model
|
|
481
456
|
? options.models.resolve(request.model.provider, request.model.id)
|
|
482
457
|
: options.defaultModel;
|
|
483
|
-
const invokedTools = new Set();
|
|
484
458
|
const granted = selectTools(request.tools, options.availableTools);
|
|
485
|
-
const missingRequiredTools = (request.requiredTools ?? []).filter((name) => !granted.some((tool) => tool.name === name));
|
|
486
|
-
if (missingRequiredTools.length > 0) {
|
|
487
|
-
throw new Error(`Required subagent tools were not granted: ${missingRequiredTools.join(", ")}`);
|
|
488
|
-
}
|
|
489
459
|
const task = formatTask(request.task, request.input, normalizedParentContext(request, options.parentMessages));
|
|
490
460
|
const session = new MikanAgentSession({
|
|
491
461
|
systemPrompt: buildSystemPrompt(request.systemPrompt, request.outputSchema, granted.map((tool) => tool.name)),
|
|
492
462
|
model,
|
|
493
463
|
thinkingLevel: request.thinkingLevel ?? options.thinkingLevel,
|
|
494
|
-
tools: granted
|
|
464
|
+
tools: granted,
|
|
495
465
|
models: options.models,
|
|
496
466
|
sessionStore: SessionStore.inMemory(options.workspaceDir),
|
|
497
467
|
settings: { compaction: { enabled: false } },
|
|
@@ -505,12 +475,11 @@ function prepareSubagentRun(options, request, runId, startedAt) {
|
|
|
505
475
|
modelSpec: { provider: model.provider, id: model.id },
|
|
506
476
|
session,
|
|
507
477
|
budget: resolveBudget(request.budget),
|
|
508
|
-
invokedTools,
|
|
509
478
|
task,
|
|
510
479
|
};
|
|
511
480
|
}
|
|
512
481
|
function buildSubagentResult(run, terminalSignal, cleanupPending = false) {
|
|
513
|
-
const { session, request,
|
|
482
|
+
const { session, request, budget } = run;
|
|
514
483
|
const stats = session.getLastRunStats();
|
|
515
484
|
const assistant = finalAssistant(session.messages);
|
|
516
485
|
const text = assistant ? contentText(assistant.content, "") : "";
|
|
@@ -531,14 +500,6 @@ function buildSubagentResult(run, terminalSignal, cleanupPending = false) {
|
|
|
531
500
|
if (stats.budgetExceededReason) {
|
|
532
501
|
return { ...base, status: "budget_exceeded", error: stats.budgetExceededReason };
|
|
533
502
|
}
|
|
534
|
-
const unusedRequiredTools = (request.requiredTools ?? []).filter((name) => !invokedTools.has(name));
|
|
535
|
-
if (unusedRequiredTools.length > 0) {
|
|
536
|
-
return {
|
|
537
|
-
...base,
|
|
538
|
-
status: "failed",
|
|
539
|
-
error: `Required tool not used: ${unusedRequiredTools.join(", ")}`,
|
|
540
|
-
};
|
|
541
|
-
}
|
|
542
503
|
if (assistant?.stopReason === "error") {
|
|
543
504
|
return { ...base, status: "failed", error: assistant.errorMessage || "Subagent failed" };
|
|
544
505
|
}
|