myshell-tools 3.0.0 → 3.2.0
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/CHANGELOG.md +52 -1
- package/README.md +32 -21
- package/dist/cli.js +22 -6
- package/dist/cli.js.map +1 -1
- package/dist/commands/cost.js +44 -25
- package/dist/commands/cost.js.map +1 -1
- package/dist/commands/doctor.d.ts +17 -4
- package/dist/commands/doctor.js +56 -34
- package/dist/commands/doctor.js.map +1 -1
- package/dist/core/native-session.d.ts +57 -0
- package/dist/core/native-session.js +68 -0
- package/dist/core/native-session.js.map +1 -0
- package/dist/core/orchestrate.js +25 -4
- package/dist/core/orchestrate.js.map +1 -1
- package/dist/core/types.d.ts +26 -0
- package/dist/infra/config.d.ts +8 -0
- package/dist/infra/config.js.map +1 -1
- package/dist/infra/credentials.d.ts +35 -0
- package/dist/infra/credentials.js +59 -1
- package/dist/infra/credentials.js.map +1 -1
- package/dist/infra/health.d.ts +57 -0
- package/dist/infra/health.js +96 -0
- package/dist/infra/health.js.map +1 -0
- package/dist/infra/insights.d.ts +14 -0
- package/dist/infra/insights.js +31 -0
- package/dist/infra/insights.js.map +1 -1
- package/dist/interface/menu.d.ts +70 -5
- package/dist/interface/menu.js +195 -26
- package/dist/interface/menu.js.map +1 -1
- package/dist/interface/render.js +11 -8
- package/dist/interface/render.js.map +1 -1
- package/dist/providers/claude.d.ts +24 -8
- package/dist/providers/claude.js +65 -15
- package/dist/providers/claude.js.map +1 -1
- package/dist/providers/codex-parse.js +14 -2
- package/dist/providers/codex-parse.js.map +1 -1
- package/dist/providers/codex.d.ts +13 -1
- package/dist/providers/codex.js +19 -8
- package/dist/providers/codex.js.map +1 -1
- package/dist/providers/port.d.ts +15 -0
- package/dist/ui/help.d.ts +17 -0
- package/dist/ui/help.js +106 -0
- package/dist/ui/help.js.map +1 -0
- package/package.json +1 -1
package/dist/interface/render.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
import { bold, cyan, dim, green, red, yellow } from '../ui/theme.js';
|
|
12
12
|
import { createSpinner } from '../ui/spinner.js';
|
|
13
|
+
import { formatTokens } from '../infra/insights.js';
|
|
13
14
|
// ---------------------------------------------------------------------------
|
|
14
15
|
// Internal helpers
|
|
15
16
|
// ---------------------------------------------------------------------------
|
|
@@ -40,7 +41,9 @@ function renderConfidence(confidence, color) {
|
|
|
40
41
|
export async function renderStream(events, out) {
|
|
41
42
|
const c = out.color;
|
|
42
43
|
let finalEvent;
|
|
43
|
-
|
|
44
|
+
// Accumulate REAL tokens across tiers so the final summary shows a measured
|
|
45
|
+
// total instead of an estimated dollar figure (subscription tool, not API).
|
|
46
|
+
let runningTokens = 0;
|
|
44
47
|
// Spinner is only used in TTY mode; we create one per tier-start and stop it
|
|
45
48
|
// when the first real output arrives or when tier-done fires.
|
|
46
49
|
const spinner = createSpinner(out);
|
|
@@ -94,15 +97,16 @@ export async function renderStream(events, out) {
|
|
|
94
97
|
}
|
|
95
98
|
case 'tier-done': {
|
|
96
99
|
stopSpinner();
|
|
97
|
-
runningUsd += ev.costUsd;
|
|
98
100
|
const confidenceStr = renderConfidence(ev.confidence, c);
|
|
99
|
-
|
|
100
|
-
|
|
101
|
+
// Tokens are real and measured; dollars are an API-equivalent estimate
|
|
102
|
+
// that doesn't map to subscription billing, so they live in `cost`, not here.
|
|
103
|
+
runningTokens += ev.inputTokens + ev.outputTokens;
|
|
104
|
+
const tokenStr = formatTokens(ev.inputTokens + ev.outputTokens);
|
|
101
105
|
const successMark = ev.success ? green('✓', c) : red('✗', c);
|
|
102
106
|
out.write(`\n${successMark} ${bold('tier done', c)} — ` +
|
|
103
107
|
`confidence: ${confidenceStr}, ` +
|
|
104
|
-
|
|
105
|
-
`duration: ${ev.durationMs}ms
|
|
108
|
+
`${tokenStr} tokens, ` +
|
|
109
|
+
`duration: ${ev.durationMs}ms\n`);
|
|
106
110
|
break;
|
|
107
111
|
}
|
|
108
112
|
case 'escalate': {
|
|
@@ -125,10 +129,9 @@ export async function renderStream(events, out) {
|
|
|
125
129
|
const successLabel = ev.success
|
|
126
130
|
? bold(green('Success', c), c)
|
|
127
131
|
: bold(red('Failed', c), c);
|
|
128
|
-
const costStr = `$${ev.totalCostUsd.toFixed(4)}`;
|
|
129
132
|
out.write(`\n${successLabel} — ` +
|
|
130
133
|
`tier: ${ev.tier}, ` +
|
|
131
|
-
|
|
134
|
+
`${formatTokens(runningTokens)} tokens, ` +
|
|
132
135
|
`attempts: ${ev.attempts}, ` +
|
|
133
136
|
`session: ${ev.sessionId}\n`);
|
|
134
137
|
break;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/interface/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/interface/render.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAGH,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAYpD,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E;;;;GAIG;AACH,SAAS,gBAAgB,CAAC,UAAyB,EAAE,KAAc;IACjE,IAAI,UAAU,KAAK,IAAI;QAAE,OAAO,GAAG,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC;IACtD,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC;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
|
6
6
|
* parsed ProviderEvents to the caller as they arrive.
|
|
7
7
|
*
|
|
8
|
-
* Sandbox enforcement
|
|
9
|
-
* The `req.sandbox` level is
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
* Sandbox enforcement:
|
|
9
|
+
* The `req.sandbox` privilege level is mapped to real Claude CLI flags (see
|
|
10
|
+
* claudeSandboxArgs):
|
|
11
|
+
* - read-only → --disallowedTools Write Edit NotebookEdit Bash
|
|
12
|
+
* (mutation/execution tools removed; reads still allowed)
|
|
13
|
+
* - workspace-write → no permission flag — Claude's default headless behavior
|
|
14
|
+
* (the verified default working mode)
|
|
15
|
+
* - full-access → --permission-mode bypassPermissions (only when the
|
|
16
|
+
* caller explicitly opts into full access)
|
|
17
|
+
* We never pass `--dangerously-skip-permissions`; `bypassPermissions` is the
|
|
18
|
+
* supported, intentional opt-in used solely for the full-access level.
|
|
15
19
|
*
|
|
16
20
|
* Authentication note:
|
|
17
21
|
* Auth state is probed at detect() time by spawning `claude auth status` and
|
|
@@ -25,7 +29,19 @@
|
|
|
25
29
|
* types/subprocess/subprocess.d.ts: the subprocess IS an AsyncIterable that
|
|
26
30
|
* yields one string per stdout line.
|
|
27
31
|
*/
|
|
28
|
-
import type { Provider } from './port.js';
|
|
32
|
+
import type { Provider, ProviderRequest } from './port.js';
|
|
33
|
+
/**
|
|
34
|
+
* Build the `claude` CLI argv for a request. Pure and exported so flag
|
|
35
|
+
* construction — model alias, native-session flags, and sandbox/permission
|
|
36
|
+
* flags — is unit-testable without spawning a real CLI.
|
|
37
|
+
*
|
|
38
|
+
* Native session (opt-in): when `req.sessionId` is set, add `--resume <id>` to
|
|
39
|
+
* continue an existing session, or `--session-id <id>` to establish a new one
|
|
40
|
+
* with our chosen id. When unset, the run is a stateless one-shot (the default).
|
|
41
|
+
*
|
|
42
|
+
* Sandbox flags are appended LAST because `--disallowedTools` is variadic.
|
|
43
|
+
*/
|
|
44
|
+
export declare function buildClaudeArgs(req: ProviderRequest): string[];
|
|
29
45
|
/**
|
|
30
46
|
* Create a Claude provider adapter.
|
|
31
47
|
*
|
package/dist/providers/claude.js
CHANGED
|
@@ -5,13 +5,17 @@
|
|
|
5
5
|
* delivers the prompt via STDIN (never as an argv argument), and streams
|
|
6
6
|
* parsed ProviderEvents to the caller as they arrive.
|
|
7
7
|
*
|
|
8
|
-
* Sandbox enforcement
|
|
9
|
-
* The `req.sandbox` level is
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
8
|
+
* Sandbox enforcement:
|
|
9
|
+
* The `req.sandbox` privilege level is mapped to real Claude CLI flags (see
|
|
10
|
+
* claudeSandboxArgs):
|
|
11
|
+
* - read-only → --disallowedTools Write Edit NotebookEdit Bash
|
|
12
|
+
* (mutation/execution tools removed; reads still allowed)
|
|
13
|
+
* - workspace-write → no permission flag — Claude's default headless behavior
|
|
14
|
+
* (the verified default working mode)
|
|
15
|
+
* - full-access → --permission-mode bypassPermissions (only when the
|
|
16
|
+
* caller explicitly opts into full access)
|
|
17
|
+
* We never pass `--dangerously-skip-permissions`; `bypassPermissions` is the
|
|
18
|
+
* supported, intentional opt-in used solely for the full-access level.
|
|
15
19
|
*
|
|
16
20
|
* Authentication note:
|
|
17
21
|
* Auth state is probed at detect() time by spawning `claude auth status` and
|
|
@@ -51,6 +55,59 @@ function toClaudeModelArg(model) {
|
|
|
51
55
|
return 'haiku';
|
|
52
56
|
return model;
|
|
53
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* Map the abstract privilege ladder to Claude CLI permission flags. Pure.
|
|
60
|
+
*
|
|
61
|
+
* - read-only → remove mutation/execution tools (reads still allowed)
|
|
62
|
+
* - workspace-write → no flag (Claude's default headless behavior)
|
|
63
|
+
* - full-access → --permission-mode bypassPermissions (explicit opt-in)
|
|
64
|
+
*
|
|
65
|
+
* Never emits `--dangerously-skip-permissions`. The mutation tool list uses the
|
|
66
|
+
* stable Claude Code tool names (Write/Edit/NotebookEdit/Bash); unknown names
|
|
67
|
+
* are harmless. `--disallowedTools` is variadic, so callers append it LAST.
|
|
68
|
+
*/
|
|
69
|
+
function claudeSandboxArgs(sandbox) {
|
|
70
|
+
switch (sandbox) {
|
|
71
|
+
case 'read-only':
|
|
72
|
+
return ['--disallowedTools', 'Write', 'Edit', 'NotebookEdit', 'Bash'];
|
|
73
|
+
case 'full-access':
|
|
74
|
+
return ['--permission-mode', 'bypassPermissions'];
|
|
75
|
+
case 'workspace-write':
|
|
76
|
+
default:
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build the `claude` CLI argv for a request. Pure and exported so flag
|
|
82
|
+
* construction — model alias, native-session flags, and sandbox/permission
|
|
83
|
+
* flags — is unit-testable without spawning a real CLI.
|
|
84
|
+
*
|
|
85
|
+
* Native session (opt-in): when `req.sessionId` is set, add `--resume <id>` to
|
|
86
|
+
* continue an existing session, or `--session-id <id>` to establish a new one
|
|
87
|
+
* with our chosen id. When unset, the run is a stateless one-shot (the default).
|
|
88
|
+
*
|
|
89
|
+
* Sandbox flags are appended LAST because `--disallowedTools` is variadic.
|
|
90
|
+
*/
|
|
91
|
+
export function buildClaudeArgs(req) {
|
|
92
|
+
const args = [
|
|
93
|
+
'-p',
|
|
94
|
+
'--output-format',
|
|
95
|
+
'stream-json',
|
|
96
|
+
'--verbose',
|
|
97
|
+
'--model',
|
|
98
|
+
toClaudeModelArg(req.model),
|
|
99
|
+
];
|
|
100
|
+
if (req.sessionId !== undefined && req.sessionId.length > 0) {
|
|
101
|
+
if (req.resume === true) {
|
|
102
|
+
args.push('--resume', req.sessionId);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
args.push('--session-id', req.sessionId);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
args.push(...claudeSandboxArgs(req.sandbox));
|
|
109
|
+
return args;
|
|
110
|
+
}
|
|
54
111
|
// ---------------------------------------------------------------------------
|
|
55
112
|
// Factory
|
|
56
113
|
// ---------------------------------------------------------------------------
|
|
@@ -67,14 +124,7 @@ export function createClaudeProvider(opts) {
|
|
|
67
124
|
return detectProvider('claude');
|
|
68
125
|
},
|
|
69
126
|
async *run(req, signal) {
|
|
70
|
-
const args =
|
|
71
|
-
'-p',
|
|
72
|
-
'--output-format',
|
|
73
|
-
'stream-json',
|
|
74
|
-
'--verbose',
|
|
75
|
-
'--model',
|
|
76
|
-
toClaudeModelArg(req.model),
|
|
77
|
-
];
|
|
127
|
+
const args = buildClaudeArgs(req);
|
|
78
128
|
// Load the stored Claude OAuth token and scope it to this child process
|
|
79
129
|
// only — never written into the global process.env.
|
|
80
130
|
let childEnv = process.env;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/providers/claude.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"claude.js","sourceRoot":"","sources":["../../src/providers/claude.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAG9B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAErE,8EAA8E;AAC9E,sBAAsB;AACtB,8EAA8E;AAE9E;;;;;;;;GAQG;AACH,SAAS,gBAAgB,CAAC,KAAa;IACrC,IAAI,KAAK,CAAC,UAAU,CAAC,aAAa,CAAC;QAAE,OAAO,MAAM,CAAC;IACnD,IAAI,KAAK,CAAC,UAAU,CAAC,eAAe,CAAC;QAAE,OAAO,QAAQ,CAAC;IACvD,IAAI,KAAK,CAAC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BACzB,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;YAAC,MAAM,CAAC;gBACP,yEAAyE;YAC3E,CAAC;YAED,gEAAgE;YAChE,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC;YAEhC,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrB,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;oBACtB,MAAM;wBACJ,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;qBACrC,CAAC;gBACJ,CAAC;qBAAM,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;oBACrF,MAAM;wBACJ,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE,aAAa,CAClB,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EACtD,MAAM,CAAC,QAAQ,IAAI,CAAC,CACrB;qBACF,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -49,6 +49,9 @@ function mapUsage(u) {
|
|
|
49
49
|
*/
|
|
50
50
|
export function createCodexParser() {
|
|
51
51
|
let accumulatedText = '';
|
|
52
|
+
// Captured from `thread.started` so the terminal `done` event can carry the
|
|
53
|
+
// Codex thread id — used to resume the native session on a later turn.
|
|
54
|
+
let threadId;
|
|
52
55
|
return function parseCodexLine(line) {
|
|
53
56
|
const trimmed = line.trim();
|
|
54
57
|
if (!trimmed)
|
|
@@ -65,9 +68,17 @@ export function createCodexParser() {
|
|
|
65
68
|
const obj = parsed;
|
|
66
69
|
const eventType = obj['type'];
|
|
67
70
|
// -----------------------------------------------------------------------
|
|
68
|
-
// thread.started
|
|
71
|
+
// thread.started — capture the thread id (for native-session resume).
|
|
72
|
+
// turn.started — emit nothing.
|
|
69
73
|
// -----------------------------------------------------------------------
|
|
70
|
-
if (eventType === 'thread.started'
|
|
74
|
+
if (eventType === 'thread.started') {
|
|
75
|
+
const tid = obj['thread_id'];
|
|
76
|
+
if (typeof tid === 'string' && tid.length > 0) {
|
|
77
|
+
threadId = tid;
|
|
78
|
+
}
|
|
79
|
+
return [];
|
|
80
|
+
}
|
|
81
|
+
if (eventType === 'turn.started') {
|
|
71
82
|
return [];
|
|
72
83
|
}
|
|
73
84
|
// -----------------------------------------------------------------------
|
|
@@ -118,6 +129,7 @@ export function createCodexParser() {
|
|
|
118
129
|
type: 'done',
|
|
119
130
|
text: accumulatedText,
|
|
120
131
|
usage,
|
|
132
|
+
...(threadId !== undefined ? { sessionId: threadId } : {}),
|
|
121
133
|
raw: parsed,
|
|
122
134
|
},
|
|
123
135
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex-parse.js","sourceRoot":"","sources":["../../src/providers/codex-parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAqD5C,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E,SAAS,QAAQ,CAAC,CAAgB;IAChC,MAAM,IAAI,GAAU;QAClB,WAAW,EAAE,CAAC,CAAC,YAAY,IAAI,CAAC;QAChC,YAAY,EAAE,CAAC,CAAC,aAAa,IAAI,CAAC;KACnC,CAAC;IAEF,0EAA0E;IAC1E,4CAA4C;IAC5C,IAAI,OAAO,CAAC,CAAC,mBAAmB,KAAK,QAAQ,EAAE,CAAC;QAC9C,OAAO,EAAE,GAAG,IAAI,EAAE,iBAAiB,EAAE,CAAC,CAAC,mBAAmB,EAAE,CAAC;IAC/D,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,8EAA8E;AAC9E,aAAa;AACb,8EAA8E;AAE9E;;;;;;;;;GASG;AACH,MAAM,UAAU,iBA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,eAAe;oBACrB,KAAK;oBACL,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;oBAC1D,GAAG,EAAE,MAAM;iBACZ;aACF,CAAC;QACJ,CAAC;QAED,0EAA0E;QAC1E,2BAA2B;QAC3B,0EAA0E;QAC1E,IAAI,SAAS,KAAK,aAAa,EAAE,CAAC;YAChC,MAAM,EAAE,GAAG,MAAwB,CAAC;YACpC,MAAM,OAAO,GAAG,EAAE,CAAC,KAAK,EAAE,OAAO,IAAI,aAAa,CAAC;YACnD,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QAC/D,CAAC;QAED,0EAA0E;QAC1E,qBAAqB;QACrB,0EAA0E;QAC1E,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;YAC1B,MAAM,EAAE,GAAG,MAAmB,CAAC;YAC/B,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,IAAI,eAAe,CAAC;YAC9C,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QAC/D,CAAC;QAED,oCAAoC;QACpC,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -27,7 +27,19 @@
|
|
|
27
27
|
* lines as strings. Confirmed from execa types: the subprocess IS an
|
|
28
28
|
* AsyncIterable<string>.
|
|
29
29
|
*/
|
|
30
|
-
import type { Provider } from './port.js';
|
|
30
|
+
import type { Provider, ProviderRequest } from './port.js';
|
|
31
|
+
/**
|
|
32
|
+
* Build the `codex` CLI argv for a request. Pure and exported so arg
|
|
33
|
+
* construction — including the EXPERIMENTAL native-session resume form — is
|
|
34
|
+
* unit-testable without spawning a real CLI.
|
|
35
|
+
*
|
|
36
|
+
* Default (one-shot / establish): `exec --json -m <model> --sandbox <level>`.
|
|
37
|
+
* Resume (native session, opt-in): `exec resume <thread-id> --json -m <model>
|
|
38
|
+
* --sandbox <level>` — Codex generates the thread id, so resume continues a
|
|
39
|
+
* thread captured from a prior turn (see codex-parse `thread.started`). Prompt
|
|
40
|
+
* is delivered via STDIN in both cases.
|
|
41
|
+
*/
|
|
42
|
+
export declare function buildCodexArgs(req: ProviderRequest): string[];
|
|
31
43
|
/**
|
|
32
44
|
* Create a Codex provider adapter.
|
|
33
45
|
*
|
package/dist/providers/codex.js
CHANGED
|
@@ -51,6 +51,24 @@ function toSandboxArg(level) {
|
|
|
51
51
|
return 'danger-full-access';
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Build the `codex` CLI argv for a request. Pure and exported so arg
|
|
56
|
+
* construction — including the EXPERIMENTAL native-session resume form — is
|
|
57
|
+
* unit-testable without spawning a real CLI.
|
|
58
|
+
*
|
|
59
|
+
* Default (one-shot / establish): `exec --json -m <model> --sandbox <level>`.
|
|
60
|
+
* Resume (native session, opt-in): `exec resume <thread-id> --json -m <model>
|
|
61
|
+
* --sandbox <level>` — Codex generates the thread id, so resume continues a
|
|
62
|
+
* thread captured from a prior turn (see codex-parse `thread.started`). Prompt
|
|
63
|
+
* is delivered via STDIN in both cases.
|
|
64
|
+
*/
|
|
65
|
+
export function buildCodexArgs(req) {
|
|
66
|
+
const opts = ['--json', '-m', req.model, '--sandbox', toSandboxArg(req.sandbox)];
|
|
67
|
+
if (req.sessionId !== undefined && req.sessionId.length > 0 && req.resume === true) {
|
|
68
|
+
return ['exec', 'resume', req.sessionId, ...opts];
|
|
69
|
+
}
|
|
70
|
+
return ['exec', ...opts];
|
|
71
|
+
}
|
|
54
72
|
// ---------------------------------------------------------------------------
|
|
55
73
|
// Factory
|
|
56
74
|
// ---------------------------------------------------------------------------
|
|
@@ -67,14 +85,7 @@ export function createCodexProvider(opts) {
|
|
|
67
85
|
return detectProvider('codex');
|
|
68
86
|
},
|
|
69
87
|
async *run(req, signal) {
|
|
70
|
-
const args =
|
|
71
|
-
'exec',
|
|
72
|
-
'--json',
|
|
73
|
-
'-m',
|
|
74
|
-
req.model,
|
|
75
|
-
'--sandbox',
|
|
76
|
-
toSandboxArg(req.sandbox),
|
|
77
|
-
];
|
|
88
|
+
const args = buildCodexArgs(req);
|
|
78
89
|
// Spawn with reject:false so we always get the result object (never throws).
|
|
79
90
|
// cancelSignal wires our AbortSignal directly to execa's termination path.
|
|
80
91
|
const subprocess = execa(bin, args, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex.js","sourceRoot":"","sources":["../../src/providers/codex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAG9B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAErD,8EAA8E;AAC9E,2BAA2B;AAC3B,8EAA8E;AAE9E;;;;;;GAMG;AACH,SAAS,YAAY,CAAC,KAAmB;IACvC,QAAQ,KAAK,EAAE,CAAC;QACd,KAAK,WAAW;YACd,OAAO,WAAW,CAAC;QACrB,KAAK,iBAAiB;YACpB,OAAO,iBAAiB,CAAC;QAC3B,KAAK,aAAa;YAChB,OAAO,oBAAoB,CAAC;IAChC,CAAC;AACH,CAAC;AAED,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,UAAU,mBAAmB,CAAC,IAAuB;IACzD,MAAM,GAAG,GAAG,IAAI,EAAE,GAAG,IAAI,OAAO,CAAC;IAEjC,OAAO;QACL,EAAE,EAAE,OAAO;QAEX,MAAM;YACJ,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC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M,UAAU,CAAC;YAEhC,IAAI,CAAC,eAAe,EAAE,CAAC;gBACrB,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;oBACtB,MAAM;wBACJ,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE,aAAa,CAAC,WAAW,EAAE,CAAC,CAAC;qBACrC,CAAC;gBACJ,CAAC;qBAAM,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;oBACrF,MAAM;wBACJ,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE,aAAa,CAClB,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EACtD,MAAM,CAAC,QAAQ,IAAI,CAAC,CACrB;qBACF,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/providers/port.d.ts
CHANGED
|
@@ -34,6 +34,15 @@ export interface ProviderRequest {
|
|
|
34
34
|
readonly sandbox: SandboxLevel;
|
|
35
35
|
/** Hard wall-clock timeout for the run. */
|
|
36
36
|
readonly timeoutMs: number;
|
|
37
|
+
/**
|
|
38
|
+
* EXPERIMENTAL native session continuity (opt-in). When set, the adapter uses
|
|
39
|
+
* the provider's native session so prior context is carried server-side
|
|
40
|
+
* instead of replayed in the prompt. Claude: `--session-id <id>` to establish,
|
|
41
|
+
* `--resume <id>` to continue. Omitted → stateless one-shot (the default).
|
|
42
|
+
*/
|
|
43
|
+
readonly sessionId?: string;
|
|
44
|
+
/** With sessionId: true continues an existing session, false establishes it. */
|
|
45
|
+
readonly resume?: boolean;
|
|
37
46
|
}
|
|
38
47
|
/**
|
|
39
48
|
* Streaming events emitted by a provider run. Discriminated on `type`.
|
|
@@ -60,6 +69,12 @@ export type ProviderEvent = {
|
|
|
60
69
|
/** Cost in USD as reported by the provider CLI, when available (preferred
|
|
61
70
|
* over estimating from the pricing table — it accounts for caching etc.). */
|
|
62
71
|
readonly costUsd?: number;
|
|
72
|
+
/**
|
|
73
|
+
* Provider-assigned session/thread id, when the CLI reports one (e.g. Codex
|
|
74
|
+
* `thread.started.thread_id`). Captured so a later turn can resume the
|
|
75
|
+
* native session. Absent when the provider does not surface an id.
|
|
76
|
+
*/
|
|
77
|
+
readonly sessionId?: string;
|
|
63
78
|
readonly raw: unknown;
|
|
64
79
|
} | {
|
|
65
80
|
readonly type: 'error';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/ui/help.ts — per-command help text.
|
|
3
|
+
*
|
|
4
|
+
* The global `myshell-tools --help` lists all commands; this module provides
|
|
5
|
+
* the focused, command-specific help shown for `myshell-tools <command> --help`
|
|
6
|
+
* (e.g. `login --help` explains the sign-in methods instead of dumping the
|
|
7
|
+
* generic command list).
|
|
8
|
+
*
|
|
9
|
+
* Pure string building — no I/O, trivially unit-testable.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Return focused help text for a known subcommand, or null when the command has
|
|
13
|
+
* no dedicated help (callers fall back to the global help).
|
|
14
|
+
*
|
|
15
|
+
* @param command - The first CLI argument (e.g. "login", "cost").
|
|
16
|
+
*/
|
|
17
|
+
export declare function commandHelpText(command: string): string | null;
|
package/dist/ui/help.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* src/ui/help.ts — per-command help text.
|
|
3
|
+
*
|
|
4
|
+
* The global `myshell-tools --help` lists all commands; this module provides
|
|
5
|
+
* the focused, command-specific help shown for `myshell-tools <command> --help`
|
|
6
|
+
* (e.g. `login --help` explains the sign-in methods instead of dumping the
|
|
7
|
+
* generic command list).
|
|
8
|
+
*
|
|
9
|
+
* Pure string building — no I/O, trivially unit-testable.
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Return focused help text for a known subcommand, or null when the command has
|
|
13
|
+
* no dedicated help (callers fall back to the global help).
|
|
14
|
+
*
|
|
15
|
+
* @param command - The first CLI argument (e.g. "login", "cost").
|
|
16
|
+
*/
|
|
17
|
+
export function commandHelpText(command) {
|
|
18
|
+
switch (command) {
|
|
19
|
+
case 'login':
|
|
20
|
+
return [
|
|
21
|
+
'myshell-tools login [provider] [--code | --browser]',
|
|
22
|
+
'',
|
|
23
|
+
'Sign in to a provider via its own OAuth. myshell-tools never handles',
|
|
24
|
+
'your credentials — it drives each CLI\'s native sign-in.',
|
|
25
|
+
'',
|
|
26
|
+
'Arguments:',
|
|
27
|
+
' provider claude | codex | opencode (omit to be prompted)',
|
|
28
|
+
'',
|
|
29
|
+
'Options:',
|
|
30
|
+
' --code No-localhost flow — paste a code (claude) or use a device',
|
|
31
|
+
' code (codex). Best inside containers / over SSH.',
|
|
32
|
+
' --browser Force the localhost browser flow (desktop).',
|
|
33
|
+
' (omitted) Auto-detect: headless/SSH/cloud-IDE → code, desktop → browser.',
|
|
34
|
+
'',
|
|
35
|
+
'Examples:',
|
|
36
|
+
' myshell-tools login # prompt for provider, auto-detect method',
|
|
37
|
+
' myshell-tools login claude --code # paste the sk-ant-oat… token',
|
|
38
|
+
' myshell-tools login codex --code # device-code flow (no localhost)',
|
|
39
|
+
].join('\n') + '\n';
|
|
40
|
+
case 'cost':
|
|
41
|
+
return [
|
|
42
|
+
'myshell-tools cost',
|
|
43
|
+
'',
|
|
44
|
+
'Show usage and routing efficiency from the local ledger.',
|
|
45
|
+
'',
|
|
46
|
+
'Leads with REAL, measured tokens (overall and per model) and a',
|
|
47
|
+
'billing-agnostic routing-efficiency ratio (how many flagship tokens you',
|
|
48
|
+
'avoided). Because this drives your SUBSCRIPTION CLIs — not metered API',
|
|
49
|
+
'keys — any dollar figure is shown only as a clearly-labeled',
|
|
50
|
+
'API-equivalent estimate, not your actual bill.',
|
|
51
|
+
].join('\n') + '\n';
|
|
52
|
+
case 'run':
|
|
53
|
+
return [
|
|
54
|
+
'myshell-tools run <task...>',
|
|
55
|
+
'',
|
|
56
|
+
'Run a one-shot task and exit (non-interactive).',
|
|
57
|
+
'',
|
|
58
|
+
'The task is classified, routed to the cheapest capable tier, executed on',
|
|
59
|
+
'your real working directory, and optionally reviewed by a different vendor.',
|
|
60
|
+
'',
|
|
61
|
+
'Example:',
|
|
62
|
+
' myshell-tools run "refactor the auth module and add tests"',
|
|
63
|
+
].join('\n') + '\n';
|
|
64
|
+
case 'status':
|
|
65
|
+
case 'check':
|
|
66
|
+
case 'doctor':
|
|
67
|
+
return [
|
|
68
|
+
`myshell-tools ${command}`,
|
|
69
|
+
'',
|
|
70
|
+
'Print a full environment health report: platform, Node version, state-',
|
|
71
|
+
'directory writability, pricing freshness, and per-provider install/auth.',
|
|
72
|
+
'',
|
|
73
|
+
'You normally never need this — the control panel surfaces any problem on',
|
|
74
|
+
'its own. It exists for support threads and CI. (`status`, `check`, and the',
|
|
75
|
+
'legacy `doctor` are aliases.)',
|
|
76
|
+
'',
|
|
77
|
+
'Options:',
|
|
78
|
+
' --fix Interactively install missing providers, sign in, and',
|
|
79
|
+
' refresh an expiring Claude token.',
|
|
80
|
+
].join('\n') + '\n';
|
|
81
|
+
case 'install':
|
|
82
|
+
return [
|
|
83
|
+
'myshell-tools install',
|
|
84
|
+
'',
|
|
85
|
+
'Write a guarded startup hook to your shell rc file so new interactive',
|
|
86
|
+
'shells launch myshell-tools automatically. Reports exactly what it wrote',
|
|
87
|
+
'and how to reverse it. Use `myshell-tools uninstall` to remove it.',
|
|
88
|
+
].join('\n') + '\n';
|
|
89
|
+
case 'uninstall':
|
|
90
|
+
return [
|
|
91
|
+
'myshell-tools uninstall',
|
|
92
|
+
'',
|
|
93
|
+
'Remove the guarded startup hook written by `myshell-tools install`.',
|
|
94
|
+
].join('\n') + '\n';
|
|
95
|
+
case 'repl':
|
|
96
|
+
return [
|
|
97
|
+
'myshell-tools repl',
|
|
98
|
+
'',
|
|
99
|
+
'Start a plain line-based REPL (no control-panel menu). Each line you type',
|
|
100
|
+
'is run as a task. Useful for scripting or minimal terminals.',
|
|
101
|
+
].join('\n') + '\n';
|
|
102
|
+
default:
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=help.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"help.js","sourceRoot":"","sources":["../../src/ui/help.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,OAAe;IAC7C,QAAQ,OAAO,EAAE,CAAC;QAChB,KAAK,OAAO;YACV,OAAO;gBACL,qDAAqD;gBACrD,EAAE;gBACF,sEAAsE;gBACtE,0DAA0D;gBAC1D,EAAE;gBACF,YAAY;gBACZ,gEAAgE;gBAChE,EAAE;gBACF,UAAU;gBACV,0EAA0E;gBAC1E,iEAAiE;gBACjE,4DAA4D;gBAC5D,+EAA+E;gBAC/E,EAAE;gBACF,WAAW;gBACX,iFAAiF;gBACjF,qEAAqE;gBACrE,yEAAyE;aAC1E,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QAEtB,KAAK,MAAM;YACT,OAAO;gBACL,oBAAoB;gBACpB,EAAE;gBACF,0DAA0D;gBAC1D,EAAE;gBACF,gEAAgE;gBAChE,yEAAyE;gBACzE,wEAAwE;gBACxE,6DAA6D;gBAC7D,gDAAgD;aACjD,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QAEtB,KAAK,KAAK;YACR,OAAO;gBACL,6BAA6B;gBAC7B,EAAE;gBACF,iDAAiD;gBACjD,EAAE;gBACF,0EAA0E;gBAC1E,6EAA6E;gBAC7E,EAAE;gBACF,UAAU;gBACV,8DAA8D;aAC/D,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;QAEtB,KAAK,QAAQ,CAAC;QACd,KAAK,OAAO,CAAC;QACb,KAAK,QAAQ;YACX,OAAO;gB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