@cmodjs/core 4.3.4 → 5.0.1
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/docs/commands.md +19 -30
- package/docs/dependencies.md +7 -5
- package/docs/index.md +4 -5
- package/docs/install-steps.md +12 -14
- package/docs/jobs.md +3 -11
- package/docs/mod.md +18 -21
- package/docs/session.md +11 -11
- package/docs/state.md +1 -1
- package/docs/testing.md +3 -5
- package/docs/ui.md +3 -3
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +3 -17
- package/mod.d.ts +0 -16
- package/mod.d.ts.map +1 -1
- package/package.json +2 -2
- package/records.d.ts +4 -11
- package/records.d.ts.map +1 -1
- package/records.js +17 -48
- package/runtime/announce.d.ts +1 -1
- package/runtime/announce.d.ts.map +1 -1
- package/runtime/announce.js +2 -3
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +3 -46
- package/runtime/engine.d.ts +2 -2
- package/runtime/engine.d.ts.map +1 -1
- package/runtime/installer.d.ts +0 -9
- package/runtime/installer.d.ts.map +1 -1
- package/runtime/installer.js +1 -15
- package/runtime/lifecycle.d.ts +1 -2
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +37 -191
- package/runtime/metadata.d.ts +1 -2
- package/runtime/metadata.d.ts.map +1 -1
- package/runtime/metadata.js +1 -2
- package/runtime/sessions.d.ts +3 -7
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +10 -34
- package/runtime/toaster.d.ts.map +1 -1
- package/runtime/toaster.js +6 -9
- package/src/jobs/program.ts +3 -17
- package/src/mod.ts +0 -18
- package/src/records.ts +20 -55
- package/src/runtime/announce.ts +2 -3
- package/src/runtime/conversations.ts +3 -45
- package/src/runtime/engine.ts +2 -2
- package/src/runtime/installer.ts +1 -37
- package/src/runtime/lifecycle.ts +38 -188
- package/src/runtime/metadata.ts +0 -3
- package/src/runtime/sessions.ts +10 -39
- package/src/runtime/toaster.ts +6 -9
- package/src/testing.ts +9 -14
- package/testing.d.ts +0 -1
- package/testing.d.ts.map +1 -1
- package/testing.js +9 -13
- package/docs/permissions.md +0 -97
- package/runtime/grants.d.ts +0 -34
- package/runtime/grants.d.ts.map +0 -1
- package/runtime/grants.js +0 -326
- package/src/runtime/grants.ts +0 -348
package/runtime/sessions.js
CHANGED
|
@@ -37,21 +37,8 @@ export function pickedColor(args) {
|
|
|
37
37
|
const picked = args.trim().toLowerCase();
|
|
38
38
|
return resetColors.includes(picked) ? undefined : picked;
|
|
39
39
|
}
|
|
40
|
-
const
|
|
41
|
-
const
|
|
42
|
-
const ownSchedule = ['CronDelete', 'CronList'];
|
|
43
|
-
export const beforePermission = (event) => (event === 'toolCall' ? 'tools' : event === TaskStart ? 'tasks' : 'prompt');
|
|
44
|
-
const answerPermissions = (event, answer) => [
|
|
45
|
-
...(Object.keys(answer).some((key) => key !== 'note') ? [beforePermission(event)] : []),
|
|
46
|
-
...(answer.note === undefined ? [] : ['prompt']),
|
|
47
|
-
];
|
|
48
|
-
export const isAct = (action) => action === 'callTool' || action in actPermissions;
|
|
49
|
-
export function toolPermission(tool) {
|
|
50
|
-
return startsTurns.includes(tool) ? 'prompt' : ownSchedule.includes(tool) ? undefined : 'tools';
|
|
51
|
-
}
|
|
52
|
-
export function actPermission(action, input) {
|
|
53
|
-
return action === 'callTool' ? (toolPermission(String(input?.name)) ?? 'tools') : actPermissions[action];
|
|
54
|
-
}
|
|
40
|
+
const acts = ['send', 'startTask', 'fork', 'clone', 'startBackgroundTask', 'callTool', 'usage', 'surfaces', 'abort'];
|
|
41
|
+
export const isAct = (action) => acts.includes(action);
|
|
55
42
|
export async function usageOf(claude) {
|
|
56
43
|
const [model, usage] = await Promise.all([claude.session.model(), claude.session.usage()]);
|
|
57
44
|
const { tokens, window, percent } = usage.context;
|
|
@@ -126,7 +113,7 @@ export function isInScope(scope, session, change, isUnder) {
|
|
|
126
113
|
export function withoutPermissionCheck(name, hearer) {
|
|
127
114
|
return `${name}: ${hearer} hears Claude Code's permission check, so hooks/register.ts must call registerPermissionCheck(addHook) after registerMod.`;
|
|
128
115
|
}
|
|
129
|
-
export function createSessionsClient({ name, claude, report,
|
|
116
|
+
export function createSessionsClient({ name, claude, report, hookOn, routeOn, permissionRoutes }) {
|
|
130
117
|
const call = (method, input) => claude.cmod.call({ to: cmodPluginName, method, input });
|
|
131
118
|
const listening = new Map();
|
|
132
119
|
const deciding = new Map();
|
|
@@ -200,20 +187,13 @@ export function createSessionsClient({ name, claude, report, isGranted, permissi
|
|
|
200
187
|
});
|
|
201
188
|
const decidersOf = (session, event, isInProject) => [...(deciding.get(session) ?? []), ...(isInProject ? (deciding.get(everySession) ?? []) : [])].filter((entry) => entry.event === event);
|
|
202
189
|
const decides = (entry, session, change) => isInScope(entry.scope, session, change, isUnderIn(session)) && (entry.matcher === undefined || matches(payloadOf(change), entry.matcher));
|
|
203
|
-
const mayDecide = (session) => session === current.id || isGranted('conversation');
|
|
204
190
|
const combined = async (session, event, change, isInProject) => {
|
|
205
191
|
const askers = decidersOf(session, event, isInProject)
|
|
206
192
|
.map((entry) => async (latest) => {
|
|
207
193
|
if (!decides(entry, session, latest))
|
|
208
194
|
return undefined;
|
|
209
195
|
const payload = await payloadFor(session, latest);
|
|
210
|
-
|
|
211
|
-
if (answer === undefined || answer === null || (typeof answer === 'object' && 'refuse' in answer))
|
|
212
|
-
return answer;
|
|
213
|
-
const missing = answerPermissions(event, answer).find((permission) => !isGranted(permission));
|
|
214
|
-
if (missing === undefined)
|
|
215
|
-
return answer;
|
|
216
|
-
throw new Error(permissionRefusal(`${entry.method} with the answer { ${Object.keys(answer).join(', ')} }`, missing));
|
|
196
|
+
return invoke(entry.method, entry.options, async (time) => takenAnswer(entry.method, beforeAnswerKeys[event], await entry.listener(payload, time)), beforeAnswerKeys[event]);
|
|
217
197
|
});
|
|
218
198
|
const answer = await foldBefore(event, change, askers, (error) => report(`session:${methodOf('before', event)}`, `The ${methodOf('before', event)} listener failed`, error));
|
|
219
199
|
return answer?.note === undefined ? answer : { ...answer, note: modNote(name, answer.note) };
|
|
@@ -464,15 +444,12 @@ export function createSessionsClient({ name, claude, report, isGranted, permissi
|
|
|
464
444
|
const answer = commandListeners.beforeRun.size === 0 ? undefined : await raise('beforeRun', run);
|
|
465
445
|
if (typeof answer?.['refuse'] === 'string')
|
|
466
446
|
return { text: answer['refuse'] };
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
if (typeof changes?.['result'] === 'string')
|
|
471
|
-
return { text: changes['result'], ...(typeof changes['exitCode'] === 'number' ? { exitCode: changes['exitCode'] } : {}) };
|
|
472
|
-
const args = typeof changes?.['args'] === 'string' ? changes['args'] : e.args;
|
|
447
|
+
if (typeof answer?.['result'] === 'string')
|
|
448
|
+
return { text: answer['result'], ...(typeof answer['exitCode'] === 'number' ? { exitCode: answer['exitCode'] } : {}) };
|
|
449
|
+
const args = typeof answer?.['args'] === 'string' ? answer['args'] : e.args;
|
|
473
450
|
const ran = await next(args === e.args ? e : { ...e, args });
|
|
474
451
|
void raise('onRun', { ...run, args });
|
|
475
|
-
return typeof
|
|
452
|
+
return typeof answer?.['note'] === 'string' ? { ...ran, context: [...(ran.context ?? []), modNote(name, answer['note'])] } : ran;
|
|
476
453
|
}, async (e, error) => {
|
|
477
454
|
const refusal = commandListeners.beforeRun.size === 0 ? undefined : refusalFor('beforeRun', await commandRun(e), error);
|
|
478
455
|
return refusal === undefined ? undefined : { text: refusal.refuse };
|
|
@@ -561,9 +538,8 @@ export function createSessionsClient({ name, claude, report, isGranted, permissi
|
|
|
561
538
|
caption: (toolCall, text) => claude.ui.notice(toolCall.callId, text),
|
|
562
539
|
});
|
|
563
540
|
const every = eventMethods(() => ({}), false);
|
|
564
|
-
const answerBefore = async (session, event, change, isInProject) => (mayDecide(session) ? combined(session, event, change, isInProject) : undefined);
|
|
565
541
|
const failedBefore = (session, event, change, isInProject, error) => {
|
|
566
|
-
const asked =
|
|
542
|
+
const asked = decidersOf(session, event, isInProject).filter((entry) => decides(entry, session, change));
|
|
567
543
|
return asked.map((entry) => refusalOf(entry.options, beforeAnswerKeys[event], error)).find((answer) => answer !== undefined);
|
|
568
544
|
};
|
|
569
545
|
return {
|
|
@@ -597,7 +573,7 @@ export function createSessionsClient({ name, claude, report, isGranted, permissi
|
|
|
597
573
|
}
|
|
598
574
|
}
|
|
599
575
|
},
|
|
600
|
-
answerBefore,
|
|
576
|
+
answerBefore: combined,
|
|
601
577
|
failedBefore,
|
|
602
578
|
raise,
|
|
603
579
|
listen,
|
package/runtime/toaster.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toaster.d.ts","sourceRoot":"","sources":["../src/runtime/toaster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAS,MAAM,aAAa,CAAA;AACpF,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAgB,SAAS,EAAE,MAAM,WAAW,CAAA;AAIxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAIzC,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9G,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC;IAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAE/L,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAEnO,eAAO,MAAM,YAAY,gBAAgB,CAAA;AAEzC,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAA;IACrC,IAAI,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAAA;CACnH,CAAA;AAID,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAyCrI,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,MAAM,GAAG,SAAS,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"toaster.d.ts","sourceRoot":"","sources":["../src/runtime/toaster.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,aAAa,EAAS,MAAM,aAAa,CAAA;AACpF,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAgB,SAAS,EAAE,MAAM,WAAW,CAAA;AAIxE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAIzC,MAAM,MAAM,UAAU,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AAE9G,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,OAAO,CAAC;IAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAE/L,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,CAAA;AAEnO,eAAO,MAAM,YAAY,gBAAgB,CAAA;AAEzC,MAAM,MAAM,OAAO,GAAG;IACpB,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACjC,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAA;IAC/B,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,CAAA;IACrC,IAAI,CAAC,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,aAAa,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CAAA;CACnH,CAAA;AAID,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAyCrI,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,MAAM,GAAG,SAAS,GAAG,OAAO,CA+StG;AA2BD,wBAAgB,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,aAAa,CAS1G;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,SAAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQhG"}
|
package/runtime/toaster.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Box, Button, drawWith, Link, Text } from '../ui/elements.js';
|
|
2
|
-
import { coreVersion,
|
|
2
|
+
import { coreVersion, installFix, isObject, secretFix } from '../records.js';
|
|
3
3
|
import { firstLine, messageOf } from '../utils/text.js';
|
|
4
4
|
import { beforeDeadline } from './deadline.js';
|
|
5
5
|
import { cmodPluginName } from './dependencies.js';
|
|
@@ -172,16 +172,13 @@ export function createToaster(claude, name, version) {
|
|
|
172
172
|
.catch((failure) => `unknown (${messageOf(failure)})`);
|
|
173
173
|
return `${name} ${modVersion}, @cmodjs/core ${coreVersion}, at ${failedAt.toISOString()}\n${message}${description === undefined ? '' : `\n${description}`}${stack}`;
|
|
174
174
|
};
|
|
175
|
-
const text = `${message}\n${description ?? ''}`;
|
|
176
|
-
const isGrantRefusal = text.includes(grantFix);
|
|
177
|
-
const isShownAtOnce = isCritical && !isGrantRefusal;
|
|
178
175
|
const logged = async () => {
|
|
179
176
|
const contact = await contactOf(claude);
|
|
180
177
|
const failure = { mod: name, id, message, details: await details(at), at: at.toISOString(), isCritical, root: claude.plugin.root, ...(contact === undefined ? {} : { contact }) };
|
|
181
|
-
const shows = await showsToast(failure,
|
|
182
|
-
if (
|
|
178
|
+
const shows = await showsToast(failure, isCritical);
|
|
179
|
+
if (isCritical)
|
|
183
180
|
return;
|
|
184
|
-
if (shows
|
|
181
|
+
if (shows !== false)
|
|
185
182
|
return show();
|
|
186
183
|
claude.ui.log(`${name}: ${message}${description === undefined ? '' : `: ${description}`}`, { to: 'debug' });
|
|
187
184
|
};
|
|
@@ -232,8 +229,8 @@ export function createToaster(claude, name, version) {
|
|
|
232
229
|
const fixes = [
|
|
233
230
|
{ sentence: installFix, label: 'Plugins', onClick: () => claude.command.run({ command: 'plugin' }) },
|
|
234
231
|
{ sentence: secretFix, label: 'Open /config', onClick: () => claude.command.run({ command: 'config' }) },
|
|
235
|
-
].filter(({ sentence }) =>
|
|
236
|
-
if (
|
|
232
|
+
].filter(({ sentence }) => `${message}\n${description ?? ''}`.includes(sentence));
|
|
233
|
+
if (isCritical)
|
|
237
234
|
show();
|
|
238
235
|
claude.clock.after(0, () => void logged());
|
|
239
236
|
return id;
|
package/src/jobs/program.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Job } from '../mod.js'
|
|
2
|
-
import { PermissionRefused, programAddresses } from '../runtime/grants.js'
|
|
3
2
|
import { engineOf } from '../runtime/engine.js'
|
|
4
3
|
import { messageOf } from '../utils/text.js'
|
|
5
4
|
import { basename } from '../vendor.js'
|
|
@@ -26,17 +25,11 @@ export function program(options: { readonly command: readonly string[]; readonly
|
|
|
26
25
|
let failure: Error | undefined
|
|
27
26
|
let exits = 0
|
|
28
27
|
const waiting: { resolve: (address: Address) => void; reject: (error: Error) => void }[] = []
|
|
29
|
-
const ownAddresses = programAddresses(mod)
|
|
30
28
|
|
|
31
|
-
const spawn =
|
|
32
|
-
|
|
33
|
-
const forget = () => {
|
|
34
|
-
if (address !== undefined) ownAddresses.delete(freeAddressOf(address))
|
|
35
|
-
address = undefined
|
|
36
|
-
}
|
|
29
|
+
const spawn = () => (singleInstance ? spawnCmod(['program', mod.name, '--', ...command], environment) : claude.process.spawn(request))
|
|
37
30
|
|
|
38
31
|
const stop = (reason: string) => {
|
|
39
|
-
|
|
32
|
+
address = undefined
|
|
40
33
|
state = 'fatal'
|
|
41
34
|
failure = new Error(`${mod.name}: the ${executable} program stopped: ${reason}`)
|
|
42
35
|
const retry = () => {
|
|
@@ -49,11 +42,9 @@ export function program(options: { readonly command: readonly string[]; readonly
|
|
|
49
42
|
}
|
|
50
43
|
|
|
51
44
|
const show = (next: Address) => {
|
|
52
|
-
forget()
|
|
53
45
|
address = next
|
|
54
46
|
state = 'running'
|
|
55
47
|
exits = 0
|
|
56
|
-
ownAddresses.add(freeAddressOf(next))
|
|
57
48
|
for (const waiter of waiting.splice(0)) waiter.resolve(next)
|
|
58
49
|
}
|
|
59
50
|
|
|
@@ -80,10 +71,9 @@ export function program(options: { readonly command: readonly string[]; readonly
|
|
|
80
71
|
}
|
|
81
72
|
}
|
|
82
73
|
} catch (error) {
|
|
83
|
-
if (error instanceof PermissionRefused) return stop(messageOf(error))
|
|
84
74
|
lastError = messageOf(error)
|
|
85
75
|
}
|
|
86
|
-
|
|
76
|
+
address = undefined
|
|
87
77
|
exits += 1
|
|
88
78
|
const wait = backoffSeconds[exits - 1]
|
|
89
79
|
if (wait === undefined) {
|
|
@@ -120,7 +110,3 @@ function addressOf(line: string): Address | undefined {
|
|
|
120
110
|
if (unix?.[1] !== undefined) return { url: 'http://localhost', socketPath: unix[1] }
|
|
121
111
|
return undefined
|
|
122
112
|
}
|
|
123
|
-
|
|
124
|
-
function freeAddressOf(address: Address): string {
|
|
125
|
-
return address.socketPath ?? new URL(address.url).host
|
|
126
|
-
}
|
package/src/mod.ts
CHANGED
|
@@ -83,23 +83,6 @@ export type Stat = Omit<Entry, 'name'> & {
|
|
|
83
83
|
|
|
84
84
|
export type FileChange = { readonly path: string; readonly type: 'change' | 'add' | 'unlink' }
|
|
85
85
|
|
|
86
|
-
export type Allowed = {
|
|
87
|
-
allows(value: string): boolean
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export type Permissions = {
|
|
91
|
-
readonly conversation: boolean
|
|
92
|
-
readonly prompt: boolean
|
|
93
|
-
readonly model: boolean
|
|
94
|
-
readonly tasks: boolean
|
|
95
|
-
readonly tools: boolean
|
|
96
|
-
readonly approve: boolean
|
|
97
|
-
readonly network: Allowed
|
|
98
|
-
readonly run: Allowed
|
|
99
|
-
readonly files: Allowed
|
|
100
|
-
readonly config: Allowed
|
|
101
|
-
}
|
|
102
|
-
|
|
103
86
|
export type SettingsFile = {
|
|
104
87
|
read(): Promise<Settings>
|
|
105
88
|
update(values: Readonly<Record<string, unknown>>): Promise<void>
|
|
@@ -222,7 +205,6 @@ export type Mod<State extends object = Record<never, never>, Declared extends Op
|
|
|
222
205
|
readonly dataFolder: string
|
|
223
206
|
readonly state: Readonly<State>
|
|
224
207
|
readonly options: OptionValues<Declared>
|
|
225
|
-
readonly permissions: Permissions
|
|
226
208
|
readonly hotkeys: { readonly [Key in keyof Keys]: Hotkey }
|
|
227
209
|
every(ms: number, listener: () => unknown): Timer
|
|
228
210
|
after(ms: number, listener: () => unknown): Timer
|
package/src/records.ts
CHANGED
|
@@ -19,13 +19,13 @@ export type Steps = {
|
|
|
19
19
|
uninstall?: string
|
|
20
20
|
program?: string
|
|
21
21
|
hotkeys?: Hotkeys
|
|
22
|
+
approve?: true
|
|
22
23
|
permissions?: readonly string[]
|
|
23
24
|
}
|
|
24
25
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export type FlagPermission = (typeof flagPermissions)[number]
|
|
26
|
+
const listPermissions = ['network', 'run', 'files', 'config'] as const
|
|
27
|
+
const flagPermissions = ['conversation', 'prompt', 'model', 'tasks', 'tools', 'approve'] as const
|
|
28
|
+
type ListPermission = (typeof listPermissions)[number]
|
|
29
29
|
const permissionNames: readonly string[] = [...listPermissions, ...flagPermissions]
|
|
30
30
|
const hostName = /^[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])?)*$/
|
|
31
31
|
const programName = /^[A-Za-z0-9][A-Za-z0-9._+-]*$/
|
|
@@ -159,12 +159,15 @@ export function readSteps(pkg: unknown): Steps | undefined {
|
|
|
159
159
|
if (!isObject(steps)) throw new Error('package.json has a "cmod" key that is not an object. Write "cmod": { "install": "./setup/install.sh", "uninstall": "./setup/uninstall.sh" }.')
|
|
160
160
|
const program = steps['program']
|
|
161
161
|
if (program !== undefined && (typeof program !== 'string' || !pluginName.test(program))) throw new Error('package.json "cmod.program" must be the program\'s command, such as "hello".')
|
|
162
|
+
const approve = steps['approve']
|
|
163
|
+
if (approve !== undefined && approve !== true) throw new Error(`package.json "cmod.approve" is ${JSON.stringify(approve)}. Write "approve": true, or leave it out.`)
|
|
162
164
|
const permissions = readPermissions(steps)
|
|
163
165
|
return {
|
|
164
166
|
...readCommand(steps, 'install'),
|
|
165
167
|
...readCommand(steps, 'uninstall'),
|
|
166
168
|
...(program === undefined ? {} : { program }),
|
|
167
169
|
...readHotkeys(steps['hotkeys']),
|
|
170
|
+
...(approve === true || permissions.includes('approve') ? { approve: true as const } : {}),
|
|
168
171
|
...(permissions.length === 0 ? {} : { permissions }),
|
|
169
172
|
}
|
|
170
173
|
}
|
|
@@ -198,50 +201,14 @@ function readPermissions(steps: Record<string, unknown>): string[] {
|
|
|
198
201
|
return items
|
|
199
202
|
}
|
|
200
203
|
|
|
201
|
-
export const grantFix = 'Turn it on in Settings.'
|
|
202
|
-
|
|
203
204
|
export const installFix = 'Install it in Plugins.'
|
|
204
205
|
|
|
205
206
|
export const secretFix = 'Set it in /config, where Claude Code keeps it in your keychain.'
|
|
206
207
|
|
|
207
|
-
export function permissionWords(item: string): string {
|
|
208
|
-
const split = item.indexOf(':')
|
|
209
|
-
const target = item.slice(split + 1)
|
|
210
|
-
switch (split === -1 ? item : item.slice(0, split)) {
|
|
211
|
-
case 'network':
|
|
212
|
-
return `Connect to ${target}`
|
|
213
|
-
case 'run':
|
|
214
|
-
return target === '*' ? 'Run any program on your computer' : `Run ${target} on your computer`
|
|
215
|
-
case 'files':
|
|
216
|
-
return `Change ${target}`
|
|
217
|
-
case 'conversation':
|
|
218
|
-
return 'Read your Claude Code conversations'
|
|
219
|
-
case 'prompt':
|
|
220
|
-
return 'Add text Claude reads and start turns'
|
|
221
|
-
case 'model':
|
|
222
|
-
return 'Ask a model, which uses your plan'
|
|
223
|
-
case 'tasks':
|
|
224
|
-
return 'Start tasks that work beside Claude'
|
|
225
|
-
case 'tools':
|
|
226
|
-
return "Use and change Claude's tool calls"
|
|
227
|
-
case 'config':
|
|
228
|
-
return `Change ${target} in your Claude Code settings`
|
|
229
|
-
case 'approve':
|
|
230
|
-
return "Approve Claude's tool calls for you"
|
|
231
|
-
default:
|
|
232
|
-
return item
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
208
|
export function settingPaths(values: Readonly<Record<string, unknown>>): string[][] {
|
|
237
209
|
return Object.entries(values).flatMap(([key, value]) => (isObject(value) && Object.keys(value).length > 0 ? settingPaths(value).map((path) => [key, ...path]) : [[key]]))
|
|
238
210
|
}
|
|
239
211
|
|
|
240
|
-
export function isSettingCovered(granted: Iterable<string>, path: string): boolean {
|
|
241
|
-
const item = `config:${path}`
|
|
242
|
-
return [...granted].some((each) => item === each || item.startsWith(`${each}.`))
|
|
243
|
-
}
|
|
244
|
-
|
|
245
212
|
export const pendingStepsMethod = 'cmod:pendingSteps'
|
|
246
213
|
|
|
247
214
|
export const finishStepsMethod = 'cmod:finishSteps'
|
|
@@ -316,18 +283,18 @@ export function preferencesPath(store: string): string {
|
|
|
316
283
|
return `${store}/preferences.json`
|
|
317
284
|
}
|
|
318
285
|
|
|
319
|
-
export type Preferences = { readonly
|
|
286
|
+
export type Preferences = { readonly showsInstalledModErrors: boolean }
|
|
320
287
|
|
|
321
288
|
export function parsePreferences(value: unknown, path: string): Preferences {
|
|
322
|
-
if (value === undefined) return {
|
|
323
|
-
if (!isObject(value) || ['
|
|
324
|
-
return {
|
|
289
|
+
if (value === undefined) return { showsInstalledModErrors: false }
|
|
290
|
+
if (!isObject(value) || (value['showsInstalledModErrors'] !== undefined && typeof value['showsInstalledModErrors'] !== 'boolean')) throw new Error(`${path} is not a map of cmod's preferences to true or false. Delete it, and cmod uses its defaults.`)
|
|
291
|
+
return { showsInstalledModErrors: value['showsInstalledModErrors'] === true }
|
|
325
292
|
}
|
|
326
293
|
|
|
327
294
|
export function parseConsent(value: unknown, path: string): Record<string, string[]> {
|
|
328
295
|
if (value === undefined) return Object.create(null)
|
|
329
296
|
if (!isObject(value) || !Object.values(value).every(isTextList)) {
|
|
330
|
-
throw new Error(`${path} is not a map of plugin names to what each was approved for. Delete it, and cmod
|
|
297
|
+
throw new Error(`${path} is not a map of plugin names to what each was approved for. Delete it, and cmod writes it again at each mod's next setup.`)
|
|
331
298
|
}
|
|
332
299
|
return Object.assign(Object.create(null), value) as Record<string, string[]>
|
|
333
300
|
}
|
|
@@ -339,7 +306,9 @@ function readHotkeys(hotkeys: unknown): Steps {
|
|
|
339
306
|
return { hotkeys: checkHotkeys('package.json "cmod"', hotkeys as Record<string, HotkeyInit>) }
|
|
340
307
|
}
|
|
341
308
|
|
|
342
|
-
export const coreVersion = '
|
|
309
|
+
export const coreVersion = '5.0.1'
|
|
310
|
+
|
|
311
|
+
export const oldestCmodVersion = '5.0.0'
|
|
343
312
|
|
|
344
313
|
export function hotkeyCommand(mod: string, hotkey: string): string {
|
|
345
314
|
return `${mod}--${hotkey}`
|
|
@@ -359,22 +328,18 @@ export function boundCombos(keybindings: unknown): Map<string, string> {
|
|
|
359
328
|
return combos
|
|
360
329
|
}
|
|
361
330
|
|
|
362
|
-
export function hotkeyWords(hotkeys: Hotkeys | undefined): string {
|
|
363
|
-
return listed(Object.values(hotkeys ?? {}).flatMap(({ title, default: combo }) => (combo === undefined ? [] : [`${combo} to ${title}`])))
|
|
364
|
-
}
|
|
365
|
-
|
|
366
331
|
function readCommand(steps: Record<string, unknown>, key: 'install' | 'uninstall'): Steps {
|
|
367
332
|
const command = steps[key]
|
|
368
333
|
if (command === undefined) return {}
|
|
369
334
|
if (typeof command !== 'string' || command.trim() === '') throw new Error(`package.json "cmod.${key}" must be a command, such as "./setup/${key}.sh".`)
|
|
370
335
|
if (/[\n\t]/.test(command)) throw new Error(`package.json "cmod.${key}" holds a line break or a tab. Write one command, such as "./setup/${key}.sh".`)
|
|
371
336
|
const atRoot = scriptPaths(command).find((path) => folderOf(path) === '.')
|
|
372
|
-
if (atRoot !== undefined) throw new Error(`package.json "cmod.${key}" names ${atRoot}, a script at the plugin root. Move it into a folder, such as ./setup/${key}.sh: cmod
|
|
337
|
+
if (atRoot !== undefined) throw new Error(`package.json "cmod.${key}" names ${atRoot}, a script at the plugin root. Move it into a folder, such as ./setup/${key}.sh: cmod runs the steps again whenever anything in a script's folder changes.`)
|
|
373
338
|
return { [key]: command }
|
|
374
339
|
}
|
|
375
340
|
|
|
376
|
-
export function bundleDefines(
|
|
377
|
-
return
|
|
341
|
+
export function bundleDefines(steps: Steps): Record<string, string> {
|
|
342
|
+
return steps.approve === true ? {} : { 'globalThis.cmodWithoutApprove': 'true' }
|
|
378
343
|
}
|
|
379
344
|
|
|
380
345
|
export function scriptPaths(command: string): string[] {
|
|
@@ -398,7 +363,7 @@ export async function scriptsSha256(steps: Steps, files: { read: ReadFile; list:
|
|
|
398
363
|
for (const path of scriptPaths(command)) {
|
|
399
364
|
if ((await files.read(path)) !== undefined) scriptFolders.push(folderOf(path))
|
|
400
365
|
}
|
|
401
|
-
if (scriptFolders.length === 0) throw new Error(`package.json "cmod.${key}" runs "${command}", which names no script file in the mod, so
|
|
366
|
+
if (scriptFolders.length === 0) throw new Error(`package.json "cmod.${key}" runs "${command}", which names no script file in the mod, so cmod cannot tell when what it runs changes. Put the commands in a script, such as ./setup/${key}.sh.`)
|
|
402
367
|
for (const folder of scriptFolders) folders.add(folder)
|
|
403
368
|
}
|
|
404
369
|
let text = [
|
|
@@ -412,7 +377,7 @@ export async function scriptsSha256(steps: Steps, files: { read: ReadFile; list:
|
|
|
412
377
|
for (const name of (await files.list(folder)).sort()) {
|
|
413
378
|
const path = `${folder}/${name}`
|
|
414
379
|
const content = await files.read(path)
|
|
415
|
-
if (content === undefined) throw new Error(`${path} links to a folder or to nothing, so
|
|
380
|
+
if (content === undefined) throw new Error(`${path} links to a folder or to nothing, so cmod cannot tell when it changes. Point the link at a file, or delete it.`)
|
|
416
381
|
text += `\0${path}\0${content}`
|
|
417
382
|
}
|
|
418
383
|
}
|
package/src/runtime/announce.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isObject
|
|
1
|
+
import { isObject } from '../records.js'
|
|
2
2
|
import { ifMissing } from '../utils/paths.js'
|
|
3
3
|
import { listed } from '../utils/text.js'
|
|
4
4
|
import type { Claude } from './claude.js'
|
|
@@ -8,7 +8,7 @@ export type Announcement = { readonly message: string; readonly description?: st
|
|
|
8
8
|
|
|
9
9
|
export const announcementMs = 10_000
|
|
10
10
|
|
|
11
|
-
export async function announcementOf(claude: Claude, plugin: Plugin,
|
|
11
|
+
export async function announcementOf(claude: Claude, plugin: Plugin, added: readonly string[], openSettings: () => Promise<void>): Promise<Announcement> {
|
|
12
12
|
const manifest = jsonOf(await claude.fs.read(`${plugin.root}/.claude-plugin/plugin.json`).catch(ifMissing(undefined)))
|
|
13
13
|
const { program, hotkeys } = plugin.steps
|
|
14
14
|
const rules = (await claude.fs.list(`${plugin.root}/rules`).catch(ifMissing([]))).filter((entry) => entry.kind === 'file' && entry.name.endsWith('.md')).map((entry) => entry.name.slice(0, -'.md'.length)).toSorted()
|
|
@@ -18,7 +18,6 @@ export async function announcementOf(claude: Claude, plugin: Plugin, granted: Re
|
|
|
18
18
|
rules.length > 0 ? `Adds ${rules.length} ${rules.length === 1 ? 'rule' : 'rules'}: ${listed(rules)}.` : undefined,
|
|
19
19
|
program === undefined ? undefined : `Installed the ${program} program.`,
|
|
20
20
|
...Object.values(hotkeys ?? {}).flatMap(({ title, default: combo }) => (combo === undefined ? [] : [`Binds ${combo} to ${title}.`])),
|
|
21
|
-
...[...granted].map((item) => `${permissionWords(item)}.`),
|
|
22
21
|
].filter((line) => line !== undefined)
|
|
23
22
|
return { message: 'Installed', ...(lines.length === 0 ? {} : { description: lines.join('\n') }), action: { label: 'Settings', onClick: () => openSettings() } }
|
|
24
23
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Args, EventResult, Frozen } from 'claude-code'
|
|
2
|
-
import {
|
|
2
|
+
import { coreVersion, dataFolder, isObject } from '../records.js'
|
|
3
3
|
import { Message, rowOfAppend, type Row } from '../session/context/turn/message/message.js'
|
|
4
4
|
import { modNote, Note } from '../session/context/turn/message/note.js'
|
|
5
5
|
import { Person } from '../session/context/turn/message/sender.js'
|
|
@@ -15,11 +15,10 @@ import { formatExit, messageOf } from '../utils/text.js'
|
|
|
15
15
|
import { beforeAnswerKeys, foldBefore, installBefore, relayOf, type Decide, type Place } from './before.js'
|
|
16
16
|
import type { Claude } from './claude.js'
|
|
17
17
|
import { cmodPluginName } from './dependencies.js'
|
|
18
|
-
import { conversationCalls, refusal } from './grants.js'
|
|
19
18
|
import { readLines, runCmod, spawnCmod } from './programs.js'
|
|
20
19
|
import type { RoutedHook, Router } from './router.js'
|
|
21
20
|
import { PassedTimeout } from './deadline.js'
|
|
22
|
-
import {
|
|
21
|
+
import { conversationMethods, everySession, isAct, isHeardBy, isInScope, pickedColor, resultOf, spawnTask, usageOf, type Act, type Listened, type SessionColor } from './sessions.js'
|
|
23
22
|
|
|
24
23
|
type Request = Readonly<Record<string, unknown>>
|
|
25
24
|
|
|
@@ -130,35 +129,6 @@ export function serveConversations({
|
|
|
130
129
|
|
|
131
130
|
const json = async <Value>(args: readonly string[]): Promise<Value> => JSON.parse(await runCmod(claude, [...args, '--json', '--project', project()], await claude.session.id())) as Value
|
|
132
131
|
|
|
133
|
-
const isGranted = async (caller: string | undefined, item: string) => {
|
|
134
|
-
if (caller === cmodPluginName) return true
|
|
135
|
-
if (caller === undefined) return false
|
|
136
|
-
const path = consentPath(store)
|
|
137
|
-
const text = await claude.fs.read(path).catch(ifMissing('{}'))
|
|
138
|
-
return (parseConsent(JSON.parse(text), path)[caller] ?? []).includes(item)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const declaredBy = async (caller: string): Promise<readonly string[] | undefined> => {
|
|
142
|
-
const read = (path: string) => claude.fs.read(path).catch(ifMissing(undefined))
|
|
143
|
-
const record = await readRecord(read, store, caller)
|
|
144
|
-
if (record === undefined) return undefined
|
|
145
|
-
if (record.permissions !== null) return record.permissions
|
|
146
|
-
const pkg = await read(`${record.root}/package.json`)
|
|
147
|
-
return pkg === undefined ? undefined : (readSteps(JSON.parse(pkg))?.permissions ?? [])
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const refused = async (caller: string | undefined, call: string, item: string) => {
|
|
151
|
-
const declared =
|
|
152
|
-
caller === undefined
|
|
153
|
-
? undefined
|
|
154
|
-
: await declaredBy(caller).catch((error: unknown) => {
|
|
155
|
-
claude.ui.log(`cmod: its refusal of ${caller} names the grant, because the permissions ${caller} declares are unreadable: ${messageOf(error)}`, { to: 'debug' })
|
|
156
|
-
return undefined
|
|
157
|
-
})
|
|
158
|
-
return refusal({ name: caller ?? 'A mod', declared: declared ?? [item], home: undefined }, call, item)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
132
|
const ended = (id: string) => new Error(`session ${id} has ended`)
|
|
163
133
|
|
|
164
134
|
const isRunning = async (id: string) => (await json<SessionData[]>(['history', 'sessions', '--running', '--all'])).some((each) => each.id === id)
|
|
@@ -358,10 +328,7 @@ export function serveConversations({
|
|
|
358
328
|
return [...new Map(all.filter((watcher) => watcher.events.includes(event)).map((watcher) => [`${watcher.from}\n${watcher.mod}`, watcher])).values()]
|
|
359
329
|
}
|
|
360
330
|
|
|
361
|
-
const askHere = async (mod: string, event: BeforeEvent, change: SessionChange, from = session, isInProject = true) => {
|
|
362
|
-
if (from !== session && !(await isGranted(mod, 'conversation'))) throw new Error(await refused(mod, 'before', 'conversation'))
|
|
363
|
-
return claude.cmod.call({ to: mod, method: conversationMethods.before, input: { session: from, event, change, isInProject } })
|
|
364
|
-
}
|
|
331
|
+
const askHere = async (mod: string, event: BeforeEvent, change: SessionChange, from = session, isInProject = true) => claude.cmod.call({ to: mod, method: conversationMethods.before, input: { session: from, event, change, isInProject } })
|
|
365
332
|
|
|
366
333
|
const isUnderHere = (task: string, ancestor: string) => {
|
|
367
334
|
for (let at: string | undefined = task, steps = 0; at !== undefined && steps < 64; at = conversation.state.tasks[at]?.parent, steps += 1) if (at === ancestor) return true
|
|
@@ -561,13 +528,7 @@ export function serveConversations({
|
|
|
561
528
|
return answered(() => askHere(relay.mod, relay.event, relay.change, relay.from, relay.project === project()))
|
|
562
529
|
}
|
|
563
530
|
|
|
564
|
-
const checkAct = async (caller: string, action: Act, input: unknown) => {
|
|
565
|
-
const needed = actPermission(action, input)
|
|
566
|
-
if (needed !== undefined && !(await isGranted(caller, needed))) throw new Error(await refused(caller, action, needed))
|
|
567
|
-
}
|
|
568
|
-
|
|
569
531
|
const perform = async (caller: string, action: Act, input: unknown, task: string | undefined): Promise<unknown> => {
|
|
570
|
-
await checkAct(caller, action, input)
|
|
571
532
|
await starting
|
|
572
533
|
if (action === 'abort') return abortTurn(input, task)
|
|
573
534
|
if (task !== undefined) return performInTask(caller, action, input, task)
|
|
@@ -654,7 +615,6 @@ export function serveConversations({
|
|
|
654
615
|
}
|
|
655
616
|
|
|
656
617
|
const actElsewhere = async (caller: string, target: string, action: Act, input: unknown, task: string | undefined): Promise<unknown> => {
|
|
657
|
-
await checkAct(caller, action, input)
|
|
658
618
|
const isLive = await isRunning(target)
|
|
659
619
|
if (!isLive && action === 'usage') return json(['history', 'usage', target, ...(task === undefined ? [] : ['--task', task])])
|
|
660
620
|
if (!isLive && action === 'surfaces') return []
|
|
@@ -823,8 +783,6 @@ export function serveConversations({
|
|
|
823
783
|
const method = methods[e.method]
|
|
824
784
|
if (method === undefined) return undefined
|
|
825
785
|
const input = isObject(e.input) ? e.input : {}
|
|
826
|
-
const isDropping = (e.method === conversationMethods.subscribe || e.method === conversationMethods.watchBefore) && Array.isArray(input['subscriptions']) && input['subscriptions'].length === 0
|
|
827
|
-
if (e.method !== conversationMethods.act && !isDropping && input['session'] !== (await claude.session.id()) && !(await isGranted(e.caller, 'conversation'))) return { deny: await refused(e.caller, conversationCalls[e.method] ?? e.method, 'conversation') }
|
|
828
786
|
try {
|
|
829
787
|
return { value: await method(input, e.caller) }
|
|
830
788
|
} catch (error) {
|
package/src/runtime/engine.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HookStream, ProcessSpawnChunk,
|
|
1
|
+
import type { HookStream, ProcessSpawnChunk, ProcessSpawnResult } from 'claude-code'
|
|
2
2
|
import type { Claude } from './claude.js'
|
|
3
3
|
import type { Pages } from './pages.js'
|
|
4
4
|
import type { Router } from './router.js'
|
|
@@ -13,7 +13,7 @@ export type Engine = {
|
|
|
13
13
|
readonly report: (failure: Failure) => void
|
|
14
14
|
readonly hasPermissionCheck: () => boolean
|
|
15
15
|
readonly answerInput: <Answer>(run: () => Promise<Answer>, passOn: () => Promise<unknown>) => Promise<Answer>
|
|
16
|
-
readonly spawnCmod: (args: readonly string[],
|
|
16
|
+
readonly spawnCmod: (args: readonly string[], env?: Readonly<Record<string, string>>) => HookStream<ProcessSpawnChunk, ProcessSpawnResult>
|
|
17
17
|
readonly widgets?: Widgets
|
|
18
18
|
readonly pages?: Pages
|
|
19
19
|
}
|
package/src/runtime/installer.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { RenderElement } from 'claude-code'
|
|
|
2
2
|
import type { Step } from '../installer.js'
|
|
3
3
|
import type { Mod } from '../mod.js'
|
|
4
4
|
import type { Option } from '../options.js'
|
|
5
|
-
import { isObject,
|
|
5
|
+
import { isObject, secretFix } from '../records.js'
|
|
6
6
|
import { Box, elementData, Input, Text, type Handler } from '../ui/elements.js'
|
|
7
7
|
import { filledButton } from './buttons.js'
|
|
8
8
|
import type { PageProps } from '../ui/panes.js'
|
|
@@ -13,15 +13,6 @@ import { merged, partMethods, stalePress, type DrawnPart, type PartPress, type P
|
|
|
13
13
|
|
|
14
14
|
export const installPage = 'cmod:install'
|
|
15
15
|
|
|
16
|
-
export type Consent = {
|
|
17
|
-
readonly install: string
|
|
18
|
-
readonly uninstall: string
|
|
19
|
-
readonly program: string
|
|
20
|
-
readonly hotkeys: string
|
|
21
|
-
readonly permissions: readonly string[]
|
|
22
|
-
readonly updates?: string | undefined
|
|
23
|
-
}
|
|
24
|
-
|
|
25
16
|
type Question = {
|
|
26
17
|
draw(props: PageProps<undefined>): RenderElement
|
|
27
18
|
cancel(): void
|
|
@@ -30,7 +21,6 @@ type Question = {
|
|
|
30
21
|
export type Installer = {
|
|
31
22
|
answer(method: string, input: unknown): Promise<{ readonly value: unknown }> | undefined
|
|
32
23
|
hear(shown: ShownPages): void
|
|
33
|
-
consent(consent: Consent): Promise<boolean>
|
|
34
24
|
options(missing: readonly (readonly [string, Option])[], save: (key: string, value: string) => Promise<string | undefined>): Promise<boolean>
|
|
35
25
|
step<State extends object>(mod: Mod<State>, step: Step<State>, index: number, total: number): Promise<boolean>
|
|
36
26
|
close(): Promise<void>
|
|
@@ -91,10 +81,6 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
|
|
|
91
81
|
|
|
92
82
|
const dialog = (title: RenderElement, ...children: readonly RenderElement[]) => Box({ flexDirection: 'column', gap: 1, children: [title, ...children] })
|
|
93
83
|
|
|
94
|
-
const bullet = (text: string) => Box({ gap: 1, children: [Text({ dimColor: true, children: '•' }), Text({ wrap: 'wrap', children: text })] })
|
|
95
|
-
|
|
96
|
-
const group = (heading: string, items: readonly string[]) => Box({ flexDirection: 'column', children: [Text({ bold: true, children: heading }), ...items.map(bullet)] })
|
|
97
|
-
|
|
98
84
|
const draw = (columns: number, isFocused: boolean): DrawnPart => {
|
|
99
85
|
if (question === undefined && !isOpen) claude().clock.after(0, () => void send({ requests: [{ close: installPage }] }).catch(log('a leftover install page stayed open')))
|
|
100
86
|
const handlers: Handler[] = []
|
|
@@ -139,28 +125,6 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
|
|
|
139
125
|
isSeen = false
|
|
140
126
|
question?.cancel()
|
|
141
127
|
},
|
|
142
|
-
consent({ install, uninstall, program, hotkeys, permissions, updates }) {
|
|
143
|
-
const changes = [
|
|
144
|
-
...(install === '' ? [] : [`Run ${install} now${uninstall === '' ? '' : `, and ${uninstall} when you remove it`}`]),
|
|
145
|
-
...(install === '' && uninstall !== '' ? [`Run ${uninstall} when you remove it`] : []),
|
|
146
|
-
...(program === '' ? [] : [`Install ${program}, which Claude runs by its name`]),
|
|
147
|
-
...(hotkeys === '' ? [] : [`Bind ${hotkeys}`]),
|
|
148
|
-
...(updates === undefined ? [] : [`Update ${name} automatically from the ${updates} marketplace`]),
|
|
149
|
-
]
|
|
150
|
-
return show<boolean>(
|
|
151
|
-
(answer) => ({
|
|
152
|
-
draw: () =>
|
|
153
|
-
dialog(
|
|
154
|
-
Text({ bold: true, children: `Install ${name}?` }),
|
|
155
|
-
...(permissions.length === 0 ? [] : [group(`${name} wants to:`, permissions.map(permissionWords))]),
|
|
156
|
-
...(changes.length === 0 ? [] : [group(permissions.length === 0 ? `${name} wants to change your computer:` : 'and change your computer:', changes)]),
|
|
157
|
-
Text({ dimColor: true, wrap: 'wrap', children: 'You can turn each permission off later in Settings.' }),
|
|
158
|
-
actions(filledButton({ key: 'accept', hotkey: 'a', variant: 'primary', label: 'Accept', onPress: () => answer(true) }), filledButton({ key: 'not-now', hotkey: 'n', label: 'Not now', onPress: () => answer(false) })),
|
|
159
|
-
),
|
|
160
|
-
}),
|
|
161
|
-
false,
|
|
162
|
-
)
|
|
163
|
-
},
|
|
164
128
|
options(missing, save) {
|
|
165
129
|
const saved = new Map<string, string>()
|
|
166
130
|
const failures = new Map<string, string>()
|