u-foo 2.5.15 → 3.0.1
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/package.json +1 -1
- package/src/code/agent.js +350 -246
- package/src/code/commands.js +16 -0
- package/src/code/context/assembler.js +18 -13
- package/src/code/context/executionSegment.js +102 -119
- package/src/code/context/index.js +11 -1
- package/src/code/context/planGraph.js +1410 -0
- package/src/code/context/planGraphService.js +857 -0
- package/src/code/context/planMode.js +405 -0
- package/src/code/context/planProjection.js +432 -0
- package/src/code/context/promptLayers.js +21 -5
- package/src/code/context/stateCommit.js +2 -0
- package/src/code/context/toolRuntime.js +172 -0
- package/src/code/context/userInteraction.js +457 -0
- package/src/code/context/userNudge.js +116 -0
- package/src/code/dispatch.js +17 -1
- package/src/code/index.js +4 -0
- package/src/code/nativeRunner.js +589 -172
- package/src/code/protocol/controlPlane.js +93 -0
- package/src/code/protocol/faultHarness.js +90 -0
- package/src/code/protocol/index.js +20 -0
- package/src/code/protocol/loopEvents.js +102 -0
- package/src/code/protocol/materialize.js +107 -0
- package/src/code/protocol/messageFixtures.js +116 -0
- package/src/code/protocol/ownership.js +147 -0
- package/src/code/protocol/protocolValidator.js +165 -0
- package/src/code/protocol/suspension.js +173 -0
- package/src/code/protocol/toolCallLedger.js +222 -0
- package/src/code/protocol/transitions.js +97 -0
- package/src/code/providers/anthropicMessagesTransport.js +93 -0
- package/src/code/providers/index.js +7 -0
- package/src/code/providers/openaiChatTransport.js +98 -0
- package/src/code/providers/transportContract.js +46 -0
- package/src/code/repl.js +147 -18
- package/src/code/runtime/agentWakeup.js +58 -0
- package/src/code/runtime/graphOwner.js +41 -0
- package/src/code/runtime/graphYieldRouter.js +42 -0
- package/src/code/runtime/index.js +15 -0
- package/src/code/runtime/loopMailbox.js +124 -0
- package/src/code/runtime/runtimeEvents.js +39 -0
- package/src/code/runtime/taskControl.js +565 -0
- package/src/code/runtime/taskFocus.js +165 -0
- package/src/code/runtime/taskLoop.js +394 -0
- package/src/code/runtime/taskRun.js +348 -0
- package/src/code/runtime/toolProvenance.js +70 -0
- package/src/code/runtime/workspaceLease.js +249 -0
- package/src/code/sessionStore.js +1 -10
- package/src/code/skills/injection.js +1 -0
- package/src/code/taskDecomposer.js +32 -8
- package/src/code/taskRoute.js +73 -0
- package/src/code/tools/askUser.js +11 -0
- package/src/code/tools/planGraph.js +29 -0
- package/src/ui/format/index.js +25 -1
- package/src/ui/format/markdownRenderer.js +224 -2
- package/src/ui/ink/UcodeApp.js +268 -22
- package/src/code/context/featureFlag.js +0 -13
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Typed mailboxes for Agent Loop vs TaskLoop.
|
|
5
|
+
* Task mailbox schema has no user-event type (runtime isolation).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { isRuntimeEvent } = require("./runtimeEvents");
|
|
9
|
+
|
|
10
|
+
const AGENT_EVENT_KINDS = Object.freeze(["user", "runtime"]);
|
|
11
|
+
const TASK_EVENT_KINDS = Object.freeze([
|
|
12
|
+
"graph_yield",
|
|
13
|
+
"tool_result",
|
|
14
|
+
"control",
|
|
15
|
+
"advance",
|
|
16
|
+
"model_turn",
|
|
17
|
+
]);
|
|
18
|
+
|
|
19
|
+
function emptyMailbox() {
|
|
20
|
+
return { queue: [], seq: 0 };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function ensureMailbox(store = null, key = "mailbox") {
|
|
24
|
+
const target = store && typeof store === "object" ? store : {};
|
|
25
|
+
if (!target[key] || typeof target[key] !== "object") {
|
|
26
|
+
target[key] = emptyMailbox();
|
|
27
|
+
}
|
|
28
|
+
if (!Array.isArray(target[key].queue)) target[key].queue = [];
|
|
29
|
+
if (!Number.isFinite(target[key].seq)) target[key].seq = 0;
|
|
30
|
+
return target[key];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function enqueue(mailbox = null, event = {}) {
|
|
34
|
+
const box = mailbox && typeof mailbox === "object" ? mailbox : emptyMailbox();
|
|
35
|
+
if (!Array.isArray(box.queue)) box.queue = [];
|
|
36
|
+
box.seq = (Number(box.seq) || 0) + 1;
|
|
37
|
+
const entry = {
|
|
38
|
+
id: `evt_${box.seq}`,
|
|
39
|
+
enqueuedAt: new Date().toISOString(),
|
|
40
|
+
...event,
|
|
41
|
+
};
|
|
42
|
+
box.queue.push(entry);
|
|
43
|
+
return entry;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function drain(mailbox = null, { max = 0 } = {}) {
|
|
47
|
+
const box = mailbox && typeof mailbox === "object" ? mailbox : emptyMailbox();
|
|
48
|
+
if (!Array.isArray(box.queue) || box.queue.length === 0) return [];
|
|
49
|
+
if (!max || max >= box.queue.length) {
|
|
50
|
+
const all = box.queue.slice();
|
|
51
|
+
box.queue = [];
|
|
52
|
+
return all;
|
|
53
|
+
}
|
|
54
|
+
const taken = box.queue.splice(0, Math.max(1, Math.floor(max)));
|
|
55
|
+
return taken;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function peek(mailbox = null) {
|
|
59
|
+
const box = mailbox && typeof mailbox === "object" ? mailbox : emptyMailbox();
|
|
60
|
+
return Array.isArray(box.queue) && box.queue.length > 0 ? box.queue[0] : null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function enqueueAgentUser(executionState = null, text = "") {
|
|
64
|
+
const state = executionState && typeof executionState === "object" ? executionState : {};
|
|
65
|
+
const mailbox = ensureMailbox(state, "agentMailbox");
|
|
66
|
+
return enqueue(mailbox, {
|
|
67
|
+
kind: "user",
|
|
68
|
+
text: String(text || "").trim(),
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function enqueueAgentRuntime(executionState = null, runtimeEvent = {}) {
|
|
73
|
+
if (!isRuntimeEvent(runtimeEvent)) {
|
|
74
|
+
throw new Error("enqueueAgentRuntime requires a runtime event");
|
|
75
|
+
}
|
|
76
|
+
const state = executionState && typeof executionState === "object" ? executionState : {};
|
|
77
|
+
const mailbox = ensureMailbox(state, "agentMailbox");
|
|
78
|
+
return enqueue(mailbox, {
|
|
79
|
+
kind: "runtime",
|
|
80
|
+
event: runtimeEvent,
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function enqueueTaskEvent(executionState = null, taskRunId = "", event = {}) {
|
|
85
|
+
const state = executionState && typeof executionState === "object" ? executionState : {};
|
|
86
|
+
if (!state.taskMailboxes || typeof state.taskMailboxes !== "object") {
|
|
87
|
+
state.taskMailboxes = {};
|
|
88
|
+
}
|
|
89
|
+
const id = String(taskRunId || "").trim();
|
|
90
|
+
if (!id) throw new Error("taskRunId required");
|
|
91
|
+
const kind = String(event.kind || "").trim();
|
|
92
|
+
if (!TASK_EVENT_KINDS.includes(kind)) {
|
|
93
|
+
throw new Error(`invalid task mailbox event kind: ${kind}`);
|
|
94
|
+
}
|
|
95
|
+
if (!state.taskMailboxes[id]) state.taskMailboxes[id] = emptyMailbox();
|
|
96
|
+
return enqueue(state.taskMailboxes[id], event);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function drainAgentMailbox(executionState = null, options = {}) {
|
|
100
|
+
const state = executionState && typeof executionState === "object" ? executionState : {};
|
|
101
|
+
return drain(ensureMailbox(state, "agentMailbox"), options);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function drainTaskMailbox(executionState = null, taskRunId = "", options = {}) {
|
|
105
|
+
const state = executionState && typeof executionState === "object" ? executionState : {};
|
|
106
|
+
const id = String(taskRunId || "").trim();
|
|
107
|
+
if (!state.taskMailboxes || !state.taskMailboxes[id]) return [];
|
|
108
|
+
return drain(state.taskMailboxes[id], options);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
module.exports = {
|
|
112
|
+
AGENT_EVENT_KINDS,
|
|
113
|
+
TASK_EVENT_KINDS,
|
|
114
|
+
emptyMailbox,
|
|
115
|
+
ensureMailbox,
|
|
116
|
+
enqueue,
|
|
117
|
+
drain,
|
|
118
|
+
peek,
|
|
119
|
+
enqueueAgentUser,
|
|
120
|
+
enqueueAgentRuntime,
|
|
121
|
+
enqueueTaskEvent,
|
|
122
|
+
drainAgentMailbox,
|
|
123
|
+
drainTaskMailbox,
|
|
124
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Runtime event types for Agent Loop wakeup (never user-role messages).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
const RUNTIME_EVENT_TYPES = Object.freeze([
|
|
8
|
+
"task_started",
|
|
9
|
+
"task_succeeded",
|
|
10
|
+
"task_failed",
|
|
11
|
+
"task_cancelled",
|
|
12
|
+
"parent_graph_ready_changed",
|
|
13
|
+
]);
|
|
14
|
+
|
|
15
|
+
function createRuntimeEvent(type = "", payload = {}) {
|
|
16
|
+
const eventType = String(type || "").trim();
|
|
17
|
+
if (!RUNTIME_EVENT_TYPES.includes(eventType)) {
|
|
18
|
+
throw new Error(`unknown runtime event type: ${type}`);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
type: eventType,
|
|
22
|
+
at: new Date().toISOString(),
|
|
23
|
+
...payload,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isRuntimeEvent(value = null) {
|
|
28
|
+
return Boolean(
|
|
29
|
+
value
|
|
30
|
+
&& typeof value === "object"
|
|
31
|
+
&& RUNTIME_EVENT_TYPES.includes(String(value.type || "")),
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
RUNTIME_EVENT_TYPES,
|
|
37
|
+
createRuntimeEvent,
|
|
38
|
+
isRuntimeEvent,
|
|
39
|
+
};
|