@miphamai/cli 0.81.6 → 0.81.8
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 +9 -9
- package/bin/daemon.ts +7 -32
- package/bin/mipham.ts +43 -29
- package/package.json +5 -2
- package/skills/standard/mipham-code-setup.SKILL.md +3 -3
- package/src/agent/sub-agent.ts +12 -1
- package/src/artifacts/manifest.ts +90 -34
- package/src/artifacts/paths.ts +19 -0
- package/src/artifacts/server.ts +48 -8
- package/src/commands/project.ts +92 -12
- package/src/config/keys-manager.ts +10 -11
- package/src/config/loader.ts +82 -1
- package/src/config/preferences.ts +5 -2
- package/src/core/context.ts +10 -2
- package/src/core/cron-poller.ts +30 -6
- package/src/core/engine.ts +19 -4
- package/src/core/metrics.ts +8 -0
- package/src/core/paths.ts +79 -0
- package/src/core/permission-rules.ts +261 -17
- package/src/core/permission.ts +3 -0
- package/src/core/session-log.ts +55 -3
- package/src/core/session-store.ts +11 -1
- package/src/daemon/engine-capabilities.ts +131 -0
- package/src/daemon/index.ts +4 -1
- package/src/daemon/launch.ts +287 -0
- package/src/daemon/remote-engine.ts +2 -0
- package/src/daemon/server.ts +9 -0
- package/src/daemon/session-worker.ts +21 -3
- package/src/i18n-core/locales/en-US.json +6 -7
- package/src/i18n-core/locales/zh-CN.json +6 -7
- package/src/index.tsx +82 -2
- package/src/mcp/client.ts +4 -2
- package/src/plugin/plugin-manager.ts +17 -6
- package/src/providers/anthropic.ts +28 -2
- package/src/providers/openai-compat.ts +14 -1
- package/src/security/path.ts +6 -1
- package/src/shared/atomic-write.ts +28 -5
- package/src/shared/package-info.ts +1 -1
- package/src/shared/types.ts +24 -0
- package/src/skills/bundled-skills.ts +1 -1
- package/src/telemetry/consent.ts +209 -0
- package/src/telemetry/crash.ts +197 -0
- package/src/telemetry/endpoint.ts +82 -0
- package/src/telemetry/index.ts +153 -0
- package/src/telemetry/payload.ts +141 -0
- package/src/telemetry/queue.ts +95 -0
- package/src/telemetry/redact.ts +127 -0
- package/src/telemetry/transport.ts +81 -0
- package/src/tools/agent/workflow.ts +11 -4
- package/src/tools/artifact/artifact.ts +14 -4
- package/src/tools/exec/bash.ts +45 -21
- package/src/tools/exec/enter-worktree.ts +6 -5
- package/src/tools/exec/exit-worktree.ts +10 -5
- package/src/tools/exec/git.ts +25 -10
- package/src/tools/file/grep.ts +37 -13
- package/src/tools/file/read.ts +151 -45
- package/src/tools/scheduling/cron.ts +34 -5
- package/src/tools/system/config.ts +9 -5
- package/src/ui/app.tsx +40 -11
- package/src/ui/commands.ts +186 -45
- package/src/workflow/primitives/agent.ts +4 -2
- package/src/artifacts/versioning.ts +0 -127
- package/src/core/task-runner-tasks.json +0 -14
- package/src/core/task-runner.ts +0 -163
- package/src/skills/mipham/runtime.ts +0 -66
- package/src/skills/standard/runtime.ts +0 -62
package/src/ui/commands.ts
CHANGED
|
@@ -16,6 +16,7 @@ import { McpClient } from '../mcp/client'
|
|
|
16
16
|
import { buildCapabilityReport } from '../core/capability-inventory'
|
|
17
17
|
import { InstructionsLoader } from '../core/instructions'
|
|
18
18
|
import { findDerivableSections, DERIVABLE_HINTS } from '../core/claude-md-audit'
|
|
19
|
+
import { worktreeRoot, workflowScriptDir, workflowScriptDirs } from '../core/paths.ts'
|
|
19
20
|
import { fixDoctor, fixConfig, fixCache, selectRepoClaudeFiles } from '../core/fix'
|
|
20
21
|
import { fixCodeTarget } from '../core/fix-code'
|
|
21
22
|
import { homedir } from 'node:os'
|
|
@@ -56,6 +57,15 @@ import { NPM_UPDATE_COMMAND, PACKAGE_VERSION, COAUTHOR_TRAILER } from '../shared
|
|
|
56
57
|
import { getPreference } from '../config/preferences'
|
|
57
58
|
import { loadCrossSessionConfig, tryRestoreFromBackup } from '../config/loader'
|
|
58
59
|
import { getMemoryManager } from '../core/memory/memory-loader'
|
|
60
|
+
import {
|
|
61
|
+
resolveTelemetry,
|
|
62
|
+
readTelemetrySettings,
|
|
63
|
+
setTelemetryEnabled,
|
|
64
|
+
setTelemetryEndpoint,
|
|
65
|
+
resetInstallId,
|
|
66
|
+
} from '../telemetry/consent'
|
|
67
|
+
import { getTelemetryConsent, enableTelemetryNow } from '../telemetry/index'
|
|
68
|
+
import { NO_ENDPOINT } from '../telemetry/endpoint'
|
|
59
69
|
import { stripIndent } from './strip-indent.js'
|
|
60
70
|
import { createT } from '../i18n-core/t'
|
|
61
71
|
import type { TranslationMap } from '../i18n-core/types'
|
|
@@ -251,7 +261,7 @@ const helpCmd: CommandHandler = (ctx) => {
|
|
|
251
261
|
/init Initialize .mipham config
|
|
252
262
|
/setup Guided project setup wizard
|
|
253
263
|
/recommend Analyze project + recommend setup
|
|
254
|
-
/permissions Show permission
|
|
264
|
+
/permissions Show or persist permission rules
|
|
255
265
|
/add-dir <dir> Add workspace directory
|
|
256
266
|
/security Security review checklist
|
|
257
267
|
/audit Same as /security
|
|
@@ -2076,8 +2086,8 @@ const todosCmd: CommandHandler = (_ctx, args) => {
|
|
|
2076
2086
|
return { content: t('commands.todos.usage_create') }
|
|
2077
2087
|
}
|
|
2078
2088
|
return {
|
|
2079
|
-
content: `${t('commands.todos.create_title')}\n\nCreating task: "${title.trim()}"\n\nPassing to AI for structured task creation with
|
|
2080
|
-
forwardToAI: `Create a new task using
|
|
2089
|
+
content: `${t('commands.todos.create_title')}\n\nCreating task: "${title.trim()}"\n\nPassing to AI for structured task creation with the Task tool...`,
|
|
2090
|
+
forwardToAI: `Create a new task using the Task tool with action "create" and subject "${title.trim()}". Set a clear description and activeForm.`,
|
|
2081
2091
|
}
|
|
2082
2092
|
}
|
|
2083
2093
|
|
|
@@ -2092,7 +2102,7 @@ const todosCmd: CommandHandler = (_ctx, args) => {
|
|
|
2092
2102
|
${t('commands.todos.item_create')}
|
|
2093
2103
|
`,
|
|
2094
2104
|
forwardToAI:
|
|
2095
|
-
'Use
|
|
2105
|
+
'Use the Task tool with action "list" to show all current tasks. Present them in a clear summary grouped by status (pending/in_progress/completed). If there are no tasks, suggest creating one.',
|
|
2096
2106
|
}
|
|
2097
2107
|
}
|
|
2098
2108
|
|
|
@@ -2104,7 +2114,8 @@ const todosCmd: CommandHandler = (_ctx, args) => {
|
|
|
2104
2114
|
|
|
2105
2115
|
${t('commands.todos.default_body')}
|
|
2106
2116
|
`,
|
|
2107
|
-
forwardToAI:
|
|
2117
|
+
forwardToAI:
|
|
2118
|
+
'Use the Task tool with action "list" to show all current tasks, then present them clearly.',
|
|
2108
2119
|
}
|
|
2109
2120
|
}
|
|
2110
2121
|
|
|
@@ -2192,7 +2203,7 @@ const goalCmd: CommandHandler = (ctx, args) => {
|
|
|
2192
2203
|
if (decompose) {
|
|
2193
2204
|
lines.push(t('commands.goal.decompose_enabled'))
|
|
2194
2205
|
// Decompose by creating initial subtasks
|
|
2195
|
-
const decomposeMsg = `Break down this goal into 3-5 subtasks: "${goal}". For each subtask, use
|
|
2206
|
+
const decomposeMsg = `Break down this goal into 3-5 subtasks: "${goal}". For each subtask, use the Task tool with action "create", giving the subject and description. Mark each as blocked by the previous one to create a dependency chain.`
|
|
2196
2207
|
return {
|
|
2197
2208
|
content: lines.join('\n'),
|
|
2198
2209
|
forwardToAI: decomposeMsg,
|
|
@@ -2813,12 +2824,12 @@ const tasksCmd: CommandHandler = (ctx) => {
|
|
|
2813
2824
|
const c = ctx.engine.getContext()
|
|
2814
2825
|
const msgs = c.getMessages()
|
|
2815
2826
|
|
|
2816
|
-
// Scan for task-related tool uses in message history
|
|
2827
|
+
// Scan for task-related tool uses in message history.
|
|
2828
|
+
// 任务工具只有一个 `Task`,动作走 action 参数 —— 过滤条件必须按真实工具名匹配,
|
|
2829
|
+
// 否则计数恒为 0,「已检测到 N 次任务操作」这条分支永远不可达。
|
|
2817
2830
|
const toolUses = msgs.flatMap((m) => {
|
|
2818
2831
|
if (Array.isArray(m.content)) {
|
|
2819
|
-
return m.content.filter(
|
|
2820
|
-
(b) => b.type === 'tool_use' && ['TaskCreate', 'TaskUpdate', 'TaskList'].includes(b.name),
|
|
2821
|
-
)
|
|
2832
|
+
return m.content.filter((b) => b.type === 'tool_use' && b.name === 'Task')
|
|
2822
2833
|
}
|
|
2823
2834
|
return []
|
|
2824
2835
|
})
|
|
@@ -2830,12 +2841,13 @@ const tasksCmd: CommandHandler = (ctx) => {
|
|
|
2830
2841
|
${toolUses.length > 0 ? t('commands.task_list.detected', { count: String(toolUses.length) }) : t('commands.task_list.no_tasks')}
|
|
2831
2842
|
|
|
2832
2843
|
${t('commands.task_list.reference')}
|
|
2833
|
-
|
|
2834
|
-
|
|
2835
|
-
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2844
|
+
Task(action: "create") — create a new task
|
|
2845
|
+
Task(action: "list") — list all tasks
|
|
2846
|
+
Task(action: "update") — update task status
|
|
2847
|
+
Task(action: "get") — get task details
|
|
2848
|
+
Task(action: "delete") — delete a task
|
|
2849
|
+
Task(action: "output") — get background task output
|
|
2850
|
+
Task(action: "stop") — stop a running task
|
|
2839
2851
|
|
|
2840
2852
|
${t('commands.task_list.legacy_hint')}
|
|
2841
2853
|
`,
|
|
@@ -3807,6 +3819,72 @@ const hooksCmd: CommandHandler = async (ctx) => {
|
|
|
3807
3819
|
return { content: lines.join('\n') }
|
|
3808
3820
|
}
|
|
3809
3821
|
|
|
3822
|
+
const telemetryCmd: CommandHandler = async (ctx, args) => {
|
|
3823
|
+
const sub = (args[0] ?? 'status').toLowerCase()
|
|
3824
|
+
|
|
3825
|
+
if (sub === 'on' || sub === 'off') {
|
|
3826
|
+
const enable = sub === 'on'
|
|
3827
|
+
setTelemetryEnabled(enable)
|
|
3828
|
+
if (enable) enableTelemetryNow()
|
|
3829
|
+
return {
|
|
3830
|
+
content: enable
|
|
3831
|
+
? '✓ Telemetry enabled. Anonymous usage counts will be sent to the configured endpoint.'
|
|
3832
|
+
: '✓ Telemetry disabled. Nothing is collected and no queue file is written.',
|
|
3833
|
+
}
|
|
3834
|
+
}
|
|
3835
|
+
|
|
3836
|
+
if (sub === 'reset-id') {
|
|
3837
|
+
const id = resetInstallId()
|
|
3838
|
+
return { content: `✓ New anonymous install id: ${id}` }
|
|
3839
|
+
}
|
|
3840
|
+
|
|
3841
|
+
if (sub === 'endpoint') {
|
|
3842
|
+
const url = args[1]
|
|
3843
|
+
if (!url) return { content: 'Usage: /telemetry endpoint <url|none>' }
|
|
3844
|
+
setTelemetryEndpoint(url)
|
|
3845
|
+
return {
|
|
3846
|
+
content:
|
|
3847
|
+
url === NO_ENDPOINT
|
|
3848
|
+
? '✓ Destination cleared. Telemetry stays on, but nothing is ever sent.'
|
|
3849
|
+
: `✓ Endpoint set to ${url}`,
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
|
|
3853
|
+
if (sub !== 'status') {
|
|
3854
|
+
return {
|
|
3855
|
+
content: 'Usage: /telemetry [status|on|off|reset-id|endpoint <url|none>]',
|
|
3856
|
+
}
|
|
3857
|
+
}
|
|
3858
|
+
|
|
3859
|
+
// ── status ──
|
|
3860
|
+
const consent = getTelemetryConsent() ?? resolveTelemetry()
|
|
3861
|
+
const settings = readTelemetrySettings('user')
|
|
3862
|
+
// Two ways for `endpoint` to be empty, and they mean different things: never
|
|
3863
|
+
// resolved (the kill switch fired first) or deliberately cleared (the `none`
|
|
3864
|
+
// sentinel). A third — nothing configured — is unreachable now that the
|
|
3865
|
+
// default is a real URL, which is why this used to be a one-line fallback.
|
|
3866
|
+
const destination = consent.endpoint
|
|
3867
|
+
? consent.endpoint
|
|
3868
|
+
: consent.endpointSource === 'off'
|
|
3869
|
+
? '_(not resolved — telemetry is off)_'
|
|
3870
|
+
: '_(nothing — the `none` sentinel cleared it)_'
|
|
3871
|
+
const lines = [
|
|
3872
|
+
'## 📡 Telemetry',
|
|
3873
|
+
'',
|
|
3874
|
+
`| Field | Value |`,
|
|
3875
|
+
`| --- | --- |`,
|
|
3876
|
+
`| State | ${consent.enabled ? '🟢 enabled' : '⚪ disabled'} |`,
|
|
3877
|
+
`| Decided by | \`${consent.source}\` |`,
|
|
3878
|
+
`| Endpoint | ${destination} |`,
|
|
3879
|
+
`| Source | \`${consent.endpointSource}\` |`,
|
|
3880
|
+
`| Install id | ${settings.installId ?? '_(not yet generated)_'} |`,
|
|
3881
|
+
`| Prompted | ${settings.promptedAt ?? '_(never)_'} |`,
|
|
3882
|
+
'',
|
|
3883
|
+
'Full data dictionary: `docs/telemetry.md`',
|
|
3884
|
+
]
|
|
3885
|
+
return { content: lines.join('\n') }
|
|
3886
|
+
}
|
|
3887
|
+
|
|
3810
3888
|
const hooksHealthCmd: CommandHandler = (ctx) => {
|
|
3811
3889
|
const hookEngine = ctx.engine.getHookEngine?.()
|
|
3812
3890
|
if (!hookEngine) {
|
|
@@ -4319,10 +4397,7 @@ const workflowsCmd: CommandHandler = async () => {
|
|
|
4319
4397
|
const { existsSync, readdirSync, readFileSync } = await import('node:fs')
|
|
4320
4398
|
const { join } = await import('node:path')
|
|
4321
4399
|
|
|
4322
|
-
const locations =
|
|
4323
|
-
join(process.cwd(), '.claude', 'workflows'),
|
|
4324
|
-
join(homedir(), '.claude', 'workflows'),
|
|
4325
|
-
]
|
|
4400
|
+
const locations = workflowScriptDirs(process.cwd())
|
|
4326
4401
|
|
|
4327
4402
|
const lines: string[] = ['─ Workflows ─', '']
|
|
4328
4403
|
let found = 0
|
|
@@ -4360,10 +4435,11 @@ const workflowsCmd: CommandHandler = async () => {
|
|
|
4360
4435
|
lines.push('No workflow scripts found.')
|
|
4361
4436
|
lines.push('')
|
|
4362
4437
|
lines.push('Workflows are multi-agent orchestration scripts stored in:')
|
|
4363
|
-
lines.push(' .
|
|
4364
|
-
lines.push('
|
|
4438
|
+
lines.push(' .mipham/workflows/ (project-level — new scripts go here)')
|
|
4439
|
+
lines.push(' .claude/workflows/ (project-level, legacy — still read)')
|
|
4440
|
+
lines.push(' ~/.claude/workflows/ (user-level, legacy — still read)')
|
|
4365
4441
|
lines.push('')
|
|
4366
|
-
lines.push('Create a .js file in either location to add a workflow.')
|
|
4442
|
+
lines.push('Create a .js file in either project location to add a workflow.')
|
|
4367
4443
|
} else {
|
|
4368
4444
|
lines.push('')
|
|
4369
4445
|
lines.push(`${found} workflow(s) found.`)
|
|
@@ -4381,14 +4457,20 @@ const workflowSaveCmd = async (name: string): Promise<CommandResult> => {
|
|
|
4381
4457
|
const { existsSync, mkdirSync, writeFileSync, readFileSync } = await import('node:fs')
|
|
4382
4458
|
const { join } = await import('node:path')
|
|
4383
4459
|
|
|
4384
|
-
const targetDir =
|
|
4460
|
+
const targetDir = workflowScriptDir(process.cwd())
|
|
4385
4461
|
if (!existsSync(targetDir)) {
|
|
4386
4462
|
mkdirSync(targetDir, { recursive: true })
|
|
4387
4463
|
}
|
|
4388
4464
|
|
|
4389
|
-
// Read the last-run state persisted by the Workflow tool
|
|
4390
|
-
|
|
4391
|
-
|
|
4465
|
+
// Read the last-run state persisted by the Workflow tool. Every readable
|
|
4466
|
+
// location is checked, not just the writable one: a run that predates the
|
|
4467
|
+
// move to `.mipham/` left its state in `.claude/workflows/`, so looking in
|
|
4468
|
+
// the new directory alone would report "no recent run" on the first save
|
|
4469
|
+
// after upgrading.
|
|
4470
|
+
const stateFile = workflowScriptDirs(process.cwd())
|
|
4471
|
+
.map((dir) => join(dir, '.last-run.json'))
|
|
4472
|
+
.find((file) => existsSync(file))
|
|
4473
|
+
if (!stateFile) {
|
|
4392
4474
|
return { content: 'No recent workflow run found. Run a workflow first with /workflow <task>.' }
|
|
4393
4475
|
}
|
|
4394
4476
|
|
|
@@ -4417,10 +4499,7 @@ const workflowRunCmd = async (name: string): Promise<CommandResult> => {
|
|
|
4417
4499
|
|
|
4418
4500
|
const safeName = name.replace(/[^a-zA-Z0-9_-]/g, '-')
|
|
4419
4501
|
|
|
4420
|
-
const locations =
|
|
4421
|
-
join(process.cwd(), '.claude', 'workflows'),
|
|
4422
|
-
join(homedir(), '.claude', 'workflows'),
|
|
4423
|
-
]
|
|
4502
|
+
const locations = workflowScriptDirs(process.cwd())
|
|
4424
4503
|
|
|
4425
4504
|
for (const loc of locations) {
|
|
4426
4505
|
const scriptPath = join(loc, `${safeName}.js`)
|
|
@@ -4435,7 +4514,9 @@ const workflowRunCmd = async (name: string): Promise<CommandResult> => {
|
|
|
4435
4514
|
}
|
|
4436
4515
|
|
|
4437
4516
|
return {
|
|
4438
|
-
content:
|
|
4517
|
+
content:
|
|
4518
|
+
`Workflow "${safeName}" not found in .mipham/workflows/, ` +
|
|
4519
|
+
`.claude/workflows/ or ~/.claude/workflows/`,
|
|
4439
4520
|
}
|
|
4440
4521
|
}
|
|
4441
4522
|
|
|
@@ -5003,7 +5084,7 @@ const forkCmd: CommandHandler = async (ctx, args) => {
|
|
|
5003
5084
|
.slice(0, 40)
|
|
5004
5085
|
const name = `${slug}-${Date.now().toString(36)}`
|
|
5005
5086
|
const branch = `worktree/${name}`
|
|
5006
|
-
const wtPath = join(process.cwd(),
|
|
5087
|
+
const wtPath = join(worktreeRoot(process.cwd()), name)
|
|
5007
5088
|
|
|
5008
5089
|
try {
|
|
5009
5090
|
execSync(`git worktree add -b ${branch} ${wtPath} HEAD`, { stdio: 'ignore', timeout: 30_000 })
|
|
@@ -5110,10 +5191,23 @@ const artifactOpenCmd: CommandHandler = async (ctx, args) => {
|
|
|
5110
5191
|
return { content: 'Usage: /artifact open <name>\nExample: /artifact open dashboard' }
|
|
5111
5192
|
}
|
|
5112
5193
|
|
|
5113
|
-
const
|
|
5114
|
-
const
|
|
5115
|
-
const
|
|
5116
|
-
|
|
5194
|
+
const { readManifest } = await import('../artifacts/manifest')
|
|
5195
|
+
const { artifactsRoot } = await import('../artifacts/paths')
|
|
5196
|
+
const manifest = readManifest(artifactsRoot(process.cwd()))
|
|
5197
|
+
|
|
5198
|
+
// 先找本会话,再退到任意会话:文件在磁盘上跨会话留存,而 `open` 是用户手敲的。
|
|
5199
|
+
// 原先写死 `session-1` + 端口 9876,工具回报的却是真会话 id 和**实际**端口
|
|
5200
|
+
// (服务端遇到端口占用会自增),所以这条命令从构造上就打不开任何东西。
|
|
5201
|
+
const entry =
|
|
5202
|
+
manifest.artifacts.find((a) => a.name === name && a.sessionId === ctx.sessionId) ??
|
|
5203
|
+
manifest.artifacts.find((a) => a.name === name)
|
|
5204
|
+
|
|
5205
|
+
if (!entry) {
|
|
5206
|
+
return { content: `✗ No artifact named "${name}". Run /artifact list to see them.` }
|
|
5207
|
+
}
|
|
5208
|
+
|
|
5209
|
+
// 用工具落盘时记下的 URL —— 那就是它印给用户的同一个坐标,两边不该各算一次。
|
|
5210
|
+
const url = entry.url
|
|
5117
5211
|
|
|
5118
5212
|
try {
|
|
5119
5213
|
await openBrowser(url)
|
|
@@ -5123,13 +5217,14 @@ const artifactOpenCmd: CommandHandler = async (ctx, args) => {
|
|
|
5123
5217
|
}
|
|
5124
5218
|
}
|
|
5125
5219
|
|
|
5126
|
-
const artifactListCmd: CommandHandler = async (
|
|
5127
|
-
const { getSessionArtifacts } = await import('../artifacts/manifest')
|
|
5128
|
-
const {
|
|
5129
|
-
const { ARTIFACTS_DIR } = await import('../shared/constants')
|
|
5220
|
+
const artifactListCmd: CommandHandler = async (ctx, _args) => {
|
|
5221
|
+
const { readManifest, getSessionArtifacts } = await import('../artifacts/manifest')
|
|
5222
|
+
const { artifactsRoot } = await import('../artifacts/paths')
|
|
5130
5223
|
|
|
5131
|
-
const dir =
|
|
5132
|
-
|
|
5224
|
+
const dir = artifactsRoot(process.cwd())
|
|
5225
|
+
// 会话 id 取自真实上下文,不是写死的 'session-1' —— 工具落盘时写的是真 id,
|
|
5226
|
+
// 写死的那一支必然过滤出空列表。
|
|
5227
|
+
const entries = getSessionArtifacts(dir, ctx.sessionId)
|
|
5133
5228
|
|
|
5134
5229
|
if (entries.length === 0) {
|
|
5135
5230
|
return {
|
|
@@ -5145,7 +5240,9 @@ const artifactListCmd: CommandHandler = async (_ctx, _args) => {
|
|
|
5145
5240
|
)
|
|
5146
5241
|
}
|
|
5147
5242
|
lines.push('', ` ${entries.length} artifact(s) — /artifact open <name> to view`)
|
|
5148
|
-
|
|
5243
|
+
// 画廊端口同样不写死:用最近一次落盘记下的那个(服务端会因端口占用自增)。
|
|
5244
|
+
const { port } = readManifest(dir)
|
|
5245
|
+
if (port) lines.push(` Gallery: http://localhost:${port}`)
|
|
5149
5246
|
|
|
5150
5247
|
return { content: lines.join('\n') }
|
|
5151
5248
|
}
|
|
@@ -5304,6 +5401,7 @@ const commandsListCmd: CommandHandler = () => {
|
|
|
5304
5401
|
'/keys audit': 'Account',
|
|
5305
5402
|
'/keys view': 'Account',
|
|
5306
5403
|
'/feedback': 'Account',
|
|
5404
|
+
'/telemetry': 'Account',
|
|
5307
5405
|
'/agents': 'Agents',
|
|
5308
5406
|
'/bg': 'Agents',
|
|
5309
5407
|
'/fork': 'Agents',
|
|
@@ -5525,6 +5623,7 @@ registry.set('/cd', cdCmd)
|
|
|
5525
5623
|
registry.set('/hooks', hooksCmd)
|
|
5526
5624
|
registry.set('/hooks health', hooksHealthCmd)
|
|
5527
5625
|
registry.set('/hooks enable', hooksEnableCmd)
|
|
5626
|
+
registry.set('/telemetry', telemetryCmd)
|
|
5528
5627
|
registry.set('/batch', batchCmd)
|
|
5529
5628
|
|
|
5530
5629
|
// ═══════════════════════════════════════════════════════════════
|
|
@@ -5539,6 +5638,47 @@ export function getCommandNames(): string[] {
|
|
|
5539
5638
|
return Array.from(registry.keys()).sort()
|
|
5540
5639
|
}
|
|
5541
5640
|
|
|
5641
|
+
/**
|
|
5642
|
+
* The commands `app.tsx` intercepts **before** the registry lookup.
|
|
5643
|
+
*
|
|
5644
|
+
* They return early and never reach `getCommand`, so the registry is not
|
|
5645
|
+
* authoritative for them. `/model-picker` is the one that is not a registry key
|
|
5646
|
+
* at all — the other five are, so listing them here is belt-and-braces rather
|
|
5647
|
+
* than a claim that they are missing.
|
|
5648
|
+
*/
|
|
5649
|
+
const PRE_REGISTRY_COMMANDS = ['/switch', '/pick', '/model-picker', '/exit', '/quit', '/focus']
|
|
5650
|
+
|
|
5651
|
+
/**
|
|
5652
|
+
* The bucket an unrecognised command name is recorded under.
|
|
5653
|
+
*
|
|
5654
|
+
* **Why this exists.** `parseSlashCommand` returns `parts[0]` — whatever the user
|
|
5655
|
+
* typed. Without a convergence point, `/foobar` mints a `command_calls./foobar`
|
|
5656
|
+
* series on the spot, and nothing bounds the number of series:
|
|
5657
|
+
* `MAX_LABEL_LENGTH` in `payload.ts` truncates the **value**, not the key count.
|
|
5658
|
+
* `tool_name` really is closed by construction (the registry declares the tool
|
|
5659
|
+
* set); `command_name` is not.
|
|
5660
|
+
*/
|
|
5661
|
+
export const UNKNOWN_COMMAND = '/unknown'
|
|
5662
|
+
|
|
5663
|
+
/** The label a command name is recorded under: itself if we ship it, else the bucket. */
|
|
5664
|
+
export function commandLabelFor(command: string): string {
|
|
5665
|
+
if (registry.has(command) || PRE_REGISTRY_COMMANDS.includes(command)) return command
|
|
5666
|
+
return UNKNOWN_COMMAND
|
|
5667
|
+
}
|
|
5668
|
+
|
|
5669
|
+
/**
|
|
5670
|
+
* Every label `command_calls` can carry — the source the collector's allowlist is
|
|
5671
|
+
* generated from.
|
|
5672
|
+
*
|
|
5673
|
+
* Two more than `getCommandNames()`: `/model-picker` (user-typable, not a registry
|
|
5674
|
+
* key) and `UNKNOWN_COMMAND`. Miss either and the allowlist does not contain it,
|
|
5675
|
+
* so the collector folds those events into `__other__` — and `__other__` is
|
|
5676
|
+
* exactly what T4 must not be reading when it votes.
|
|
5677
|
+
*/
|
|
5678
|
+
export function getCommandLabelNames(): string[] {
|
|
5679
|
+
return Array.from(new Set([...registry.keys(), ...PRE_REGISTRY_COMMANDS, UNKNOWN_COMMAND])).sort()
|
|
5680
|
+
}
|
|
5681
|
+
|
|
5542
5682
|
export interface CommandEntry {
|
|
5543
5683
|
name: string
|
|
5544
5684
|
description: string
|
|
@@ -5640,7 +5780,7 @@ const COMMAND_DESCRIPTIONS: Record<string, string> = {
|
|
|
5640
5780
|
'/loop': 'Run prompt on interval',
|
|
5641
5781
|
'/init': 'Initialize .mipham config',
|
|
5642
5782
|
'/setup': 'Guided project setup wizard',
|
|
5643
|
-
'/permissions': 'Show permission
|
|
5783
|
+
'/permissions': 'Show or persist permission rules',
|
|
5644
5784
|
'/add-dir': 'Add workspace directory',
|
|
5645
5785
|
'/recommend': 'Analyze project + recommend skills & setup',
|
|
5646
5786
|
'/security': 'Security review checklist',
|
|
@@ -5681,6 +5821,7 @@ const COMMAND_DESCRIPTIONS: Record<string, string> = {
|
|
|
5681
5821
|
'/hooks health': 'Check hook health — see failures, disabled hooks, recovery status',
|
|
5682
5822
|
'/hooks enable': 'Manually re-enable a hook that was auto-disabled after repeated failures',
|
|
5683
5823
|
'/batch': 'Apply changes across multiple files',
|
|
5824
|
+
'/telemetry': 'Show or change anonymous usage-reporting settings',
|
|
5684
5825
|
}
|
|
5685
5826
|
|
|
5686
5827
|
export function getCommandList(): CommandEntry[] {
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
import { join } from 'node:path'
|
|
1
2
|
import { SubAgent } from '../../agent/sub-agent'
|
|
2
3
|
import type { ProviderRegistry } from '../../providers/registry'
|
|
3
4
|
import type { Llm } from '../../providers/llm'
|
|
4
5
|
import type { ToolDefinition } from '../../shared/index.ts'
|
|
5
6
|
import type { PermissionSystem } from '../../core/permission'
|
|
7
|
+
import { worktreeRoot } from '../../core/paths.ts'
|
|
6
8
|
import { validateJSONSchema, formatValidationErrors } from '../schema-validator'
|
|
7
9
|
|
|
8
10
|
export interface WorkflowAgentOpts {
|
|
@@ -32,7 +34,7 @@ export interface WorkflowAgentOpts {
|
|
|
32
34
|
* 4. Returns the validated object, or { raw, validationErrors } on final failure.
|
|
33
35
|
*
|
|
34
36
|
* When `isolation: 'worktree'` is set:
|
|
35
|
-
* 1. A git worktree is created at .
|
|
37
|
+
* 1. A git worktree is created at .mipham/worktrees/wf-<slug>
|
|
36
38
|
* 2. The sub-agent runs with its cwd set to the worktree path
|
|
37
39
|
* 3. Changes are auto-committed (best-effort)
|
|
38
40
|
* 4. The worktree is cleaned up after execution
|
|
@@ -60,7 +62,7 @@ export async function workflowAgent(
|
|
|
60
62
|
if (opts.isolation === 'worktree') {
|
|
61
63
|
const slug = `wf-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 6)}`
|
|
62
64
|
worktreeBranch = `worktree/${slug}`
|
|
63
|
-
worktreePath =
|
|
65
|
+
worktreePath = join(worktreeRoot(process.cwd()), slug)
|
|
64
66
|
|
|
65
67
|
const proc = Bun.spawn(['git', 'worktree', 'add', '-b', worktreeBranch, worktreePath, 'HEAD'], {
|
|
66
68
|
stdout: 'pipe',
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import { mkdirSync, writeFileSync, readFileSync, existsSync, readdirSync, statSync } from 'node:fs'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import { homedir } from 'node:os'
|
|
4
|
-
|
|
5
|
-
const DEFAULT_VERSIONS_DIR = join(homedir(), '.mipham', 'artifacts')
|
|
6
|
-
|
|
7
|
-
export interface ArtifactVersion {
|
|
8
|
-
name: string
|
|
9
|
-
version: number
|
|
10
|
-
path: string
|
|
11
|
-
createdAt: string
|
|
12
|
-
size: number
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Manages artifact version snapshots on disk.
|
|
17
|
-
*
|
|
18
|
-
* Directory layout:
|
|
19
|
-
* <dir>/<name>/versions/v1.html
|
|
20
|
-
* <dir>/<name>/versions/v2.html
|
|
21
|
-
* <dir>/<name>/current.html (latest snapshot)
|
|
22
|
-
* <dir>/<name>/manifest.json ({ name, currentVersion, versionCount })
|
|
23
|
-
*/
|
|
24
|
-
export class ArtifactVersioning {
|
|
25
|
-
private dir: string
|
|
26
|
-
|
|
27
|
-
constructor(dir?: string) {
|
|
28
|
-
this.dir = dir ?? DEFAULT_VERSIONS_DIR
|
|
29
|
-
mkdirSync(this.dir, { recursive: true })
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/** Save a new version of an artifact. Returns the assigned version number. */
|
|
33
|
-
saveVersion(name: string, content: string): number {
|
|
34
|
-
const artifactDir = join(this.dir, name)
|
|
35
|
-
const versionsDir = join(artifactDir, 'versions')
|
|
36
|
-
mkdirSync(versionsDir, { recursive: true })
|
|
37
|
-
|
|
38
|
-
// Determine next version number
|
|
39
|
-
const existing = this.listVersions(name)
|
|
40
|
-
const nextVersion = (existing.length > 0 ? Math.max(...existing.map((v) => v.version)) : 0) + 1
|
|
41
|
-
|
|
42
|
-
// Save versioned file
|
|
43
|
-
const versionPath = join(versionsDir, `v${nextVersion}.html`)
|
|
44
|
-
writeFileSync(versionPath, content, 'utf-8')
|
|
45
|
-
|
|
46
|
-
// Update current.html
|
|
47
|
-
writeFileSync(join(artifactDir, 'current.html'), content, 'utf-8')
|
|
48
|
-
|
|
49
|
-
// Update manifest
|
|
50
|
-
writeFileSync(
|
|
51
|
-
join(artifactDir, 'manifest.json'),
|
|
52
|
-
JSON.stringify(
|
|
53
|
-
{
|
|
54
|
-
name,
|
|
55
|
-
currentVersion: nextVersion,
|
|
56
|
-
versionCount: nextVersion,
|
|
57
|
-
},
|
|
58
|
-
null,
|
|
59
|
-
2,
|
|
60
|
-
),
|
|
61
|
-
)
|
|
62
|
-
|
|
63
|
-
return nextVersion
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** List all saved versions for an artifact, newest first. */
|
|
67
|
-
listVersions(name: string): ArtifactVersion[] {
|
|
68
|
-
const versionsDir = join(this.dir, name, 'versions')
|
|
69
|
-
if (!existsSync(versionsDir)) return []
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
return readdirSync(versionsDir)
|
|
73
|
-
.filter((f) => f.startsWith('v') && f.endsWith('.html'))
|
|
74
|
-
.map((f) => {
|
|
75
|
-
const vNum = parseInt(f.replace('v', '').replace('.html', ''), 10)
|
|
76
|
-
const path = join(versionsDir, f)
|
|
77
|
-
const stat = statSync(path)
|
|
78
|
-
return {
|
|
79
|
-
name,
|
|
80
|
-
version: vNum,
|
|
81
|
-
path,
|
|
82
|
-
createdAt: stat.birthtime.toISOString(),
|
|
83
|
-
size: stat.size,
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
.sort((a, b) => b.version - a.version)
|
|
87
|
-
} catch {
|
|
88
|
-
return []
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Get artifact content.
|
|
94
|
-
* - If a version number is given, returns that specific version.
|
|
95
|
-
* - Otherwise returns the latest (current.html).
|
|
96
|
-
* Returns null if the requested version does not exist.
|
|
97
|
-
*/
|
|
98
|
-
getVersion(name: string, version?: number): string | null {
|
|
99
|
-
const artifactDir = join(this.dir, name)
|
|
100
|
-
|
|
101
|
-
if (version !== undefined) {
|
|
102
|
-
const vPath = join(artifactDir, 'versions', `v${version}.html`)
|
|
103
|
-
return existsSync(vPath) ? readFileSync(vPath, 'utf-8') : null
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const currentPath = join(artifactDir, 'current.html')
|
|
107
|
-
return existsSync(currentPath) ? readFileSync(currentPath, 'utf-8') : null
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** Produce a simple line-by-line text diff between two versions. */
|
|
111
|
-
diff(name: string, v1: number, v2: number): string {
|
|
112
|
-
const content1 = this.getVersion(name, v1) || ''
|
|
113
|
-
const content2 = this.getVersion(name, v2) || ''
|
|
114
|
-
const lines1 = content1.split('\n')
|
|
115
|
-
const lines2 = content2.split('\n')
|
|
116
|
-
|
|
117
|
-
const diffLines: string[] = []
|
|
118
|
-
const maxLen = Math.max(lines1.length, lines2.length)
|
|
119
|
-
for (let i = 0; i < maxLen; i++) {
|
|
120
|
-
if (lines1[i] !== lines2[i]) {
|
|
121
|
-
if (lines1[i] !== undefined) diffLines.push(`- ${lines1[i]}`)
|
|
122
|
-
if (lines2[i] !== undefined) diffLines.push(`+ ${lines2[i]}`)
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
return diffLines.length > 0 ? diffLines.join('\n') : '(no changes)'
|
|
126
|
-
}
|
|
127
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 1,
|
|
3
|
-
"tasks": [
|
|
4
|
-
{
|
|
5
|
-
"id": "task-answer-fn",
|
|
6
|
-
"instruction": "用 Write 工具在 <taskDir>/solution.ts 写入一个 TypeScript 文件,导出 `export function answer(): number { return 42 }`。",
|
|
7
|
-
"groundTruth": {
|
|
8
|
-
"kind": "file-contains",
|
|
9
|
-
"file": "solution.ts",
|
|
10
|
-
"contains": ["export function answer", "42"]
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
]
|
|
14
|
-
}
|