@miphamai/cli 0.6.8 → 0.6.9
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/index.tsx +4 -1
- package/src/tools/agent/memory.ts +20 -2
- package/src/tools/agent/workflow.ts +58 -0
- package/src/tools/index.ts +2 -0
package/package.json
CHANGED
package/src/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { App } from './ui/app'
|
|
|
4
4
|
import { loadConfig } from './config/loader'
|
|
5
5
|
import { bootstrapProviders } from './providers/bootstrap'
|
|
6
6
|
import { InstructionsLoader } from './core/instructions'
|
|
7
|
+
import { loadSessionMemories } from './core/memory/memory-loader'
|
|
7
8
|
import { ContextManager } from './core/context'
|
|
8
9
|
import { QueryEngine } from './core/engine'
|
|
9
10
|
import { SessionStore } from './core/session-store'
|
|
@@ -93,7 +94,9 @@ export async function runApp(options: RunOptions): Promise<void> {
|
|
|
93
94
|
}
|
|
94
95
|
|
|
95
96
|
if (context.getMessageCount() === 0) {
|
|
96
|
-
|
|
97
|
+
const basePrompt = instructions.buildSystemPrompt()
|
|
98
|
+
const memoryReminder = loadSessionMemories(basePrompt)
|
|
99
|
+
context.setSystemPrompt(memoryReminder ? `${basePrompt}\n\n${memoryReminder}` : basePrompt)
|
|
97
100
|
}
|
|
98
101
|
|
|
99
102
|
// Create tool registry with all built-in tools
|
|
@@ -4,6 +4,23 @@ import type { ToolDefinition } from '../../shared/index.ts'
|
|
|
4
4
|
|
|
5
5
|
const MEMORY_DIR = join(process.env.HOME || '~', '.mipham', 'memory')
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* Format a memory file with frontmatter, compatible with MemoryManager.parseMemoryFile.
|
|
9
|
+
*/
|
|
10
|
+
function formatMemory(name: string, content: string): string {
|
|
11
|
+
const desc = content.slice(0, 80).replace(/\n/g, ' ')
|
|
12
|
+
return `---
|
|
13
|
+
name: ${name}
|
|
14
|
+
description: ${desc}
|
|
15
|
+
metadata:
|
|
16
|
+
type: reference
|
|
17
|
+
relevance: []
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
${content}
|
|
21
|
+
`
|
|
22
|
+
}
|
|
23
|
+
|
|
7
24
|
export const memoryTool: ToolDefinition = {
|
|
8
25
|
name: 'Memory',
|
|
9
26
|
description: 'Read and write persistent memory files in ~/.mipham/memory/.',
|
|
@@ -27,7 +44,7 @@ export const memoryTool: ToolDefinition = {
|
|
|
27
44
|
mkdirSync(MEMORY_DIR, { recursive: true })
|
|
28
45
|
|
|
29
46
|
if (action === 'list') {
|
|
30
|
-
const files = readdirSync(MEMORY_DIR).filter((f) => f.endsWith('.md'))
|
|
47
|
+
const files = readdirSync(MEMORY_DIR).filter((f) => f.endsWith('.md') && f !== 'MEMORY.md')
|
|
31
48
|
return { success: true, content: files.join('\n') || '(no memories)' }
|
|
32
49
|
}
|
|
33
50
|
|
|
@@ -42,7 +59,8 @@ export const memoryTool: ToolDefinition = {
|
|
|
42
59
|
}
|
|
43
60
|
|
|
44
61
|
if (action === 'write') {
|
|
45
|
-
|
|
62
|
+
const body = formatMemory(name, params.content as string)
|
|
63
|
+
writeFileSync(filePath, body, 'utf-8')
|
|
46
64
|
return { success: true, content: `Memory "${name}" written` }
|
|
47
65
|
}
|
|
48
66
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { ToolDefinition } from '../../shared/index.ts'
|
|
2
|
+
import { runWorkflow } from '../../workflow/runtime'
|
|
3
|
+
import type { QueryEngine } from '../../core/engine'
|
|
4
|
+
|
|
5
|
+
export const workflowTool: ToolDefinition = {
|
|
6
|
+
name: 'Workflow',
|
|
7
|
+
description:
|
|
8
|
+
'Execute a multi-agent workflow script. The script uses agent(), parallel(), pipeline(), phase(), log(), args, budget primitives. Use for complex orchestrated tasks.',
|
|
9
|
+
category: 'agent',
|
|
10
|
+
permission: 'ask',
|
|
11
|
+
parameters: {
|
|
12
|
+
type: 'object',
|
|
13
|
+
properties: {
|
|
14
|
+
script: {
|
|
15
|
+
type: 'string',
|
|
16
|
+
description:
|
|
17
|
+
'JavaScript workflow script using agent/parallel/pipeline/phase/log/args/budget primitives',
|
|
18
|
+
},
|
|
19
|
+
args: {
|
|
20
|
+
type: 'object',
|
|
21
|
+
description: 'Arguments to pass to the workflow script as the `args` global',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
required: ['script'],
|
|
25
|
+
},
|
|
26
|
+
async execute(params, ctx) {
|
|
27
|
+
const script = params.script as string
|
|
28
|
+
const args = (params.args as Record<string, unknown>) || {}
|
|
29
|
+
|
|
30
|
+
if (!ctx.registry || !ctx.toolRegistry) {
|
|
31
|
+
return {
|
|
32
|
+
success: false,
|
|
33
|
+
content: '',
|
|
34
|
+
error: 'Workflow execution requires an active provider and tool registry.',
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Build a minimal engine-like interface for runWorkflow
|
|
39
|
+
const engineStub = {
|
|
40
|
+
getRegistry: () => ctx.registry!,
|
|
41
|
+
getTools: () => ctx.toolRegistry!,
|
|
42
|
+
} as QueryEngine
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const { runId, result } = await runWorkflow(script, engineStub, args)
|
|
46
|
+
return {
|
|
47
|
+
success: true,
|
|
48
|
+
content: `Workflow ${runId} completed.\n\nResult:\n${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}`,
|
|
49
|
+
}
|
|
50
|
+
} catch (err) {
|
|
51
|
+
return {
|
|
52
|
+
success: false,
|
|
53
|
+
content: '',
|
|
54
|
+
error: `Workflow execution failed: ${String(err)}`,
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
}
|
package/src/tools/index.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { agentTool } from './agent/agent'
|
|
|
11
11
|
import { skillTool } from './agent/skill'
|
|
12
12
|
import { planTool } from './agent/plan'
|
|
13
13
|
import { memoryTool } from './agent/memory'
|
|
14
|
+
import { workflowTool } from './agent/workflow'
|
|
14
15
|
import { webFetchTool } from './network/web-fetch'
|
|
15
16
|
import { webSearchTool } from './network/web-search'
|
|
16
17
|
import { configTool } from './system/config'
|
|
@@ -112,6 +113,7 @@ export function createToolRegistry(): Map<string, ToolDefinition> {
|
|
|
112
113
|
withValidation(skillTool),
|
|
113
114
|
withValidation(planTool),
|
|
114
115
|
withValidation(memoryTool),
|
|
116
|
+
withValidation(workflowTool),
|
|
115
117
|
// Network tools
|
|
116
118
|
withValidation(webFetchTool),
|
|
117
119
|
withValidation(webSearchTool),
|