@cr1ms0n/pi-subagent 0.8.9 → 0.10.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/CHANGELOG.md +24 -0
- package/README.md +130 -569
- package/README.zh-CN.md +132 -0
- package/docs/ARCHITECTURE.md +56 -13
- package/docs/COST-ACCOUNTING.md +116 -66
- package/docs/DEVELOPMENT.md +124 -0
- package/docs/PLAN.md +2 -0
- package/docs/REFERENCE.md +436 -0
- package/docs/RELEASING.md +135 -16
- package/docs/ROADMAP.md +2 -0
- package/docs/SECURITY.md +52 -16
- package/docs/UX.md +158 -141
- package/package.json +10 -2
- package/skills/subagent/SKILL.md +82 -49
- package/src/backends/pi.ts +164 -94
- package/src/child-preflight.ts +166 -0
- package/src/config.ts +254 -252
- package/src/dispatch-preflight.ts +87 -0
- package/src/dispatch-routing.ts +56 -0
- package/src/extension.ts +366 -158
- package/src/format.ts +436 -365
- package/src/jev-router.ts +1032 -0
- package/src/orchestrator.ts +75 -19
- package/src/persistence.ts +643 -335
- package/src/policy.ts +120 -89
- package/src/process-lock.ts +730 -687
- package/src/protocol.ts +320 -290
- package/src/registry.ts +730 -632
- package/src/routing-policy.ts +276 -0
- package/src/routing-types.ts +217 -0
- package/src/runner.ts +1299 -850
- package/src/schema.ts +10 -10
- package/src/startup-check.ts +481 -0
- package/src/types.ts +208 -198
- package/src/usage.ts +316 -274
- package/src/model-policy.ts +0 -169
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { JevRouter } from "./jev-router.js";
|
|
2
|
+
import { finalizeRoutedTasks, type PreparedTask, type ResolvedTask } from "./policy.js";
|
|
3
|
+
import type { RoutingModelCandidate, RoutingPurpose, RoutingToolCandidate } from "./routing-types.js";
|
|
4
|
+
|
|
5
|
+
/** Frozen catalog projection: no tool schema, executable, path or credential crosses the selector. */
|
|
6
|
+
export interface RoutingCatalog {
|
|
7
|
+
readonly models: readonly RoutingModelCandidate[];
|
|
8
|
+
readonly tools: readonly RoutingToolCandidate[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Resolve every worker before allowing a launch. Selection is ordered deliberately: a failed
|
|
13
|
+
* earlier worker does not initiate further paid requests. Each task keeps its original deadline.
|
|
14
|
+
* The injected owner assertion runs after every await, including a successful but cancelled call.
|
|
15
|
+
*/
|
|
16
|
+
export async function routePreparedTasks(
|
|
17
|
+
prepared: readonly PreparedTask[],
|
|
18
|
+
catalog: RoutingCatalog,
|
|
19
|
+
router: Pick<JevRouter, "select">,
|
|
20
|
+
options: { purpose: RoutingPurpose; signal: AbortSignal; assertOwner(): void },
|
|
21
|
+
): Promise<ResolvedTask[]> {
|
|
22
|
+
const decisions = [];
|
|
23
|
+
for (let index = 0; index < prepared.length; index++) {
|
|
24
|
+
options.assertOwner();
|
|
25
|
+
const task = prepared[index]!;
|
|
26
|
+
if (task.deadline !== undefined && Date.now() >= task.deadline) {
|
|
27
|
+
throw new Error(`Task ${index + 1}: timeout before Jev selection; no child was started.`);
|
|
28
|
+
}
|
|
29
|
+
const names = new Set(task.candidateTools);
|
|
30
|
+
const result = await router.select({
|
|
31
|
+
task: task.task,
|
|
32
|
+
models: catalog.models,
|
|
33
|
+
tools: catalog.tools.filter((tool) => names.has(tool.name)),
|
|
34
|
+
constraints: {
|
|
35
|
+
profile: task.profile,
|
|
36
|
+
requestedThinking: task.requestedThinking,
|
|
37
|
+
structuredOutput: task.outputSchema !== undefined,
|
|
38
|
+
},
|
|
39
|
+
}, { purpose: options.purpose, taskIndex: index, deadline: task.deadline, signal: options.signal });
|
|
40
|
+
options.assertOwner();
|
|
41
|
+
if (!result.ok) throw new Error(`Task ${index + 1}: Jev ${result.code}: ${result.message}`);
|
|
42
|
+
if (result.persistenceErrors?.length) {
|
|
43
|
+
throw new Error(`Task ${index + 1}: routing receipts could not be persisted; no child was started.`);
|
|
44
|
+
}
|
|
45
|
+
decisions.push(result.decision);
|
|
46
|
+
}
|
|
47
|
+
const finalized = finalizeRoutedTasks(prepared, decisions, catalog.models);
|
|
48
|
+
if (!finalized.ok) throw new Error(finalized.error);
|
|
49
|
+
// An earlier parallel task may have expired while a later task was being selected.
|
|
50
|
+
for (let index = 0; index < finalized.tasks.length; index++) {
|
|
51
|
+
const deadline = finalized.tasks[index]!.deadline;
|
|
52
|
+
if (deadline !== undefined && Date.now() >= deadline) throw new Error(`Task ${index + 1}: timeout during routing; no child was started.`);
|
|
53
|
+
}
|
|
54
|
+
options.assertOwner();
|
|
55
|
+
return finalized.tasks;
|
|
56
|
+
}
|