@miphamai/cli 0.85.22 → 0.85.24
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 +1 -1
- package/bin/mipham.ts +40 -13
- package/package.json +1 -1
- package/src/agent/agent-context.ts +19 -6
- package/src/agent/agent-registry.ts +42 -2
- package/src/agent/message-router.ts +30 -0
- package/src/agent/sub-agent.ts +17 -0
- package/src/config/loader.ts +41 -0
- package/src/core/context-microcompact.ts +1 -1
- package/src/core/context.ts +167 -10
- package/src/core/cron-poller.ts +74 -6
- package/src/core/engine.ts +34 -7
- package/src/core/hooks-config.ts +4 -0
- package/src/core/hooks-executor.ts +96 -28
- package/src/core/hooks.ts +49 -3
- package/src/core/permission-rules.ts +32 -2
- package/src/core/safe-mode.ts +11 -0
- package/src/core/session-exit.ts +73 -0
- package/src/core/session-log.ts +36 -1
- package/src/daemon/engine-capabilities.ts +13 -4
- package/src/daemon/launch.ts +37 -0
- package/src/daemon/server.ts +9 -1
- package/src/i18n-core/locales/en-US.json +1 -0
- package/src/i18n-core/locales/zh-CN.json +1 -0
- package/src/index.tsx +68 -27
- package/src/mcp/client.ts +22 -8
- package/src/mcp/http-transport.ts +19 -4
- package/src/mcp/registry.ts +40 -5
- package/src/plugin/plugin-loader.ts +4 -0
- package/src/providers/anthropic.ts +8 -2
- package/src/providers/openai-compat.ts +14 -2
- package/src/shared/arg-validation.ts +2 -1
- package/src/shared/package-info.ts +2 -2
- package/src/shared/types.ts +18 -0
- package/src/skills/loader.ts +86 -4
- package/src/tools/agent/workflow.ts +9 -2
- package/src/tools/exec/bash.ts +38 -11
- package/src/tools/exec/exit-worktree.ts +45 -4
- package/src/tools/file/read.ts +16 -2
- package/src/tools/network/web-fetch.ts +11 -3
- package/src/tools/network/web-search.ts +5 -1
- package/src/tools/scheduling/cron.ts +2 -1
- package/src/tools/scheduling/schedule-wakeup.ts +23 -8
- package/src/tools/validation.ts +11 -0
- package/src/ui/app.tsx +6 -5
- package/src/ui/commands.ts +17 -8
- package/src/workflow/primitives/agent.ts +34 -5
- package/src/workflow/primitives/verify.ts +36 -20
- package/src/workflow/runtime.ts +10 -2
|
@@ -11,15 +11,33 @@
|
|
|
11
11
|
* picks the winner, and optionally synthesizes a final result.
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import { workflowAgent } from './agent'
|
|
15
14
|
import { parallel } from './parallel'
|
|
16
|
-
import type { WorkflowAgentOpts } from './agent'
|
|
17
15
|
|
|
18
|
-
// Agent function signature matching the sandbox-injected
|
|
19
|
-
// (prompt, opts?) → result.
|
|
20
|
-
//
|
|
21
|
-
|
|
22
|
-
|
|
16
|
+
// Agent function signature matching the sandbox-injected `agent`:
|
|
17
|
+
// (prompt, opts?) → result. The workflow runtime passes its own wrapped agent
|
|
18
|
+
// in, so every verify()/judge() fan-out is journaled and replayable on resume.
|
|
19
|
+
export type AgentFn = (prompt: string, opts?: Record<string, unknown>) => Promise<unknown>
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* These primitives must run **inside** a workflow run.
|
|
23
|
+
*
|
|
24
|
+
* The run's `agent` is what makes an agent call journaled (so resume replays it
|
|
25
|
+
* instead of re-running) and what binds the provider registry, tools and
|
|
26
|
+
* permission system. Without it there is no sensible fallback: calling the raw
|
|
27
|
+
* `workflowAgent` here would need a registry positionally, so it would either
|
|
28
|
+
* crash or — worse — run unbudgeted and unjournaled, and every resumed run
|
|
29
|
+
* would re-run all of its skeptics.
|
|
30
|
+
*/
|
|
31
|
+
function resolveAgent(opts: { agent?: AgentFn; _mockAgent?: AgentFn }): AgentFn {
|
|
32
|
+
const fn = opts.agent ?? opts._mockAgent
|
|
33
|
+
if (!fn) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"verify()/judge() need the run's agent(): they are only callable inside a workflow run, " +
|
|
36
|
+
'where the runtime injects it.',
|
|
37
|
+
)
|
|
38
|
+
}
|
|
39
|
+
return fn
|
|
40
|
+
}
|
|
23
41
|
|
|
24
42
|
// ── Types ──
|
|
25
43
|
|
|
@@ -39,8 +57,10 @@ export interface VerifyOpts {
|
|
|
39
57
|
voters?: number // consensus: default 3
|
|
40
58
|
threshold?: number
|
|
41
59
|
schema: Record<string, unknown>
|
|
42
|
-
/**
|
|
43
|
-
|
|
60
|
+
/** Injected by the workflow runtime: the run's wrapped `agent` (journal + resume cache). */
|
|
61
|
+
agent?: AgentFn
|
|
62
|
+
/** Test-only: inject a mock agent function. */
|
|
63
|
+
_mockAgent?: AgentFn
|
|
44
64
|
}
|
|
45
65
|
|
|
46
66
|
interface VerdictVote {
|
|
@@ -67,8 +87,10 @@ export interface JudgeOpts {
|
|
|
67
87
|
judges?: number // default: 3
|
|
68
88
|
synthesize?: boolean // default: true
|
|
69
89
|
schema: Record<string, unknown>
|
|
90
|
+
/** Injected by the workflow runtime: the run's wrapped `agent` (journal + resume cache). */
|
|
91
|
+
agent?: AgentFn
|
|
70
92
|
/** Test-only: inject a mock agent function. */
|
|
71
|
-
_mockAgent?:
|
|
93
|
+
_mockAgent?: AgentFn
|
|
72
94
|
}
|
|
73
95
|
|
|
74
96
|
// ── Helpers ──
|
|
@@ -82,10 +104,7 @@ function defaultThreshold(mode: VerifyMode, total: number): number {
|
|
|
82
104
|
// ── verify() ──
|
|
83
105
|
|
|
84
106
|
export async function verify(finding: unknown, opts: VerifyOpts): Promise<VerifyResult> {
|
|
85
|
-
|
|
86
|
-
// In production sandbox usage, _mockAgent is set to the pre-bound agent
|
|
87
|
-
// function injected by the workflow runtime.
|
|
88
|
-
const agentFn: AgentFn = opts._mockAgent ?? (workflowAgent as unknown as AgentFn)
|
|
107
|
+
const agentFn = resolveAgent(opts)
|
|
89
108
|
const mode = opts.mode
|
|
90
109
|
|
|
91
110
|
const findingStr = JSON.stringify(finding, null, 2)
|
|
@@ -126,9 +145,7 @@ export async function verify(finding: unknown, opts: VerifyOpts): Promise<Verify
|
|
|
126
145
|
|
|
127
146
|
// Fan out all agent calls concurrently
|
|
128
147
|
const rawVotes = await parallel(
|
|
129
|
-
prompts.map(
|
|
130
|
-
(p) => () => agentFn(p.prompt, { schema: opts.schema as WorkflowAgentOpts['schema'] }),
|
|
131
|
-
),
|
|
148
|
+
prompts.map((p) => () => agentFn(p.prompt, { schema: opts.schema })),
|
|
132
149
|
)
|
|
133
150
|
|
|
134
151
|
// Filter out failed agents (null) and build vote objects
|
|
@@ -160,8 +177,7 @@ export async function verify(finding: unknown, opts: VerifyOpts): Promise<Verify
|
|
|
160
177
|
// ── judge() ──
|
|
161
178
|
|
|
162
179
|
export async function judge(attempts: unknown[], opts: JudgeOpts): Promise<JudgeResult> {
|
|
163
|
-
|
|
164
|
-
const agentFn: AgentFn = opts._mockAgent ?? (workflowAgent as unknown as AgentFn)
|
|
180
|
+
const agentFn = resolveAgent(opts)
|
|
165
181
|
const judgeCount = opts.judges ?? 3
|
|
166
182
|
const schemaDesc = JSON.stringify(opts.schema)
|
|
167
183
|
|
|
@@ -198,7 +214,7 @@ export async function judge(attempts: unknown[], opts: JudgeOpts): Promise<Judge
|
|
|
198
214
|
`You are judge #${sp.judgeIndex + 1}. Score this attempt against the criteria: ${opts.criteria.join(', ')}.\n\n` +
|
|
199
215
|
`Attempt:\n${JSON.stringify(sp.attempt, null, 2)}\n\n` +
|
|
200
216
|
`Return JSON matching this schema:\n${schemaDesc}`,
|
|
201
|
-
{ schema: opts.schema
|
|
217
|
+
{ schema: opts.schema },
|
|
202
218
|
),
|
|
203
219
|
),
|
|
204
220
|
)
|
package/src/workflow/runtime.ts
CHANGED
|
@@ -223,8 +223,16 @@ export async function runWorkflow(
|
|
|
223
223
|
sandboxCtx.agent = sealValue(agent)
|
|
224
224
|
sandboxCtx.parallel = sealValue(parallel)
|
|
225
225
|
sandboxCtx.pipeline = sealValue(pipeline)
|
|
226
|
-
|
|
227
|
-
|
|
226
|
+
// verify()/judge() fan out their own agent calls, so they need the run's agent
|
|
227
|
+
// too. Handing them the bare primitive would put those calls outside the
|
|
228
|
+
// journal and the resume cache: a resumed run would replay every agent() it
|
|
229
|
+
// can see and then silently re-run all of verify's skeptics and judge's scores.
|
|
230
|
+
sandboxCtx.verify = sealValue((finding: unknown, opts: Record<string, unknown> = {}) =>
|
|
231
|
+
verify(finding, { ...opts, agent } as Parameters<typeof verify>[1]),
|
|
232
|
+
)
|
|
233
|
+
sandboxCtx.judge = sealValue((attempts: unknown[], opts: Record<string, unknown> = {}) =>
|
|
234
|
+
judge(attempts, { ...opts, agent } as Parameters<typeof judge>[1]),
|
|
235
|
+
)
|
|
228
236
|
sandboxCtx.loopUntilConvergence = sealValue(loopUntilConvergence)
|
|
229
237
|
sandboxCtx.phase = sealValue(wrappedPhase)
|
|
230
238
|
sandboxCtx.log = sealValue(log)
|