minimal-agent 0.18.20 → 0.18.22

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 (188) hide show
  1. package/README.md +16 -3
  2. package/package.json +1 -1
  3. package/plugins/cron-runner/README.md +23 -0
  4. package/plugins/cron-runner/commands/cron.md +7 -1
  5. package/plugins/cron-runner/plugin.js +9 -2
  6. package/plugins/cron-runner/plugin.ts +10 -2
  7. package/plugins/cron-runner/src/commands.js +112 -25
  8. package/plugins/cron-runner/src/commands.ts +154 -33
  9. package/plugins/cron-runner/src/contract.js +70 -0
  10. package/plugins/cron-runner/src/contract.ts +70 -0
  11. package/plugins/cron-runner/src/requests.js +22 -13
  12. package/plugins/cron-runner/src/requests.ts +34 -14
  13. package/plugins/cron-runner/src/runs.js +63 -10
  14. package/plugins/cron-runner/src/runs.ts +107 -15
  15. package/plugins/cron-runner/src/scheduler.js +188 -76
  16. package/plugins/cron-runner/src/scheduler.ts +277 -94
  17. package/plugins/cron-runner/src/schema.js +52 -17
  18. package/plugins/cron-runner/src/schema.ts +73 -22
  19. package/plugins/cron-runner/src/service.js +29 -8
  20. package/plugins/cron-runner/src/service.ts +71 -18
  21. package/plugins/cron-runner/src/store.js +92 -30
  22. package/plugins/cron-runner/src/store.ts +156 -53
  23. package/plugins/cron-runner/src/transaction.js +24 -0
  24. package/plugins/cron-runner/src/transaction.ts +36 -0
  25. package/plugins/cron-runner/src/types.ts +30 -4
  26. package/plugins/cron-runner/test/lifecycle.test.ts +419 -0
  27. package/plugins/cron-runner/test/plugin-integration.test.ts +3 -2
  28. package/plugins/cron-runner/test/reliability.test.ts +2 -2
  29. package/plugins/cron-runner/test/store-and-scheduler.test.ts +9 -7
  30. package/plugins/workflow-runner/plugin.js +1 -0
  31. package/plugins/workflow-runner/plugin.ts +1 -0
  32. package/plugins/workflow-runner/src/index.js +1 -0
  33. package/plugins/workflow-runner/src/index.ts +2 -0
  34. package/plugins/workflow-runner/src/runner.js +6 -1
  35. package/plugins/workflow-runner/src/runner.ts +5 -1
  36. package/plugins/workflow-runner/src/types.ts +1 -0
  37. package/plugins/workflow-runner/test/api.test.ts +1 -0
  38. package/plugins/workflow-runner/test/apiCapabilities.test.ts +4 -0
  39. package/plugins/workflow-runner/test/apiConcurrencyGate.test.ts +1 -0
  40. package/plugins/workflow-runner/test/childWorkflow.test.ts +19 -0
  41. package/plugins/workflow-runner/test/embeddedExecution.test.ts +23 -3
  42. package/src/advisor/README.md +17 -6
  43. package/src/advisor/advisorNudge.js +23 -3
  44. package/src/advisor/advisorNudge.ts +20 -3
  45. package/src/advisor/deliveryReview.js +9 -2
  46. package/src/advisor/deliveryReview.ts +10 -2
  47. package/src/cli/args.js +1 -0
  48. package/src/cli/args.ts +1 -0
  49. package/src/cli/headlessTurn.js +143 -0
  50. package/src/cli/headlessTurn.ts +187 -0
  51. package/src/cli/lifecycle.js +52 -0
  52. package/src/cli/lifecycle.ts +59 -0
  53. package/src/cli/print.js +91 -240
  54. package/src/cli/print.ts +99 -301
  55. package/src/cli/quickModelSetup.js +3 -0
  56. package/src/cli/quickModelSetup.tsx +3 -0
  57. package/src/cli/streamJson.js +244 -334
  58. package/src/cli/streamJson.ts +248 -416
  59. package/src/cli/wizards/contextAdvisorWizard.js +0 -7
  60. package/src/cli/wizards/contextAdvisorWizard.tsx +0 -11
  61. package/src/cli/wizards/providerPresets.js +25 -14
  62. package/src/cli/wizards/providerPresets.ts +25 -14
  63. package/src/cli/wizards/providerWizard.js +29 -11
  64. package/src/cli/wizards/providerWizard.tsx +29 -11
  65. package/src/config/configDefaults.js +2 -2
  66. package/src/config/configDefaults.ts +2 -2
  67. package/src/config/configDiagnostics.js +7 -3
  68. package/src/config/configDiagnostics.ts +6 -3
  69. package/src/config/configFile.ts +1 -1
  70. package/src/context/compact.js +40 -10
  71. package/src/context/compact.ts +51 -12
  72. package/src/context/compactResources.js +39 -0
  73. package/src/context/compactResources.ts +35 -0
  74. package/src/context/manualCompact.js +20 -0
  75. package/src/context/manualCompact.ts +28 -0
  76. package/src/llm/client.js +4 -0
  77. package/src/llm/client.ts +4 -0
  78. package/src/llm/messageProvenance.js +1 -1
  79. package/src/llm/messageProvenance.ts +1 -1
  80. package/src/loop/README.md +4 -2
  81. package/src/loop/deliveryIntent.js +3 -2
  82. package/src/loop/deliveryIntent.ts +4 -2
  83. package/src/loop/messages.js +1 -0
  84. package/src/loop/messages.ts +1 -0
  85. package/src/loop/options.ts +2 -0
  86. package/src/loop.js +10 -2
  87. package/src/loop.ts +9 -2
  88. package/src/main.js +40 -45
  89. package/src/main.tsx +33 -52
  90. package/src/plugin-sdk.js +1 -1
  91. package/src/plugin-sdk.ts +1 -1
  92. package/src/plugins/artifactDelivery.js +76 -0
  93. package/src/plugins/artifactDelivery.ts +76 -0
  94. package/src/plugins/pluginApi.ts +4 -0
  95. package/src/plugins/pluginRunner.js +2 -0
  96. package/src/plugins/pluginRunner.ts +3 -0
  97. package/src/prompts/delegation.js +2 -2
  98. package/src/prompts/delegation.ts +2 -2
  99. package/src/prompts/policyRegistry.js +7 -5
  100. package/src/prompts/policyRegistry.ts +7 -5
  101. package/src/prompts/promptAssembly.js +2 -2
  102. package/src/prompts/promptAssembly.ts +2 -2
  103. package/src/runtime/requestIntent.js +86 -0
  104. package/src/runtime/requestIntent.ts +66 -0
  105. package/src/runtime/systemEvents.js +10 -1
  106. package/src/runtime/systemEvents.ts +9 -1
  107. package/src/session/commandTranscript.js +76 -0
  108. package/src/session/commandTranscript.ts +77 -0
  109. package/src/session/executionOutcome.js +25 -0
  110. package/src/session/executionOutcome.ts +34 -0
  111. package/src/session/runAgentTurn.js +8 -1
  112. package/src/session/runAgentTurn.ts +10 -1
  113. package/src/session/runTurn.js +40 -15
  114. package/src/session/runTurn.ts +38 -12
  115. package/src/session/sessionState.js +7 -2
  116. package/src/session/sessionState.ts +7 -2
  117. package/src/team/onlineToolContract.js +1 -0
  118. package/src/team/onlineToolContract.ts +1 -0
  119. package/src/tools/advisor/advisor.js +73 -30
  120. package/src/tools/advisor/advisor.ts +73 -33
  121. package/src/tools/advisor/advisorCoordination.js +44 -0
  122. package/src/tools/advisor/advisorCoordination.ts +45 -0
  123. package/src/tools/advisor/advisorDescription.js +1 -1
  124. package/src/tools/advisor/advisorDescription.ts +1 -1
  125. package/src/tools/agent/README.md +2 -0
  126. package/src/tools/agent/agent.js +7 -3
  127. package/src/tools/agent/agent.ts +7 -3
  128. package/src/tools/agent/agentHandoff.js +2 -1
  129. package/src/tools/agent/agentHandoff.ts +2 -1
  130. package/src/tools/agent/agentTaskService.js +26 -5
  131. package/src/tools/agent/agentTaskService.ts +25 -5
  132. package/src/tools/agent/agentTypes.js +2 -2
  133. package/src/tools/agent/agentTypes.ts +2 -2
  134. package/src/tools/agent/baselineAttach.js +14 -7
  135. package/src/tools/agent/baselineAttach.ts +14 -7
  136. package/src/tools/applypatch/applyPatch.js +39 -13
  137. package/src/tools/applypatch/applyPatch.ts +35 -15
  138. package/src/tools/bash/bash.js +3 -0
  139. package/src/tools/bash/bash.ts +3 -0
  140. package/src/tools/capabilities.js +1 -0
  141. package/src/tools/capabilities.ts +1 -0
  142. package/src/tools/download/download.js +147 -11
  143. package/src/tools/download/download.ts +193 -17
  144. package/src/tools/edit/edit.js +4 -4
  145. package/src/tools/edit/edit.ts +4 -4
  146. package/src/tools/edit/multi-edit.js +2 -2
  147. package/src/tools/edit/multi-edit.ts +2 -2
  148. package/src/tools/index.js +2 -0
  149. package/src/tools/index.ts +2 -0
  150. package/src/tools/powershell/powershell.js +2 -0
  151. package/src/tools/powershell/powershell.ts +2 -0
  152. package/src/tools/schedule/schedule.js +184 -0
  153. package/src/tools/schedule/schedule.ts +214 -0
  154. package/src/tools/shared/fileUtils.js +16 -6
  155. package/src/tools/shared/fileUtils.ts +15 -6
  156. package/src/tools/tasks/backgroundTaskService.js +108 -12
  157. package/src/tools/tasks/backgroundTaskService.ts +106 -14
  158. package/src/tools/tasks/taskOutput.js +15 -5
  159. package/src/tools/tasks/taskOutput.ts +13 -5
  160. package/src/tools/tasks/taskStop.js +2 -2
  161. package/src/tools/tasks/taskStop.ts +2 -2
  162. package/src/tools/toolPromptGuides.js +4 -3
  163. package/src/tools/toolPromptGuides.ts +4 -3
  164. package/src/tools/webfetch/webfetch.js +1 -1
  165. package/src/tools/webfetch/webfetch.ts +1 -1
  166. package/src/types.ts +6 -0
  167. package/src/ui/App.js +3 -1
  168. package/src/ui/App.tsx +2 -0
  169. package/src/ui/InputBox.js +2 -2
  170. package/src/ui/InputBox.tsx +2 -2
  171. package/src/ui/LiveArea.js +6 -1
  172. package/src/ui/LiveArea.tsx +6 -1
  173. package/src/ui/MessageList.js +2 -0
  174. package/src/ui/MessageList.tsx +2 -0
  175. package/src/ui/README.md +8 -2
  176. package/src/ui/activityPresentation.js +23 -3
  177. package/src/ui/activityPresentation.ts +22 -3
  178. package/src/ui/backgroundWake.js +20 -4
  179. package/src/ui/backgroundWake.ts +19 -4
  180. package/src/ui/commandTranscript.js +2 -69
  181. package/src/ui/commandTranscript.ts +2 -71
  182. package/src/ui/hooks/useBackgroundAgents.js +33 -0
  183. package/src/ui/hooks/useBackgroundAgents.ts +36 -0
  184. package/src/ui/hooks/useChat.js +46 -25
  185. package/src/ui/hooks/useChat.ts +36 -23
  186. package/src/web/protocol.ts +5 -2
  187. package/src/cli/wizards/advisorWizard.js +0 -152
  188. package/src/cli/wizards/advisorWizard.tsx +0 -203
@@ -0,0 +1,187 @@
1
+ import { getWorkingDir } from '../bootstrap/workingDir.js';
2
+ import { getContextPath } from '../context/persistContext.js';
3
+ import { updateSessionMetadata } from '../context/sessionRegistry.js';
4
+ import { workspaceIndexService } from '../context/workspaceIndex.js';
5
+ import { previousUserRequest } from '../memory/recallQuery.js';
6
+ import { createPromptCacheContext } from '../llm/promptCache.js';
7
+ import {
8
+ buildTransientPromptBundle,
9
+ browserPromptRuntime,
10
+ } from '../prompts/system.js';
11
+ import { refreshStableSystemPrompt } from '../prompts/stableSystemPrompt.js';
12
+ import { backgroundCompletionFields } from '../runtime/backgroundCompletion.js';
13
+ import {
14
+ createAgentRuntimeContext,
15
+ filterToolsForRuntime,
16
+ memoryContextFromRuntime,
17
+ } from '../runtime/agentRuntimeContext.js';
18
+ import { runTurn } from '../session/runTurn.js';
19
+ import {
20
+ createSessionState,
21
+ disposeDetachedSessionState,
22
+ } from '../session/sessionState.js';
23
+ import { ALL_TOOLS } from '../tools/index.js';
24
+ import { classifyComputerAutomationIntent } from '../tools/computeruse/computerIntent.js';
25
+ import { listRunningBackgroundTasks } from '../tools/tasks/backgroundTaskService.js';
26
+ import { hydrateSessionWorktree } from '../tools/worktree/sessionWorktree.js';
27
+ import type { ImageInputSpec, LoopEvent, Provider } from '../types.js';
28
+ import type { PluginEvent } from '../plugins/pluginApi.js';
29
+ import { createLocalBrowserScope, type BrowserCliMode } from './browser.js';
30
+ import {
31
+ createCliComputerRun,
32
+ type ComputerUseCliMode,
33
+ } from './computerUse.js';
34
+
35
+ export interface HeadlessOptions {
36
+ maxTurns?: number;
37
+ sessionFile?: string;
38
+ workspace?: { cwd: string; sessionId: string };
39
+ memoryAccess?: import('../runtime/agentRuntimeContext.js').MemoryAccessInput;
40
+ computerUseMode?: ComputerUseCliMode;
41
+ computerUseTraceDir?: string;
42
+ browserMode?: BrowserCliMode;
43
+ }
44
+
45
+ /** Both print transports use the same locked, journalled user-turn lifecycle. */
46
+ export async function* runHeadlessTurn(
47
+ provider: Provider,
48
+ prompt: string,
49
+ options: HeadlessOptions & {
50
+ signal: AbortSignal;
51
+ interactive: boolean;
52
+ host: 'cli' | 'stream-json';
53
+ imageInputs?: ImageInputSpec[];
54
+ imageDetail?: ImageInputSpec['detail'];
55
+ imageMaxLongSidePixel?: number;
56
+ },
57
+ ): AsyncGenerator<LoopEvent | PluginEvent> {
58
+ const sessionState = createSessionState();
59
+ const browsers = createLocalBrowserScope();
60
+ const cwdRoot = options.workspace?.cwd ?? getWorkingDir();
61
+ const sessionId = options.workspace?.sessionId ?? 'default';
62
+ let terminal: LoopEvent | PluginEvent | undefined;
63
+ let failed = false;
64
+ for await (const event of runTurn({
65
+ userInput: prompt,
66
+ provider,
67
+ sessionFile: options.sessionFile ?? getContextPath(),
68
+ strictPersistence: true,
69
+ signal: options.signal,
70
+ maxTurns: options.maxTurns,
71
+ imageInputs: options.imageInputs,
72
+ parseInlineImages: true,
73
+ imageDetail: options.imageDetail,
74
+ imageMaxLongSidePixel: options.imageMaxLongSidePixel,
75
+ prepare: async (history) => {
76
+ const workspace = await workspaceIndexService.register(
77
+ cwdRoot,
78
+ previousUserRequest(history) ?? prompt,
79
+ );
80
+ await hydrateSessionWorktree({
81
+ sessionState,
82
+ workspaceId: workspace.id,
83
+ sessionId,
84
+ cwd: cwdRoot,
85
+ });
86
+ const cwd = sessionState.activeWorktree?.path ?? cwdRoot;
87
+ const conversationKey = `workspace:${workspace.id}:session:${sessionId}`;
88
+ const computerRun =
89
+ options.computerUseMode && options.computerUseMode !== 'disabled'
90
+ ? createCliComputerRun({
91
+ mode: options.computerUseMode,
92
+ surface: 'cli',
93
+ conversationKey,
94
+ userInput: prompt,
95
+ allowedFileRoots: [cwd],
96
+ supervised: options.interactive,
97
+ diagnosticTraceDir: options.computerUseTraceDir,
98
+ })
99
+ : undefined;
100
+ const runtimeContext = createAgentRuntimeContext({
101
+ surface: options.host === 'cli' ? 'cli' : 'headless',
102
+ host: options.host,
103
+ profile: 'main',
104
+ cwd,
105
+ workspaceId: workspace.id,
106
+ sessionId,
107
+ owner: options.memoryAccess === 'denied' ? 'untrusted' : 'local-owner',
108
+ memoryAccess: options.memoryAccess ?? 'read-only',
109
+ interactiveAsk: options.interactive,
110
+ browser: await browsers.resolve({
111
+ mode: options.browserMode ?? 'headless',
112
+ conversationKey,
113
+ userInput: prompt,
114
+ allowedUploadRoots: [cwd],
115
+ }),
116
+ computer: computerRun,
117
+ computerIntent: classifyComputerAutomationIntent(
118
+ prompt,
119
+ sessionState.computerAutomation,
120
+ ),
121
+ });
122
+ const tools = filterToolsForRuntime(ALL_TOOLS, runtimeContext);
123
+ await refreshStableSystemPrompt(history, cwd, tools);
124
+ const transientBundle = await buildTransientPromptBundle({
125
+ cwd,
126
+ tools,
127
+ runtime: {
128
+ surface: runtimeContext.surface,
129
+ host: options.host,
130
+ cwd,
131
+ workspaceId: workspace.id,
132
+ sessionId,
133
+ interactiveAsk: options.interactive,
134
+ memoryAccess: runtimeContext.memoryAccess,
135
+ browser: browserPromptRuntime(
136
+ runtimeContext.browser,
137
+ provider.supportsVision,
138
+ ),
139
+ currentUserInput: prompt,
140
+ previousUserInput: previousUserRequest(history),
141
+ contextWindow: provider.contextWindow,
142
+ },
143
+ });
144
+ await updateSessionMetadata(cwdRoot, sessionId, {
145
+ lastMessagePreview: prompt,
146
+ }).catch(() => {});
147
+ return {
148
+ runtimeContext,
149
+ sessionState,
150
+ computerRun,
151
+ transientBundle,
152
+ allowedTools: tools.map((tool) => tool.name),
153
+ promptCache: createPromptCacheContext(conversationKey),
154
+ memoryContext: memoryContextFromRuntime(runtimeContext),
155
+ };
156
+ },
157
+ cleanup: async () => {
158
+ try {
159
+ await disposeDetachedSessionState(sessionState);
160
+ } finally {
161
+ await browsers.dispose();
162
+ }
163
+ },
164
+ })) {
165
+ if (event.type === 'error' && event.code !== 'compact_failed')
166
+ failed = true;
167
+ if (event.type === 'turn_done') {
168
+ terminal = {
169
+ ...event,
170
+ ...backgroundCompletionFields(sessionState.backgroundTasks),
171
+ };
172
+ const running = listRunningBackgroundTasks(sessionState.backgroundTasks);
173
+ if (running.length)
174
+ yield {
175
+ type: 'warning',
176
+ message:
177
+ `${running.length} 个后台任务尚未完成,本次 CLI 收尾将终止它们,其结果未经验证:` +
178
+ running
179
+ .map((task) => `${task.id}(${task.command.slice(0, 80)})`)
180
+ .join(';'),
181
+ };
182
+ } else yield event;
183
+ }
184
+ // A terminal success is only published after persistence and resource cleanup.
185
+ options.signal.throwIfAborted();
186
+ if (terminal && !failed) yield terminal;
187
+ }
@@ -0,0 +1,52 @@
1
+ /** Signal handlers only request cancellation. The owning turn saves and exits. */
2
+ export function createCliLifecycle() {
3
+ const controller = new AbortController();
4
+ let exitCode;
5
+ const interrupt = () => {
6
+ exitCode ??= 130;
7
+ controller.abort(new DOMException('Interrupted', 'AbortError'));
8
+ };
9
+ const terminate = () => {
10
+ exitCode ??= 143;
11
+ controller.abort(new DOMException('Terminated', 'AbortError'));
12
+ };
13
+ const outputError = (error) => {
14
+ exitCode ??= 1;
15
+ controller.abort(error);
16
+ };
17
+ process.on('SIGINT', interrupt);
18
+ process.on('SIGTERM', terminate);
19
+ process.stdout.on('error', outputError);
20
+ process.stderr.on('error', outputError);
21
+ return {
22
+ signal: controller.signal,
23
+ fail(error) {
24
+ exitCode ??= 1;
25
+ controller.abort(error);
26
+ },
27
+ get exitCode() {
28
+ return exitCode;
29
+ },
30
+ dispose() {
31
+ process.removeListener('SIGINT', interrupt);
32
+ process.removeListener('SIGTERM', terminate);
33
+ process.stdout.removeListener('error', outputError);
34
+ process.stderr.removeListener('error', outputError);
35
+ },
36
+ };
37
+ }
38
+ /** Wait for queued protocol output before removing error handlers or exiting. */
39
+ export async function flushCliOutput() {
40
+ await Promise.all([process.stdout, process.stderr].map((stream) => new Promise((resolve) => {
41
+ if (stream.destroyed ||
42
+ !stream.writable ||
43
+ stream.writableLength === 0)
44
+ return resolve();
45
+ try {
46
+ stream.write('', () => resolve());
47
+ }
48
+ catch {
49
+ resolve();
50
+ }
51
+ })));
52
+ }
@@ -0,0 +1,59 @@
1
+ /** Signal handlers only request cancellation. The owning turn saves and exits. */
2
+ export function createCliLifecycle() {
3
+ const controller = new AbortController();
4
+ let exitCode: number | undefined;
5
+ const interrupt = () => {
6
+ exitCode ??= 130;
7
+ controller.abort(new DOMException('Interrupted', 'AbortError'));
8
+ };
9
+ const terminate = () => {
10
+ exitCode ??= 143;
11
+ controller.abort(new DOMException('Terminated', 'AbortError'));
12
+ };
13
+ const outputError = (error: NodeJS.ErrnoException) => {
14
+ exitCode ??= 1;
15
+ controller.abort(error);
16
+ };
17
+ process.on('SIGINT', interrupt);
18
+ process.on('SIGTERM', terminate);
19
+ process.stdout.on('error', outputError);
20
+ process.stderr.on('error', outputError);
21
+ return {
22
+ signal: controller.signal,
23
+ fail(error: Error) {
24
+ exitCode ??= 1;
25
+ controller.abort(error);
26
+ },
27
+ get exitCode() {
28
+ return exitCode;
29
+ },
30
+ dispose() {
31
+ process.removeListener('SIGINT', interrupt);
32
+ process.removeListener('SIGTERM', terminate);
33
+ process.stdout.removeListener('error', outputError);
34
+ process.stderr.removeListener('error', outputError);
35
+ },
36
+ };
37
+ }
38
+
39
+ /** Wait for queued protocol output before removing error handlers or exiting. */
40
+ export async function flushCliOutput(): Promise<void> {
41
+ await Promise.all(
42
+ [process.stdout, process.stderr].map(
43
+ (stream) =>
44
+ new Promise<void>((resolve) => {
45
+ if (
46
+ stream.destroyed ||
47
+ !stream.writable ||
48
+ stream.writableLength === 0
49
+ )
50
+ return resolve();
51
+ try {
52
+ stream.write('', () => resolve());
53
+ } catch {
54
+ resolve();
55
+ }
56
+ }),
57
+ ),
58
+ );
59
+ }