@miphamai/cli 0.85.54 → 0.85.56

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.
@@ -0,0 +1,107 @@
1
+ import React from 'react'
2
+ import { Box, Text, useInput } from 'ink'
3
+ import { useI18n } from '../i18n-context'
4
+ import { useKeyState } from './use-key-state'
5
+ import type { ApprovalChoice, ApprovalRequest } from '../core/approval-prompt'
6
+
7
+ const wrap = (i: number, len: number) => ((i % len) + len) % len
8
+
9
+ /**
10
+ * A compact, non-JSON rendering of the call under review. The prompt is a
11
+ * decision, not a debugger: the command line or the target path is what the
12
+ * user needs to see, and the exact rule "always allow" would write is printed
13
+ * next to that option.
14
+ */
15
+ function detailFor(request: ApprovalRequest): string {
16
+ const input = request.input
17
+ if (typeof input.command === 'string') return `$ ${input.command}`
18
+ if (typeof input.file_path === 'string') return input.file_path
19
+ try {
20
+ return JSON.stringify(input)
21
+ } catch {
22
+ return ''
23
+ }
24
+ }
25
+
26
+ function truncate(text: string, max = 200): string {
27
+ return text.length <= max ? text : `${text.slice(0, max)}…`
28
+ }
29
+
30
+ /**
31
+ * The permission prompt itself — CC's missing half in Mipham.
32
+ *
33
+ * Key handling goes through `useKeyState.read()`, not the rendered closure:
34
+ * remote/paste bursts deliver "↓ Enter" in one chunk, and reading `.value`
35
+ * would choose the row *before* the arrow — the exact bug `/copy` had.
36
+ *
37
+ * `onChoose` is the only output. The engine owns what the choice means
38
+ * (persist a rule, run once, or refuse); this component never touches the
39
+ * permission system, so the same UI cannot drift from the gate's semantics.
40
+ */
41
+ export function ApprovalPrompt({
42
+ request,
43
+ onChoose,
44
+ }: {
45
+ request: ApprovalRequest
46
+ onChoose: (choice: ApprovalChoice) => void
47
+ }) {
48
+ const { t } = useI18n()
49
+ const options: ApprovalChoice[] = request.rule
50
+ ? ['allow-once', 'allow-always', 'deny']
51
+ : ['allow-once', 'deny']
52
+ const idx = useKeyState(0)
53
+
54
+ useInput((_input, key) => {
55
+ if (key.escape) {
56
+ onChoose('deny')
57
+ return
58
+ }
59
+ if (key.return) {
60
+ const choice = options[Math.min(idx.read(), options.length - 1)]
61
+ if (choice) onChoose(choice)
62
+ return
63
+ }
64
+ if (key.upArrow) idx.set((prev) => wrap(prev - 1, options.length))
65
+ if (key.downArrow) idx.set((prev) => wrap(prev + 1, options.length))
66
+ })
67
+
68
+ const label = (choice: ApprovalChoice): string => {
69
+ switch (choice) {
70
+ case 'allow-once':
71
+ return t('ui.approval.allow_once')
72
+ case 'allow-always':
73
+ return t('ui.approval.allow_always', { rule: request.rule ?? '' })
74
+ case 'deny':
75
+ return t('ui.approval.deny')
76
+ }
77
+ }
78
+
79
+ const selected = Math.min(idx.value, options.length - 1)
80
+
81
+ return (
82
+ <Box flexDirection="column" borderStyle="round" borderColor="yellow" padding={1}>
83
+ <Box marginBottom={1}>
84
+ <Text bold color="yellow">
85
+ {t('ui.approval.title')}
86
+ </Text>
87
+ <Text dimColor> {t('ui.approval.hint')}</Text>
88
+ </Box>
89
+ <Box marginBottom={1} flexDirection="column">
90
+ <Text bold>{request.tool}</Text>
91
+ <Text dimColor>{truncate(detailFor(request))}</Text>
92
+ </Box>
93
+ {options.map((choice, i) => {
94
+ const isSelected = i === selected
95
+ return (
96
+ <Box key={choice} flexDirection="column">
97
+ <Text color={isSelected ? 'yellow' : 'white'} bold={isSelected}>
98
+ {isSelected ? '▶ ' : ' '}
99
+ {label(choice)}
100
+ </Text>
101
+ {choice === 'allow-always' && <Text dimColor> {t('ui.approval.persist_note')}</Text>}
102
+ </Box>
103
+ )
104
+ })}
105
+ </Box>
106
+ )
107
+ }
@@ -620,6 +620,13 @@ const statusCmd: CommandHandler = async (ctx) => {
620
620
  .filter((p) => p.status !== 'upcoming')
621
621
  .map((p) => `${p.id} ${health.get(p.id) ? '🟢' : '🔴'}`)
622
622
  .join(' ')
623
+ // Only the engine knows what it actually wired. A remote stub without the
624
+ // accessor omits the row instead of showing a guess.
625
+ const selfCheck = (
626
+ ctx.engine as QueryEngine & {
627
+ getSelfCheckStatus?: () => { reviewGate: boolean; verification: boolean }
628
+ }
629
+ ).getSelfCheckStatus?.()
623
630
 
624
631
  return {
625
632
  content: stripIndent`
@@ -630,6 +637,7 @@ const statusCmd: CommandHandler = async (ctx) => {
630
637
  ${t('commands.status.tokens')} ~${c.getEstimatedTokens().toLocaleString()} / ${c.getMaxTokens().toLocaleString()}
631
638
  ${t('commands.status.tools')} ${tools.size} ${t('commands.status.loaded')}
632
639
  ${t('commands.status.permission')} ${liveMode(ctx)}
640
+ ${selfCheck ? `Self-check review=${selfCheck.reviewGate ? 'on' : 'off'} verification=${selfCheck.verification ? 'on' : 'off'}` : ''}
633
641
  Telemetry ${telemetryStatus(ctx)}
634
642
 
635
643
  ${t('commands.status.system_title')}
@@ -2,7 +2,7 @@ import { join } from 'node:path'
2
2
  import { SubAgent } from '../../agent/sub-agent'
3
3
  import type { ProviderRegistry } from '../../providers/registry'
4
4
  import type { Llm } from '../../providers/llm'
5
- import type { ToolDefinition } from '../../shared/index.ts'
5
+ import type { ToolDefinition, ToolContext } from '../../shared/index.ts'
6
6
  import type { PermissionSystem } from '../../core/permission'
7
7
  import type { SubAgentServices } from '../../agent/services'
8
8
  import { worktreeRoot } from '../../core/paths.ts'
@@ -40,6 +40,8 @@ export interface WorkflowAgentOpts {
40
40
  permissionSystem?: PermissionSystem
41
41
  /** Hooks, gates and DLP handed down by the engine running the workflow. */
42
42
  services?: SubAgentServices
43
+ /** Write tracking handed down by the engine (the review gate is one consumer). */
44
+ toolContext?: Partial<ToolContext>
43
45
  /** Run the agent in an isolated git worktree (optional). */
44
46
  isolation?: 'worktree'
45
47
  /**
@@ -173,6 +175,7 @@ export async function workflowAgent(
173
175
  effort: opts.effort,
174
176
  allowedTools: undefined, // use all tools by default
175
177
  worktreePath,
178
+ toolContext: opts.toolContext,
176
179
  signal: opts.signal,
177
180
  // The prompt is computed by the script, not typed by the user — say so,
178
181
  // so text the script relayed from a file or another agent cannot pass
@@ -152,6 +152,10 @@ export async function runWorkflow(
152
152
  ...(opts || {}),
153
153
  permissionSystem: permission,
154
154
  services: engine.getSubAgentServices(),
155
+ // Stub engines (the Workflow tool's, older tests) may predate this
156
+ // accessor; a missing write tap must not fail the whole run.
157
+ toolContext:
158
+ typeof engine.getToolContext === 'function' ? engine.getToolContext() : undefined,
155
159
  signal: controller.signal,
156
160
  } as Record<string, unknown>,
157
161
  llm,