@springbrand/agent-runtime 0.3.0-alpha.1 → 0.3.0-alpha.10

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.
Files changed (107) hide show
  1. package/package.json +6 -6
  2. package/src/adapter/cloudflare/agent.ts +157 -14
  3. package/src/adapter/cloudflare/define-agent.ts +12 -7
  4. package/src/adapter/cloudflare/index.ts +18 -0
  5. package/src/adapter/cloudflare/scheduling/schedule-rule.ts +322 -0
  6. package/src/adapter/cloudflare/scheduling/zoned-cron.ts +11 -6
  7. package/src/adapter/cloudflare/schema.ts +15 -0
  8. package/src/adapter/cloudflare/subagent/definition.ts +4 -4
  9. package/src/adapter/cloudflare/subagent/runner.ts +1 -1
  10. package/src/adapter/cloudflare/subagent/tools.ts +2 -2
  11. package/src/adapter/cloudflare/universal-agent/preparation.ts +3 -3
  12. package/src/adapter/cloudflare/universal-agent/tools.ts +4 -6
  13. package/src/adapter/cloudflare/workspace/version-control.ts +1 -1
  14. package/src/config/agent-context.ts +1 -1
  15. package/src/config/assembler.ts +29 -31
  16. package/src/config/assembly-snapshot.ts +1 -1
  17. package/src/config/definition.ts +1 -1
  18. package/src/config/harness-runtime.ts +9 -1
  19. package/src/config/model-guidance.ts +21 -0
  20. package/src/config/pinning.ts +22 -3
  21. package/src/config/ports.ts +27 -7
  22. package/src/config/public-contracts.ts +2 -2
  23. package/src/context/assembly.ts +1 -1
  24. package/src/context/extension/assembly.ts +2 -2
  25. package/src/context/memory/budget/gate.ts +19 -3
  26. package/src/conversation/harness-stream.ts +2 -1
  27. package/src/conversation/message/projection.ts +38 -21
  28. package/src/conversation/state.ts +23 -2
  29. package/src/harness/session-harness.ts +86 -5
  30. package/src/index.ts +7 -7
  31. package/src/lib/artifacts.ts +18 -0
  32. package/src/lib/execution-level.ts +13 -0
  33. package/src/lib/prompt.ts +7 -6
  34. package/src/lib/token-estimate.ts +8 -0
  35. package/src/models/index.ts +1 -0
  36. package/src/session/cloudflare/migration.ts +70 -6
  37. package/src/skills/springbrand-worker-website/index.ts +1 -1
  38. package/src/submission/admission.ts +12 -1
  39. package/src/submission/contracts.ts +42 -2
  40. package/src/submission/delivery.ts +1 -1
  41. package/src/submission/finalization.ts +1 -1
  42. package/src/submission/repository.ts +64 -4
  43. package/src/submission/unattended.ts +40 -0
  44. package/src/telemetry/coordinator.ts +1 -1
  45. package/src/telemetry/subagent-lifecycle.ts +1 -1
  46. package/src/telemetry/turn-events.ts +1 -1
  47. package/src/tools/README.md +44 -0
  48. package/src/tools/{ai-adapter.ts → adapters/ai-to-pi.ts} +6 -9
  49. package/src/tools/{declared.ts → adapters/declared.ts} +6 -2
  50. package/src/tools/{nested-tools.ts → adapters/pi-to-ai.ts} +2 -2
  51. package/src/tools/assistant/ask-user.ts +317 -0
  52. package/src/tools/assistant/candidate.ts +15 -0
  53. package/src/tools/assistant/followups.ts +34 -0
  54. package/src/tools/assistant/index.ts +19 -0
  55. package/src/tools/assistant/memory.ts +73 -0
  56. package/src/tools/assistant/plan.ts +98 -0
  57. package/src/tools/{time.ts → assistant/time.ts} +1 -1
  58. package/src/tools/{core-host.ts → codemode/adapter.ts} +50 -49
  59. package/src/tools/{core.ts → codemode/index.ts} +36 -92
  60. package/src/tools/codemode/workspace-connector.ts +198 -0
  61. package/src/tools/extension/index.ts +42 -0
  62. package/src/tools/index.ts +28 -26
  63. package/src/tools/{gateway.ts → mcp/gateway.ts} +19 -19
  64. package/src/tools/{mcp.ts → mcp/index.ts} +5 -5
  65. package/src/tools/{approval → runtime/approval}/repository.ts +13 -12
  66. package/src/tools/{compiler.ts → runtime/compiler.ts} +84 -147
  67. package/src/tools/runtime/contracts.ts +117 -0
  68. package/src/tools/{decision-gate.ts → runtime/decision-gate.ts} +147 -37
  69. package/src/tools/{human-decisions.ts → runtime/human-decisions.ts} +4 -4
  70. package/src/tools/{interaction → runtime/interaction}/repository.ts +1 -7
  71. package/src/tools/runtime/result.ts +22 -0
  72. package/src/tools/runtime/unattended-error.ts +4 -0
  73. package/src/tools/sandbox/index.ts +228 -0
  74. package/src/tools/schedule/index.ts +301 -0
  75. package/src/tools/skill/contracts.ts +20 -0
  76. package/src/tools/skill/index.ts +99 -0
  77. package/src/tools/skill/resources.ts +322 -0
  78. package/src/tools/skill/scripts.ts +168 -0
  79. package/src/tools/{subagent-authority.ts → subagent/authority.ts} +31 -31
  80. package/src/tools/{subagent.ts → subagent/index.ts} +34 -37
  81. package/src/tools/{subagent-run-repository.ts → subagent/repository.ts} +1 -1
  82. package/src/tools/{subagent-runtime.ts → subagent/runtime.ts} +1 -1
  83. package/src/tools/{temporary-agent → subagent/temporary}/approvals.ts +4 -7
  84. package/src/tools/{temporary-agent → subagent/temporary}/core.ts +1 -1
  85. package/src/tools/{temporary-agent → subagent/temporary}/runner.ts +1 -1
  86. package/src/tools/{temporary-agent → subagent/temporary}/workspace.ts +1 -4
  87. package/src/tools/{web-fetch.ts → web/fetch.ts} +4 -13
  88. package/src/tools/web/index.ts +2 -0
  89. package/src/tools/web/search/api.ts +1320 -0
  90. package/src/tools/web/search/index.ts +2 -0
  91. package/src/tools/{web-search/web-search.ts → web/search/search.ts} +5 -7
  92. package/src/tools/{workspace-sandbox.ts → workspace/index.ts} +12 -272
  93. package/src/tools/{workspace-revision.ts → workspace/revision.ts} +3 -3
  94. package/src/tools/base.ts +0 -534
  95. package/src/tools/schedule.ts +0 -261
  96. package/src/tools/skill.ts +0 -565
  97. package/src/tools/web-search/api.ts +0 -1318
  98. package/src/tools/web-search/index.ts +0 -2
  99. package/src/tools/workspace-state-connector.ts +0 -146
  100. package/src/tools/{approval → runtime/approval}/index.ts +0 -0
  101. package/src/tools/{interaction → runtime/interaction}/index.ts +0 -0
  102. package/src/tools/{temporary-agent → subagent/temporary}/coordinator.ts +0 -0
  103. package/src/tools/{subagent-types → subagent/types}/contract.ts +0 -0
  104. package/src/tools/{subagent-types → subagent/types}/extract/index.ts +0 -0
  105. package/src/tools/{subagent-types → subagent/types}/fanout/index.ts +0 -0
  106. package/src/tools/{subagent-types → subagent/types}/registry.ts +1 -1
  107. /package/src/tools/{workspace-versioning.ts → workspace/versioning.ts} +0 -0
@@ -1,261 +0,0 @@
1
- import type {
2
- AgentTool,
3
- AgentToolResult,
4
- } from "@earendil-works/pi-agent-core";
5
- import { Type, type TSchema } from "@earendil-works/pi-ai";
6
- import type {
7
- RuntimeSchedulePort,
8
- RuntimeScheduleUpdate,
9
- } from "../config/ports";
10
- import type { ScheduleSpec } from "../submission/contracts";
11
- import { serializeOutput } from "../lib/artifacts";
12
- import type { PiToolCandidate } from "./compiler";
13
-
14
- const scheduleTriggerParameters = Type.Union([
15
- Type.Object({
16
- kind: Type.Literal("once-in"),
17
- seconds: Type.Integer({
18
- minimum: 1,
19
- description: "Fire once, this many seconds from now.",
20
- }),
21
- }, { additionalProperties: false }),
22
- Type.Object({
23
- kind: Type.Literal("once-at"),
24
- at: Type.String({
25
- description:
26
- "Fire once at this absolute UTC ISO time, e.g. 2026-07-20T09:00:00Z.",
27
- }),
28
- }, { additionalProperties: false }),
29
- Type.Object({
30
- kind: Type.Literal("cron"),
31
- cron: Type.String({
32
- description:
33
- "Repeat on a standard UTC cron, e.g. '0 9 * * *' = daily 09:00 UTC.",
34
- }),
35
- }, { additionalProperties: false }),
36
- Type.Object({
37
- kind: Type.Literal("interval"),
38
- seconds: Type.Integer({
39
- minimum: 1,
40
- description: "Repeat every this many seconds.",
41
- }),
42
- }, { additionalProperties: false }),
43
- ], { description: "When to fire." });
44
-
45
- const scheduleParameters = Type.Object({
46
- prompt: Type.String({
47
- description:
48
- "The standalone instruction to run when the schedule fires. The future turn has no context from this chat, so make it self-contained.",
49
- }),
50
- trigger: scheduleTriggerParameters,
51
- label: Type.String({
52
- description:
53
- "A short human-readable name for this task (e.g. '每日周报提醒'). Required — it is how the user recognises the task in their schedule list and how they will refer to it when asking you to cancel it later.",
54
- }),
55
- timezone: Type.Optional(Type.String({
56
- description:
57
- "IANA timezone the clock times in `trigger` should be interpreted in, e.g. 'Asia/Shanghai'. Pass the user's own timezone whenever they state a wall-clock time. Omit only for delays and intervals. Defaults to UTC.",
58
- })),
59
- }, { additionalProperties: false });
60
-
61
- const noParameters = Type.Object({}, { additionalProperties: false });
62
- const scheduleIdParameters = Type.Object({
63
- id: Type.String({
64
- description: "The schedule id, as returned by `list_schedules`.",
65
- }),
66
- }, { additionalProperties: false });
67
- const updateScheduleParameters = Type.Object({
68
- id: Type.String({ description: "The exact id returned by `list_schedules`." }),
69
- prompt: Type.Optional(Type.String()),
70
- trigger: Type.Optional(scheduleTriggerParameters),
71
- label: Type.Optional(Type.String()),
72
- timezone: Type.Optional(Type.String()),
73
- }, { additionalProperties: false });
74
- const changeScheduleAgentParameters = Type.Object({
75
- id: Type.String({
76
- description: "The exact schedule id returned by `list_schedules`.",
77
- }),
78
- userAgentId: Type.String({
79
- description: "The exact User Agent id selected by the user.",
80
- }),
81
- }, { additionalProperties: false });
82
-
83
- function result<T>(details: T): AgentToolResult<T> {
84
- return {
85
- content: [{ type: "text", text: serializeOutput(details).text }],
86
- details,
87
- };
88
- }
89
-
90
- function candidate<T extends TSchema>(
91
- tool: AgentTool<T>,
92
- options: Partial<
93
- Pick<
94
- PiToolCandidate,
95
- "alwaysRequiresApproval" | "exposureMode" | "owner" | "requiredExecutionLevel" | "retry" | "summary"
96
- >
97
- > = {},
98
- ): PiToolCandidate {
99
- return {
100
- owner: options.owner ?? "runtime-base",
101
- exposureMode: options.exposureMode ?? "direct",
102
- requiredExecutionLevel: options.requiredExecutionLevel ?? "safe",
103
- source: "action",
104
- tool,
105
- ...(options.alwaysRequiresApproval
106
- ? { alwaysRequiresApproval: true }
107
- : {}),
108
- ...(options.summary ? { summary: options.summary } : {}),
109
- ...(options.retry ? { retry: options.retry } : {}),
110
- };
111
- }
112
-
113
- export function schedulePiToolCandidates(
114
- schedule: RuntimeSchedulePort,
115
- ): PiToolCandidate[] {
116
- return [
117
- candidate(
118
- {
119
- name: "schedule",
120
- label: "Schedule prompt",
121
- description:
122
- "Schedule a prompt to run LATER, autonomously. Use when the user asks to be reminded, or to run something after a delay / at a time / on a recurring basis. The user always reviews the proposed schedule before it is created. The scheduled prompt runs in its own dedicated session at each trigger with NO memory of this conversation, so phrase `prompt` as a fully standalone instruction. After scheduling, tell the user what you set.",
123
- parameters: scheduleParameters,
124
- async execute(_toolCallId, input, signal) {
125
- signal?.throwIfAborted();
126
- const spec: ScheduleSpec = {
127
- trigger: input.trigger,
128
- job: { kind: "prompt", prompt: input.prompt },
129
- label: input.label,
130
- ...(input.timezone ? { tz: input.timezone } : {}),
131
- };
132
- const { id } = await schedule.create(spec);
133
- return result({ scheduled: true, id });
134
- },
135
- },
136
- {
137
- alwaysRequiresApproval: true,
138
- exposureMode: "direct",
139
- summary: "Create a scheduled task",
140
- },
141
- ),
142
- candidate(
143
- {
144
- name: "list_schedules",
145
- label: "List schedules",
146
- description:
147
- "List the user's existing scheduled tasks. Call this when the user asks what they have scheduled, or before cancelling one — you need the id, and the user will refer to a task by what it does, not by its id.",
148
- parameters: noParameters,
149
- async execute(_toolCallId, _input, signal) {
150
- signal?.throwIfAborted();
151
- return result({ schedules: await schedule.list() });
152
- },
153
- },
154
- { retry: "idempotent" },
155
- ),
156
- candidate({
157
- name: "update_schedule",
158
- label: "Update schedule",
159
- description:
160
- "Update one scheduled task without changing its id or history. Call `list_schedules` first and use an exact id. If multiple tasks plausibly match the user's wording, ask which one instead of guessing.",
161
- parameters: updateScheduleParameters,
162
- async execute(_toolCallId, input, signal) {
163
- signal?.throwIfAborted();
164
- const changes: RuntimeScheduleUpdate = {
165
- ...(input.prompt !== undefined ? { prompt: input.prompt } : {}),
166
- ...(input.trigger !== undefined ? { trigger: input.trigger } : {}),
167
- ...(input.label !== undefined ? { label: input.label } : {}),
168
- ...(input.timezone !== undefined ? { tz: input.timezone } : {}),
169
- };
170
- const { ok } = await schedule.update(input.id, changes);
171
- return result({ updated: ok, id: input.id });
172
- },
173
- }),
174
- candidate({
175
- name: "pause_schedule",
176
- label: "Pause schedule",
177
- description:
178
- "Pause one scheduled task. Call `list_schedules` first and use an exact id; ask the user if the target is ambiguous.",
179
- parameters: scheduleIdParameters,
180
- async execute(_toolCallId, input, signal) {
181
- signal?.throwIfAborted();
182
- const { ok } = await schedule.pause(input.id);
183
- return result({ paused: ok, id: input.id });
184
- },
185
- }),
186
- candidate({
187
- name: "resume_schedule",
188
- label: "Resume schedule",
189
- description:
190
- "Resume one paused scheduled task. Call `list_schedules` first and use an exact id; ask the user if the target is ambiguous.",
191
- parameters: scheduleIdParameters,
192
- async execute(_toolCallId, input, signal) {
193
- signal?.throwIfAborted();
194
- const { ok } = await schedule.resume(input.id);
195
- return result({ resumed: ok, id: input.id });
196
- },
197
- }),
198
- candidate(
199
- {
200
- name: "cancel_schedule",
201
- label: "Cancel schedule",
202
- description:
203
- "Cancel a scheduled task by id. Call `list_schedules` first to find the id that matches what the user described. If more than one plausibly matches, ask the user which one instead of guessing — cancelling is not reversible.",
204
- parameters: scheduleIdParameters,
205
- async execute(_toolCallId, input, signal) {
206
- signal?.throwIfAborted();
207
- const { ok } = await schedule.cancel(input.id);
208
- return result(ok
209
- ? { cancelled: true, id: input.id }
210
- : {
211
- cancelled: false,
212
- id: input.id,
213
- reason: "no schedule with that id",
214
- });
215
- },
216
- },
217
- {
218
- requiredExecutionLevel: "high",
219
- summary: "Cancel a scheduled task",
220
- },
221
- ),
222
- candidate(
223
- {
224
- name: "list_user_agents",
225
- label: "List User Agents",
226
- description:
227
- "List the enabled User Agents available for scheduled tasks. " +
228
- "Use this before changing a schedule Agent.",
229
- parameters: noParameters,
230
- async execute(_toolCallId, _input, signal) {
231
- signal?.throwIfAborted();
232
- return result({ agents: await schedule.listAgents() });
233
- },
234
- },
235
- { owner: "schedule-host" },
236
- ),
237
- candidate(
238
- {
239
- name: "change_schedule_agent",
240
- label: "Change schedule Agent",
241
- description:
242
- "Change which User Agent executes one scheduled task without " +
243
- "changing its id or history. Call `list_schedules` and " +
244
- "`list_user_agents` first and use exact ids; ask the user when " +
245
- "the target is ambiguous.",
246
- parameters: changeScheduleAgentParameters,
247
- async execute(_toolCallId, input, signal) {
248
- signal?.throwIfAborted();
249
- const { ok } = await schedule.changeAgent(
250
- input.id,
251
- input.userAgentId,
252
- );
253
- return result({ updated: ok, id: input.id });
254
- },
255
- },
256
- { owner: "schedule-host" },
257
- ),
258
- ];
259
- }
260
-
261
- /** 从 {@link RuntimeSchedulePort} 生成定时任务 Tool 集。 */