@abelxiaoxing/cadence 1.8.2 → 1.8.4
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 +71 -531
- package/agents/design-explorer.md +15 -23
- package/agents/diagnosis-worker.md +12 -23
- package/agents/implementation-worker.md +16 -34
- package/config/.env.example +2 -5
- package/package.json +1 -1
- package/prompts/abel-diagnose.md +5 -5
- package/src/candidate-context.ts +289 -0
- package/src/contracts.ts +12 -22
- package/src/durable-contracts.ts +1 -5
- package/src/durable-workflow.ts +3 -159
- package/src/evidence-draft.ts +1 -1
- package/src/index.ts +12 -16
- package/src/package-candidate-process.ts +206 -0
- package/src/package-candidate.ts +11 -214
- package/src/package-workflow.ts +5 -42
- package/src/packet-runtime.ts +144 -255
- package/src/phase-execution.ts +134 -230
- package/src/startup-card.ts +17 -23
- package/src/subagent-process.ts +476 -0
- package/src/transport-budget.ts +1 -3
- package/src/workflow-policy.ts +9 -18
- package/src/workflow-state-machine.ts +1 -15
- package/config/routes.example.json +0 -39
- package/src/child-budget.ts +0 -58
- package/src/child-model.ts +0 -142
- package/src/child-session.ts +0 -640
- package/src/parent-provider.ts +0 -375
- package/src/route-policy.ts +0 -545
- package/src/submit-tool.ts +0 -950
- package/src/worker-broker.ts +0 -806
package/src/child-model.ts
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AssistantMessage,
|
|
3
|
-
type Context,
|
|
4
|
-
cleanupSessionResources,
|
|
5
|
-
type Model,
|
|
6
|
-
type Models,
|
|
7
|
-
} from "@earendil-works/pi-ai";
|
|
8
|
-
|
|
9
|
-
import { requestBounds, TransportTimeout } from "./transport-budget.ts";
|
|
10
|
-
|
|
11
|
-
/** Only the public model transport contract crosses into the child executor. */
|
|
12
|
-
export type ChildModelClient = Pick<Models, "streamSimple">;
|
|
13
|
-
|
|
14
|
-
export function abortable<T>(
|
|
15
|
-
promise: Promise<T>,
|
|
16
|
-
signal: AbortSignal,
|
|
17
|
-
): Promise<T> {
|
|
18
|
-
signal.throwIfAborted();
|
|
19
|
-
return new Promise<T>((resolve, reject) => {
|
|
20
|
-
const onAbort = () => {
|
|
21
|
-
cleanup();
|
|
22
|
-
reject(signal.reason);
|
|
23
|
-
};
|
|
24
|
-
const cleanup = () => signal.removeEventListener("abort", onAbort);
|
|
25
|
-
signal.addEventListener("abort", onAbort, { once: true });
|
|
26
|
-
promise.then(
|
|
27
|
-
(value) => {
|
|
28
|
-
cleanup();
|
|
29
|
-
resolve(value);
|
|
30
|
-
},
|
|
31
|
-
(error) => {
|
|
32
|
-
cleanup();
|
|
33
|
-
reject(error);
|
|
34
|
-
},
|
|
35
|
-
);
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function notify(callback: (() => void) | undefined) {
|
|
40
|
-
try {
|
|
41
|
-
callback?.();
|
|
42
|
-
} catch {
|
|
43
|
-
/* Observers cannot control execution. */
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** Consume one complete model turn, never execute tools from partial events. */
|
|
48
|
-
export async function requestChildTurn(input: {
|
|
49
|
-
client: ChildModelClient;
|
|
50
|
-
model: Model<string>;
|
|
51
|
-
context: Context;
|
|
52
|
-
signal: AbortSignal;
|
|
53
|
-
sessionId: string;
|
|
54
|
-
onStart?: () => void;
|
|
55
|
-
onHeaders?: () => void;
|
|
56
|
-
onProgress?: () => void;
|
|
57
|
-
onMessage(message: AssistantMessage): void;
|
|
58
|
-
}): Promise<AssistantMessage | undefined> {
|
|
59
|
-
input.signal.throwIfAborted();
|
|
60
|
-
const bounds = requestBounds();
|
|
61
|
-
const controller = new AbortController();
|
|
62
|
-
const forward = () => controller.abort(input.signal.reason);
|
|
63
|
-
input.signal.addEventListener("abort", forward, { once: true });
|
|
64
|
-
let accepting = true;
|
|
65
|
-
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
66
|
-
const schedule = (
|
|
67
|
-
code: "first-progress-timeout" | "stream-idle-timeout",
|
|
68
|
-
ms: number,
|
|
69
|
-
) => {
|
|
70
|
-
clearTimeout(timer);
|
|
71
|
-
timer = setTimeout(() => controller.abort(new TransportTimeout(code)), ms);
|
|
72
|
-
};
|
|
73
|
-
let consume: Promise<AssistantMessage | undefined> | undefined;
|
|
74
|
-
try {
|
|
75
|
-
schedule("first-progress-timeout", bounds.firstProgressMs);
|
|
76
|
-
notify(input.onStart);
|
|
77
|
-
controller.signal.throwIfAborted();
|
|
78
|
-
const stream = input.client.streamSimple(input.model, input.context, {
|
|
79
|
-
signal: controller.signal,
|
|
80
|
-
reasoning: "low",
|
|
81
|
-
...(Number.isFinite(input.model.contextWindow) &&
|
|
82
|
-
Number.isFinite(input.model.maxTokens)
|
|
83
|
-
? {
|
|
84
|
-
maxTokens: Math.max(
|
|
85
|
-
1,
|
|
86
|
-
Math.min(
|
|
87
|
-
input.model.maxTokens,
|
|
88
|
-
Math.floor(input.model.contextWindow / 2),
|
|
89
|
-
),
|
|
90
|
-
),
|
|
91
|
-
}
|
|
92
|
-
: {}),
|
|
93
|
-
maxRetries: 0,
|
|
94
|
-
sessionId: input.sessionId,
|
|
95
|
-
onResponse: () => {
|
|
96
|
-
if (accepting && !controller.signal.aborted) notify(input.onHeaders);
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
consume = (async () => {
|
|
100
|
-
for await (const event of stream) {
|
|
101
|
-
if (!accepting) break;
|
|
102
|
-
if (event.type === "done" || event.type === "error") {
|
|
103
|
-
const final = event.type === "done" ? event.message : event.error;
|
|
104
|
-
// Cooperative cancellation may report terminal usage during bounded drain.
|
|
105
|
-
input.onMessage(final);
|
|
106
|
-
return final;
|
|
107
|
-
}
|
|
108
|
-
if (
|
|
109
|
-
!controller.signal.aborted &&
|
|
110
|
-
(event.type === "text_delta" ||
|
|
111
|
-
event.type === "thinking_delta" ||
|
|
112
|
-
event.type === "toolcall_delta") &&
|
|
113
|
-
event.delta.length > 0
|
|
114
|
-
) {
|
|
115
|
-
schedule("stream-idle-timeout", bounds.streamIdleMs);
|
|
116
|
-
notify(input.onProgress);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return undefined;
|
|
120
|
-
})();
|
|
121
|
-
return await abortable(consume, controller.signal);
|
|
122
|
-
} finally {
|
|
123
|
-
clearTimeout(timer);
|
|
124
|
-
input.signal.removeEventListener("abort", forward);
|
|
125
|
-
if (controller.signal.aborted && consume) {
|
|
126
|
-
let drainTimer: ReturnType<typeof setTimeout> | undefined;
|
|
127
|
-
await Promise.race([
|
|
128
|
-
consume.catch(() => undefined),
|
|
129
|
-
new Promise<void>((resolve) => {
|
|
130
|
-
drainTimer = setTimeout(resolve, bounds.cancellationDrainMs);
|
|
131
|
-
}),
|
|
132
|
-
]);
|
|
133
|
-
clearTimeout(drainTimer);
|
|
134
|
-
}
|
|
135
|
-
accepting = false;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/** Release only this child's provider caches/connections, never host sessions. */
|
|
140
|
-
export function disposeChildTransport(sessionId: string): void {
|
|
141
|
-
cleanupSessionResources(sessionId);
|
|
142
|
-
}
|