@cmodjs/core 4.2.0 → 4.3.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/docs/commands.md +4 -4
- package/docs/install-steps.md +4 -3
- package/docs/mod.md +9 -8
- package/docs/permissions.md +3 -3
- package/docs/testing.md +2 -0
- package/docs/ui.md +12 -3
- package/hotkeys.d.ts +1 -1
- package/hotkeys.d.ts.map +1 -1
- package/hotkeys.js +2 -0
- package/jobs/program.js +1 -1
- package/package.json +1 -1
- package/records.d.ts +9 -1
- package/records.d.ts.map +1 -1
- package/records.js +27 -6
- package/register.d.ts.map +1 -1
- package/register.js +1 -0
- package/runtime/announce.d.ts +2 -7
- package/runtime/announce.d.ts.map +1 -1
- package/runtime/announce.js +13 -52
- package/runtime/claude.d.ts +2 -1
- package/runtime/claude.d.ts.map +1 -1
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +24 -4
- package/runtime/grants.d.ts +1 -0
- package/runtime/grants.d.ts.map +1 -1
- package/runtime/grants.js +1 -1
- package/runtime/hotkeys.js +1 -1
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +27 -20
- package/runtime/sessions.d.ts +2 -1
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +5 -6
- package/runtime/toaster.d.ts +22 -1
- package/runtime/toaster.d.ts.map +1 -1
- package/runtime/toaster.js +69 -24
- package/runtime/ui.js +1 -1
- package/src/hotkeys.ts +2 -1
- package/src/jobs/program.ts +1 -1
- package/src/records.ts +29 -5
- package/src/register.ts +1 -0
- package/src/runtime/announce.ts +14 -56
- package/src/runtime/claude.ts +2 -0
- package/src/runtime/conversations.ts +25 -4
- package/src/runtime/grants.ts +1 -1
- package/src/runtime/hotkeys.ts +1 -1
- package/src/runtime/lifecycle.ts +27 -21
- package/src/runtime/sessions.ts +4 -5
- package/src/runtime/toaster.ts +68 -25
- package/src/runtime/ui.ts +1 -1
- package/src/testing/fake-claude.ts +2 -1
- package/src/testing.ts +7 -2
- package/src/utils/changelog.ts +0 -15
- package/testing/fake-claude.d.ts.map +1 -1
- package/testing/fake-claude.js +2 -1
- package/testing.d.ts.map +1 -1
- package/testing.js +7 -2
- package/utils/changelog.d.ts +0 -1
- package/utils/changelog.d.ts.map +1 -1
- package/utils/changelog.js +0 -15
package/runtime/conversations.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { consentPath, coreVersion, dataFolder,
|
|
1
|
+
import { consentPath, coreVersion, dataFolder, isObject, parseConsent, readRecord, readSteps } from '../records.js';
|
|
2
2
|
import { Message, rowOfAppend } from '../session/context/turn/message/message.js';
|
|
3
3
|
import { modNote, Note } from '../session/context/turn/message/note.js';
|
|
4
4
|
import { Person } from '../session/context/turn/message/sender.js';
|
|
@@ -13,6 +13,7 @@ import { ifMissing } from '../utils/paths.js';
|
|
|
13
13
|
import { formatExit, messageOf } from '../utils/text.js';
|
|
14
14
|
import { beforeAnswerKeys, foldBefore, installBefore, relayOf } from './before.js';
|
|
15
15
|
import { cmodPluginName } from './dependencies.js';
|
|
16
|
+
import { conversationCalls, refusal } from './grants.js';
|
|
16
17
|
import { readLines, runCmod, spawnCmod } from './programs.js';
|
|
17
18
|
import { PassedTimeout } from './deadline.js';
|
|
18
19
|
import { actPermission, conversationMethods, everySession, isAct, isHeardBy, isInScope, pickedColor, resultOf, spawnTask, usageOf } from './sessions.js';
|
|
@@ -80,6 +81,25 @@ export function serveConversations({ claude, router, store, project, report, cle
|
|
|
80
81
|
const text = await claude.fs.read(path).catch(ifMissing('{}'));
|
|
81
82
|
return (parseConsent(JSON.parse(text), path)[caller] ?? []).includes(item);
|
|
82
83
|
};
|
|
84
|
+
const declaredBy = async (caller) => {
|
|
85
|
+
const read = (path) => claude.fs.read(path).catch(ifMissing(undefined));
|
|
86
|
+
const record = await readRecord(read, store, caller);
|
|
87
|
+
if (record === undefined)
|
|
88
|
+
return undefined;
|
|
89
|
+
if (record.permissions !== null)
|
|
90
|
+
return record.permissions;
|
|
91
|
+
const pkg = await read(`${record.root}/package.json`);
|
|
92
|
+
return pkg === undefined ? undefined : (readSteps(JSON.parse(pkg))?.permissions ?? []);
|
|
93
|
+
};
|
|
94
|
+
const refused = async (caller, call, item) => {
|
|
95
|
+
const declared = caller === undefined
|
|
96
|
+
? undefined
|
|
97
|
+
: await declaredBy(caller).catch((error) => {
|
|
98
|
+
claude.ui.log(`cmod: its refusal of ${caller} names the grant, because the permissions ${caller} declares are unreadable: ${messageOf(error)}`, { to: 'debug' });
|
|
99
|
+
return undefined;
|
|
100
|
+
});
|
|
101
|
+
return refusal({ name: caller ?? 'A mod', declared: declared ?? [item], home: undefined }, call, item);
|
|
102
|
+
};
|
|
83
103
|
const ended = (id) => new Error(`session ${id} has ended`);
|
|
84
104
|
const isRunning = async (id) => (await json(['history', 'sessions', '--running', '--all'])).some((each) => each.id === id);
|
|
85
105
|
let color = { session: '' };
|
|
@@ -282,7 +302,7 @@ export function serveConversations({ claude, router, store, project, report, cle
|
|
|
282
302
|
};
|
|
283
303
|
const askHere = async (mod, event, change, from = session, isInProject = true) => {
|
|
284
304
|
if (from !== session && !(await isGranted(mod, 'conversation')))
|
|
285
|
-
throw new Error(
|
|
305
|
+
throw new Error(await refused(mod, 'before', 'conversation'));
|
|
286
306
|
return claude.cmod.call({ to: mod, method: conversationMethods.before, input: { session: from, event, change, isInProject } });
|
|
287
307
|
};
|
|
288
308
|
const isUnderHere = (task, ancestor) => {
|
|
@@ -488,7 +508,7 @@ export function serveConversations({ claude, router, store, project, report, cle
|
|
|
488
508
|
const checkAct = async (caller, action, input) => {
|
|
489
509
|
const needed = actPermission(action, input);
|
|
490
510
|
if (needed !== undefined && !(await isGranted(caller, needed)))
|
|
491
|
-
throw new Error(
|
|
511
|
+
throw new Error(await refused(caller, action, needed));
|
|
492
512
|
};
|
|
493
513
|
const perform = async (caller, action, input, task) => {
|
|
494
514
|
await checkAct(caller, action, input);
|
|
@@ -778,7 +798,7 @@ export function serveConversations({ claude, router, store, project, report, cle
|
|
|
778
798
|
const input = isObject(e.input) ? e.input : {};
|
|
779
799
|
const isDropping = (e.method === conversationMethods.subscribe || e.method === conversationMethods.watchBefore) && Array.isArray(input['subscriptions']) && input['subscriptions'].length === 0;
|
|
780
800
|
if (e.method !== conversationMethods.act && !isDropping && input['session'] !== (await claude.session.id()) && !(await isGranted(e.caller, 'conversation')))
|
|
781
|
-
return { deny:
|
|
801
|
+
return { deny: await refused(e.caller, conversationCalls[e.method] ?? e.method, 'conversation') };
|
|
782
802
|
try {
|
|
783
803
|
return { value: await method(input, e.caller) };
|
|
784
804
|
}
|
package/runtime/grants.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type Grants = {
|
|
|
14
14
|
export declare class PermissionRefused extends Error {
|
|
15
15
|
}
|
|
16
16
|
export declare function programAddresses(mod: object): Set<string>;
|
|
17
|
+
export declare const conversationCalls: Readonly<Record<string, string>>;
|
|
17
18
|
export declare function checkGrant(grants: Grants, call: string, item: string | undefined): Promise<void>;
|
|
18
19
|
export declare function checkRun(grants: Grants, call: 'process.run' | 'process.spawn', argv: readonly string[]): Promise<void>;
|
|
19
20
|
export declare function checkWrite(grants: Grants, call: string, path: string): Promise<void>;
|
package/runtime/grants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grants.d.ts","sourceRoot":"","sources":["../src/runtime/grants.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAG7C,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAA;IACpC,QAAQ,CAAC,OAAO,EAAE,MAAM,WAAW,CAAC,MAAM,CAAC,CAAA;IAC3C,QAAQ,CAAC,OAAO,EAAE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G,UAAU,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAI9G;AA0BD,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IAChC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAC1C,CAAA;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAEzD;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAa9G;AAED,wBAAsB,aAAa,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CA+BxJ"}
|
package/runtime/grants.js
CHANGED
|
@@ -11,7 +11,7 @@ export function programAddresses(mod) {
|
|
|
11
11
|
return known;
|
|
12
12
|
}
|
|
13
13
|
const projectSettingsFiles = ['.claude/settings.json', '.claude/settings.local.json', '.mcp.json'];
|
|
14
|
-
const conversationCalls = {
|
|
14
|
+
export const conversationCalls = {
|
|
15
15
|
[conversationMethods.sessions]: 'sessions.list',
|
|
16
16
|
[conversationMethods.search]: 'sessions.search',
|
|
17
17
|
[conversationMethods.messages]: 'messages',
|
package/runtime/hotkeys.js
CHANGED
|
@@ -41,7 +41,7 @@ export async function createHotkeys({ name, declared, configRoot, claude, router
|
|
|
41
41
|
await listener();
|
|
42
42
|
}
|
|
43
43
|
catch (error) {
|
|
44
|
-
report({ id: `hotkey:${hotkey}`, message: `The ${declared[hotkey]?.title ?? hotkey} hotkey failed`, error });
|
|
44
|
+
report({ id: `hotkey:${hotkey}`, message: `The ${declared[hotkey]?.title ?? hotkey} hotkey failed`, error, isCritical: true });
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
return {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.d.ts","sourceRoot":"","sources":["../src/runtime/lifecycle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,EAAqB,WAAW,EAAE,MAAM,EAAc,aAAa,EAAwB,MAAM,aAAa,CAAA;AAGxI,OAAO,KAAK,EAAoB,GAAG,EAAE,aAAa,EAA8G,MAAM,WAAW,CAAA;AACjL,OAAO,KAAK,EAAE,OAAO,EAAgB,MAAM,eAAe,CAAA;AAC1D,OAAO,EAA4S,KAAK,KAAK,EAAE,MAAM,eAAe,CAAA;AAGpV,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAOzC,OAAO,EAA6F,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AACxI,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAO7D,OAAO,EAA6B,KAAK,UAAU,EAAE,MAAM,aAAa,CAAA;AAMxE,OAAO,EAA+B,KAAK,UAAU,EAAgB,MAAM,cAAc,CAAA;AAWzF,MAAM,MAAM,MAAM,GAAG;IACnB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAA;IACpC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAA;IAC7B,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAA;IAC9B,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAA;IACrB,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAA;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AAG,OAAO,CAAC,OAAO,CAAC,CAAA;CACpF,CAAA;AAuDD,wBAAsB,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CA2BhE;AAoCD,wBAAgB,eAAe,CAAC,KAAK,SAAS,MAAM,EAAE,QAAQ,SAAS,OAAO,GAAG,OAAO,EACtF,UAAU,EAAE,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAClD,gBAAgB,GAAE,MAAM,gBAAgB,GAAG,SAA2B,EACtE,OAAO,GAAE,aAAkB,EAC3B,UAAU,UAAO,GAChB,SAAS,CAAC,KAAK,CAAC,CAqkBlB"}
|
package/runtime/lifecycle.js
CHANGED
|
@@ -2,13 +2,13 @@ import { consentPath, dataFolder, finishStepsMethod, grantFix, coreVersion, isAt
|
|
|
2
2
|
import { homePrefix, ifMissing, relativePath } from '../utils/paths.js';
|
|
3
3
|
import { firstLine, formatExit, messageOf } from '../utils/text.js';
|
|
4
4
|
import { beforeDeadline } from './deadline.js';
|
|
5
|
-
import {
|
|
5
|
+
import { announcementMs, announcementOf } from './announce.js';
|
|
6
6
|
import { bind } from './bound.js';
|
|
7
7
|
import { serveConversations } from './conversations.js';
|
|
8
8
|
import { answerCall, answeringOwnCalls, cmodPluginName, dependencyCalls, withBareRefusals } from './dependencies.js';
|
|
9
9
|
import { keepEngine } from './engine.js';
|
|
10
10
|
import { classicFailure, classicHook, userSkillHook } from './hooks.js';
|
|
11
|
-
import { checkedAnswer, checkingGrants, checkRun, checkSettings, checksAnswers, checkWrite, isCovered, itemOf, passedDown, programAddresses } from './grants.js';
|
|
11
|
+
import { checkedAnswer, checkingGrants, checkRun, checkSettings, checksAnswers, checkWrite, isCovered, itemOf, passedDown, programAddresses, refusal } from './grants.js';
|
|
12
12
|
import { cmodError, locatingPrograms, readLines, spawnCmod } from './programs.js';
|
|
13
13
|
import { createModFiles, resolvedPath } from './metadata.js';
|
|
14
14
|
import { fitsOption } from '../options.js';
|
|
@@ -117,8 +117,8 @@ export function createLifecycle(definition, permissionRoutes = () => undefined,
|
|
|
117
117
|
const granted = new Set();
|
|
118
118
|
let activation;
|
|
119
119
|
let mod;
|
|
120
|
-
const openSettings = async (
|
|
121
|
-
await claude().cmod.call({ to: cmodPluginName, method: partMethods.changed, input: { requests: [{ settings: true
|
|
120
|
+
const openSettings = async () => {
|
|
121
|
+
await claude().cmod.call({ to: cmodPluginName, method: partMethods.changed, input: { requests: [{ settings: true }], isAsked: true } });
|
|
122
122
|
};
|
|
123
123
|
let imports;
|
|
124
124
|
let raise;
|
|
@@ -151,7 +151,7 @@ export function createLifecycle(definition, permissionRoutes = () => undefined,
|
|
|
151
151
|
phase = 'failed';
|
|
152
152
|
failure ??= new Error(`${definition.name}: ${reason}${/[.!?]$/.test(reason) ? '' : '.'}${fix === undefined ? '' : ` ${fix}`}`, { cause: error });
|
|
153
153
|
const again = retry === undefined ? {} : { retry: () => ((failure = undefined), stopRetrying(), retry().catch(report)) };
|
|
154
|
-
toastFailure({ id: installId, message: reason, ...(fix === undefined ? {} : { description: fix }), ...(error === undefined ? {} : { error }), ...again });
|
|
154
|
+
toastFailure({ id: installId, message: reason, ...(fix === undefined ? {} : { description: fix }), ...(error === undefined ? {} : { error }), ...again, isCritical: true });
|
|
155
155
|
watchRecord();
|
|
156
156
|
};
|
|
157
157
|
let consented;
|
|
@@ -207,7 +207,7 @@ export function createLifecycle(definition, permissionRoutes = () => undefined,
|
|
|
207
207
|
return programs?.refresh();
|
|
208
208
|
}
|
|
209
209
|
if (failed !== undefined)
|
|
210
|
-
return void toastFailure({ id: recordId, message: failed, retry: record });
|
|
210
|
+
return void toastFailure({ id: recordId, message: failed, retry: record, isCritical: true });
|
|
211
211
|
throw new Error(`cmod setup ${formatExit(code, lastError)}`);
|
|
212
212
|
};
|
|
213
213
|
const record = () => {
|
|
@@ -304,20 +304,18 @@ export function createLifecycle(definition, permissionRoutes = () => undefined,
|
|
|
304
304
|
runtime.claude.ui.invalidate('ui.render');
|
|
305
305
|
if (definition.name === cmodPluginName)
|
|
306
306
|
runtime.claude.ui.invalidate('command.describe');
|
|
307
|
-
void runSteps(active.mod).catch((error) => toastFailure({ id: 'cmod:steps', message: 'Its installer stopped', error }));
|
|
307
|
+
void runSteps(active.mod).catch((error) => toastFailure({ id: 'cmod:steps', message: 'Its installer stopped', error, isCritical: true }));
|
|
308
308
|
const missed = missedSessionStart;
|
|
309
309
|
missedSessionStart = undefined;
|
|
310
310
|
if (missed !== undefined)
|
|
311
311
|
await replaySessionStart(missed);
|
|
312
|
-
|
|
313
|
-
const announced = announcedOf(await runtime.claude.store.get(announcedKey));
|
|
314
|
-
if (announced?.version === version) {
|
|
312
|
+
if ((await runtime.claude.store.get(announcedKey)) !== undefined) {
|
|
315
313
|
runtime.toaster.toast.dismiss(installId);
|
|
316
314
|
return;
|
|
317
315
|
}
|
|
318
|
-
await runtime.claude.store.set(announcedKey, { version
|
|
316
|
+
await runtime.claude.store.set(announcedKey, { version: plugin.version ?? '' });
|
|
319
317
|
const { toaster } = runtime;
|
|
320
|
-
void announcementOf(runtime.claude, plugin, granted, added,
|
|
318
|
+
void announcementOf(runtime.claude, plugin, granted, added, openSettings)
|
|
321
319
|
.then(({ message, ...options }) => toaster.toast.success(message, { id: installId, duration: announcementMs, ...options }))
|
|
322
320
|
.catch((error) => toastFailure({ id: installId, message: 'Could not say what it installed', error }));
|
|
323
321
|
};
|
|
@@ -570,13 +568,11 @@ export function createLifecycle(definition, permissionRoutes = () => undefined,
|
|
|
570
568
|
if (droppedParts.has(item))
|
|
571
569
|
return;
|
|
572
570
|
droppedParts.add(item);
|
|
573
|
-
const
|
|
574
|
-
|
|
575
|
-
runtime?.toaster.toast.warning(`Answered ${part} without your grant to "${permissionWords(item)}", so cmod dropped it`, {
|
|
571
|
+
const isDeclared = (plugin?.steps.permissions ?? []).includes(item);
|
|
572
|
+
toastFailure({
|
|
576
573
|
id: `dropped:${item}`,
|
|
574
|
+
message: `Answered ${part} without your grant to "${permissionWords(item)}", so cmod dropped it`,
|
|
577
575
|
description: isDeclared ? grantFix : `It needs "permissions": { "${item}": true } in package.json "cmod".`,
|
|
578
|
-
duration: Infinity,
|
|
579
|
-
...(isDeclared ? { action: { label: 'Settings', onClick: () => openSettings('permissions') } } : {}),
|
|
580
576
|
});
|
|
581
577
|
},
|
|
582
578
|
};
|
|
@@ -624,7 +620,17 @@ export function createLifecycle(definition, permissionRoutes = () => undefined,
|
|
|
624
620
|
if (runtime !== undefined)
|
|
625
621
|
return;
|
|
626
622
|
programs = locatingPrograms(claudeCalls);
|
|
627
|
-
|
|
623
|
+
const callingCmod = {
|
|
624
|
+
...claudeCalls,
|
|
625
|
+
cmod: {
|
|
626
|
+
async call(input) {
|
|
627
|
+
if (input.to === definition.name)
|
|
628
|
+
await holdUntilStarted();
|
|
629
|
+
return answeringOwnCalls(claudeCalls, router).cmod.call(input);
|
|
630
|
+
},
|
|
631
|
+
},
|
|
632
|
+
};
|
|
633
|
+
runtime = { claude: programs.claude, toaster: createToaster(callingCmod, definition.name, () => plugin?.version) };
|
|
628
634
|
readStarted = read;
|
|
629
635
|
try {
|
|
630
636
|
drawCount = (await claudeCalls.clock.now()) * drawsPerMs;
|
|
@@ -679,7 +685,7 @@ export function createLifecycle(definition, permissionRoutes = () => undefined,
|
|
|
679
685
|
return { value: await pendingSteps(mod) };
|
|
680
686
|
if (call.method === finishStepsMethod) {
|
|
681
687
|
const active = mod;
|
|
682
|
-
const opened = await installer.collect(() => Promise.race([runSteps(active).catch((error) => void toastFailure({ id: 'cmod:steps', message: 'Could not finish the setup', error })), installer.shown()]));
|
|
688
|
+
const opened = await installer.collect(() => Promise.race([runSteps(active).catch((error) => void toastFailure({ id: 'cmod:steps', message: 'Could not finish the setup', error, isCritical: true })), installer.shown()]));
|
|
683
689
|
return { value: opened };
|
|
684
690
|
}
|
|
685
691
|
}
|
|
@@ -731,7 +737,7 @@ async function createMod(definition, runtime) {
|
|
|
731
737
|
home,
|
|
732
738
|
configRoot,
|
|
733
739
|
projectRoot: () => modState.root,
|
|
734
|
-
freeFolders: () => [modState.root, runtime.dataFolder],
|
|
740
|
+
freeFolders: () => [modState.root, definition.name === cmodPluginName ? runtime.store : runtime.dataFolder],
|
|
735
741
|
freeAddresses: () => programAddresses(mod),
|
|
736
742
|
};
|
|
737
743
|
const checked = checkingGrants(claude, grants);
|
|
@@ -789,6 +795,7 @@ async function createMod(definition, runtime) {
|
|
|
789
795
|
claude: checked,
|
|
790
796
|
report: (id, message, error) => report({ id, message, error }),
|
|
791
797
|
isGranted: (permission) => flag(permission),
|
|
798
|
+
permissionRefusal: (call, permission) => refusal(grants, call, permission),
|
|
792
799
|
hookOn: (hook, listener, failed) => hookOn(hook, listener, failed),
|
|
793
800
|
routeOn: (event, hook, failed) => router.add(event, hook, failed),
|
|
794
801
|
permissionRoutes: runtime.permissionRoutes,
|
package/runtime/sessions.d.ts
CHANGED
|
@@ -70,11 +70,12 @@ export declare function isHeardBy(event: SessionEvent, matcher: unknown, change:
|
|
|
70
70
|
export declare function isInScope(scope: Scope, session: string, change: SessionChange, isUnder: (task: string, ancestor: string) => boolean): boolean;
|
|
71
71
|
export declare function withoutPermissionCheck(name: string, hearer: string): string;
|
|
72
72
|
export type HookOn = (hook: string, listener: (input: unknown) => HookFields | undefined | Promise<HookFields | undefined>, failed?: (input: unknown, error: Error) => HookFields | undefined) => Subscription;
|
|
73
|
-
export declare function createSessionsClient({ name, claude, report, isGranted, hookOn, routeOn, permissionRoutes }: {
|
|
73
|
+
export declare function createSessionsClient({ name, claude, report, isGranted, permissionRefusal, hookOn, routeOn, permissionRoutes }: {
|
|
74
74
|
readonly name: string;
|
|
75
75
|
readonly claude: Claude;
|
|
76
76
|
readonly report: (id: string, message: string, error: unknown) => void;
|
|
77
77
|
readonly isGranted: (permission: string) => boolean;
|
|
78
|
+
readonly permissionRefusal: (call: string, permission: string) => string;
|
|
78
79
|
readonly hookOn?: HookOn;
|
|
79
80
|
readonly routeOn?: RouteOn;
|
|
80
81
|
readonly permissionRoutes?: () => PermissionRoutes | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/runtime/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAM5D,OAAO,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAA;AAC3E,OAAO,EAAsB,KAAK,IAAI,EAAE,MAAM,iCAAiC,CAAA;AAC/E,OAAO,EAA+D,KAAK,aAAa,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,KAAK,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAG5K,OAAO,EAAuD,KAAK,WAAW,EAA+F,KAAK,WAAW,EAA8D,KAAK,YAAY,EAAuC,KAAK,QAAQ,EAAkB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,KAAK,KAAK,EAAE,MAAM,uBAAuB,CAAA;AACla,OAAO,EAAsC,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAA;AAC1F,OAAO,EAAkF,KAAK,KAAK,EAAE,MAAM,aAAa,CAAA;AACxH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"sessions.d.ts","sourceRoot":"","sources":["../src/runtime/sessions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAM5D,OAAO,EAAE,UAAU,EAAE,MAAM,gDAAgD,CAAA;AAC3E,OAAO,EAAsB,KAAK,IAAI,EAAE,MAAM,iCAAiC,CAAA;AAC/E,OAAO,EAA+D,KAAK,aAAa,EAAE,K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BAAoB,CAAC,GAAG,YAAY,CAAA;CACnL,CAAA;AAED,eAAO,MAAM,QAAQ,UAAW,OAAO,KAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAqH,CAAA;AAE/L,eAAO,MAAM,OAAO,WAAY,UAAU,KAAG,UAAmG,CAAA;AAqChJ,KAAK,iBAAiB,GAAG,OAAO,CAAC,WAAW,EAAE,iBAAiB,CAAC,CAAA;AAmChE,wBAAsB,SAAS,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAc1H;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,iBAAiB,EAAE,KAAK,EAAE,OAAO,GAAG,UAAU,CAGrF;AAkBD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC,EAAE,IAAI,EAAE,YAAY,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,EAAE,QAAQ,EAAE,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,UAAU,CAI7L"}
|
package/runtime/sessions.js
CHANGED
|
@@ -13,7 +13,6 @@ import { matches, sentMatcher } from '../utils/matcher.js';
|
|
|
13
13
|
import { beforeAnswerKeys, foldAnswers, foldBefore, methodOf, takenAnswer } from './before.js';
|
|
14
14
|
import { cmodPluginName } from './dependencies.js';
|
|
15
15
|
import { messageOf } from '../utils/text.js';
|
|
16
|
-
import { grantFix, permissionWords } from '../records.js';
|
|
17
16
|
import { listenerOf, PassedTimeout, withinTime } from './deadline.js';
|
|
18
17
|
import { callFiles } from './hooks.js';
|
|
19
18
|
export const everySession = '*';
|
|
@@ -127,7 +126,7 @@ export function isInScope(scope, session, change, isUnder) {
|
|
|
127
126
|
export function withoutPermissionCheck(name, hearer) {
|
|
128
127
|
return `${name}: ${hearer} hears Claude Code's permission check, so hooks/register.ts must call registerPermissionCheck(addHook) after registerMod.`;
|
|
129
128
|
}
|
|
130
|
-
export function createSessionsClient({ name, claude, report, isGranted, hookOn, routeOn, permissionRoutes }) {
|
|
129
|
+
export function createSessionsClient({ name, claude, report, isGranted, permissionRefusal, hookOn, routeOn, permissionRoutes }) {
|
|
131
130
|
const call = (method, input) => claude.cmod.call({ to: cmodPluginName, method, input });
|
|
132
131
|
const listening = new Map();
|
|
133
132
|
const deciding = new Map();
|
|
@@ -146,6 +145,8 @@ export function createSessionsClient({ name, claude, report, isGranted, hookOn,
|
|
|
146
145
|
queued.delete(key);
|
|
147
146
|
const heard = (from) => [...(from.get(key) ?? [])].map(({ event, matcher, options, scope }) => ({ event, matcher: matcher === undefined ? undefined : sentMatcher(matcher), ...(options.onFailure === 'refuse' ? { onFailure: 'refuse', scope } : {}) }));
|
|
148
147
|
const tracksTasks = [...(listening.get(key) ?? []), ...(deciding.get(key) ?? [])].some(({ scope }) => scope.task !== undefined || scope.isGoal === true);
|
|
148
|
+
if (tracksTasks)
|
|
149
|
+
void learnTasks(key).catch((error) => report(`tasks:${key}`, 'Could not read the tasks it listens under', error));
|
|
149
150
|
const subscriptions = [...heard(listening), ...(tracksTasks ? [{ event: TaskStart }] : [])];
|
|
150
151
|
await call(conversationMethods.subscribe, { session: key, subscriptions }).catch((error) => report(`sessions:${key}`, `Hears nothing from ${key === everySession ? 'the other sessions' : `session ${key}`}`, error));
|
|
151
152
|
await call(conversationMethods.watchBefore, { session: key, subscriptions: heard(deciding) }).catch((error) => report(`before:${key}`, `Changes nothing in ${key === everySession ? 'the other sessions' : `session ${key}`}`, error));
|
|
@@ -176,8 +177,6 @@ export function createSessionsClient({ name, claude, report, isGranted, hookOn,
|
|
|
176
177
|
const set = into.get(key) ?? new Set();
|
|
177
178
|
set.add(entry);
|
|
178
179
|
into.set(key, set);
|
|
179
|
-
if (scope.task !== undefined || scope.isGoal === true)
|
|
180
|
-
void learnTasks(scope.session ?? current.id).catch((error) => report(`tasks:${key}`, 'Could not read the tasks it listens under', error));
|
|
181
180
|
onChange(key);
|
|
182
181
|
return {
|
|
183
182
|
remove() {
|
|
@@ -214,7 +213,7 @@ export function createSessionsClient({ name, claude, report, isGranted, hookOn,
|
|
|
214
213
|
const missing = answerPermissions(event, answer).find((permission) => !isGranted(permission));
|
|
215
214
|
if (missing === undefined)
|
|
216
215
|
return answer;
|
|
217
|
-
throw new Error(
|
|
216
|
+
throw new Error(permissionRefusal(`${entry.method} with the answer { ${Object.keys(answer).join(', ')} }`, missing));
|
|
218
217
|
});
|
|
219
218
|
const answer = await foldBefore(event, change, askers, (error) => report(`session:${methodOf('before', event)}`, `The ${methodOf('before', event)} listener failed`, error));
|
|
220
219
|
return answer?.note === undefined ? answer : { ...answer, note: modNote(name, answer.note) };
|
|
@@ -467,7 +466,7 @@ export function createSessionsClient({ name, claude, report, isGranted, hookOn,
|
|
|
467
466
|
return { text: answer['refuse'] };
|
|
468
467
|
const changes = answer !== undefined && isGranted('prompt') ? answer : undefined;
|
|
469
468
|
if (answer !== undefined && changes === undefined)
|
|
470
|
-
report('session:beforeRun', 'The beforeRun listener failed', new Error(
|
|
469
|
+
report('session:beforeRun', 'The beforeRun listener failed', new Error(permissionRefusal(`beforeRun with the answer { ${Object.keys(answer).join(', ')} }`, 'prompt')));
|
|
471
470
|
if (typeof changes?.['result'] === 'string')
|
|
472
471
|
return { text: changes['result'], ...(typeof changes['exitCode'] === 'number' ? { exitCode: changes['exitCode'] } : {}) };
|
|
473
472
|
const args = typeof changes?.['args'] === 'string' ? changes['args'] : e.args;
|
package/runtime/toaster.d.ts
CHANGED
|
@@ -12,7 +12,19 @@ export type Failure = {
|
|
|
12
12
|
readonly error?: unknown;
|
|
13
13
|
readonly description?: string;
|
|
14
14
|
readonly retry?: () => unknown;
|
|
15
|
+
readonly isCritical?: boolean;
|
|
15
16
|
};
|
|
17
|
+
export type LoggedFailure = {
|
|
18
|
+
readonly mod: string;
|
|
19
|
+
readonly id: string;
|
|
20
|
+
readonly message: string;
|
|
21
|
+
readonly details: string;
|
|
22
|
+
readonly at: string;
|
|
23
|
+
readonly isCritical: boolean;
|
|
24
|
+
readonly root: string;
|
|
25
|
+
readonly contact?: Contact;
|
|
26
|
+
};
|
|
27
|
+
export declare const failedMethod = "cmod:failed";
|
|
16
28
|
export type Toaster = {
|
|
17
29
|
readonly toast: Toast;
|
|
18
30
|
copy(text: string): Promise<void>;
|
|
@@ -20,5 +32,14 @@ export type Toaster = {
|
|
|
20
32
|
readonly shown: readonly ShownToast[];
|
|
21
33
|
draw(drawn: RenderElement, table: ElementTable, band: RenderPropsOf['AbovePrompt'], bandId: string): RenderElement;
|
|
22
34
|
};
|
|
23
|
-
export
|
|
35
|
+
export type Contact = {
|
|
36
|
+
readonly kind: 'github';
|
|
37
|
+
readonly repository: string;
|
|
38
|
+
} | {
|
|
39
|
+
readonly kind: 'email';
|
|
40
|
+
readonly address: string;
|
|
41
|
+
};
|
|
42
|
+
export declare function createToaster(claude: Claude, name: string, version: () => string | undefined): Toaster;
|
|
43
|
+
export declare function reportLink(contact: Contact, name: string, message: string, details: string): RenderElement;
|
|
44
|
+
export declare function reportPrompt(name: string, contact: Contact | undefined, details: string): string;
|
|
24
45
|
//# sourceMappingURL=toaster.d.ts.map
|
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;
|
|
1
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AA;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,CAkTtG;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,9 +1,13 @@
|
|
|
1
1
|
import { Box, Button, drawWith, Link, Text } from '../ui/elements.js';
|
|
2
2
|
import { coreVersion, grantFix, installFix, isObject, secretFix } from '../records.js';
|
|
3
3
|
import { firstLine, messageOf } from '../utils/text.js';
|
|
4
|
+
import { beforeDeadline } from './deadline.js';
|
|
5
|
+
import { cmodPluginName } from './dependencies.js';
|
|
6
|
+
export const failedMethod = 'cmod:failed';
|
|
4
7
|
const githubRepository = /^https:\/\/github\.com\/([^/]+\/[^/#?]+?)(?:\.git)?(?:\/issues)?\/?$/;
|
|
5
8
|
const linkLimit = 2048;
|
|
6
9
|
const hiddenKey = 'cmod:hidden-failures';
|
|
10
|
+
const failedCallMs = 30_000;
|
|
7
11
|
const defaultDuration = 4000;
|
|
8
12
|
const visibleToasts = 3;
|
|
9
13
|
const spinner = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
|
|
@@ -17,9 +21,10 @@ const icons = {
|
|
|
17
21
|
warning: { glyph: '⚠', color: 'warning' },
|
|
18
22
|
error: { glyph: '✗', color: 'error' },
|
|
19
23
|
};
|
|
20
|
-
export function createToaster(claude, name, version
|
|
24
|
+
export function createToaster(claude, name, version) {
|
|
21
25
|
const entries = new Map();
|
|
22
26
|
const hidden = new Map();
|
|
27
|
+
const sent = new Map();
|
|
23
28
|
void claude.store.get(hiddenKey).then((saved) => {
|
|
24
29
|
if (typeof saved !== 'object' || saved === null)
|
|
25
30
|
return;
|
|
@@ -70,6 +75,10 @@ export function createToaster(claude, name, version, openPermissions) {
|
|
|
70
75
|
});
|
|
71
76
|
};
|
|
72
77
|
const dismiss = (id) => {
|
|
78
|
+
if (id === undefined)
|
|
79
|
+
sent.clear();
|
|
80
|
+
else
|
|
81
|
+
sent.delete(String(id));
|
|
73
82
|
for (const entry of entries.values()) {
|
|
74
83
|
if (id !== undefined && entry.id !== id)
|
|
75
84
|
continue;
|
|
@@ -133,33 +142,69 @@ export function createToaster(claude, name, version, openPermissions) {
|
|
|
133
142
|
};
|
|
134
143
|
const press = (entry, run) => () => void Promise.resolve()
|
|
135
144
|
.then(run)
|
|
136
|
-
.catch((error) => fail({ id: `press:${entry.id}`, message: `${entry.message}: the press failed`, error }));
|
|
137
|
-
const
|
|
145
|
+
.catch((error) => fail({ id: `press:${entry.id}`, message: `${entry.message}: the press failed`, error, isCritical: true }));
|
|
146
|
+
const logFailure = (failure) => claude.cmod.call({ to: cmodPluginName, method: failedMethod, input: failure });
|
|
147
|
+
const showsToast = async (failure, isShown) => {
|
|
148
|
+
try {
|
|
149
|
+
const logged = logFailure(failure);
|
|
150
|
+
const answer = await (isShown ? logged : beforeDeadline(claude, { ms: failedCallMs }, failedMethod, logged));
|
|
151
|
+
if (isObject(answer) && typeof answer['showsToast'] === 'boolean')
|
|
152
|
+
return answer['showsToast'];
|
|
153
|
+
throw new Error(`cmod answered ${answer === undefined ? 'nothing' : JSON.stringify(answer)}, not { showsToast: true or false }`);
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
claude.ui.log(`${name}: cmod kept no Log of ${failure.id}, so it shows the toast: ${messageOf(error)}`, { to: 'debug' });
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
const fail = ({ id, message, error, description = error === undefined || describe(error) === message ? undefined : describe(error), retry, isCritical = false }) => {
|
|
138
161
|
const hides = `${version() ?? ''}\n${message}\n${error === undefined ? '' : describe(error)}`;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const shown = entries.get(id);
|
|
143
|
-
if (shown?.hides === hides && shown.trying === undefined && shown.options.description === description) {
|
|
144
|
-
const previous = clockTime(shown.at);
|
|
145
|
-
shown.at = new Date();
|
|
146
|
-
if (clockTime(shown.at) !== previous)
|
|
147
|
-
changed();
|
|
162
|
+
const at = new Date();
|
|
163
|
+
const repeat = `${hides}\n${description ?? ''}\n${at.toISOString().slice(0, 16)}`;
|
|
164
|
+
if (sent.get(id) === repeat)
|
|
148
165
|
return id;
|
|
149
|
-
|
|
166
|
+
sent.set(id, repeat);
|
|
150
167
|
const stack = error instanceof Error && error.stack !== undefined ? `\n\n${error.stack}` : '';
|
|
151
|
-
const details = async () => {
|
|
168
|
+
const details = async (failedAt) => {
|
|
152
169
|
const modVersion = await claude.fs
|
|
153
170
|
.read(`${claude.plugin.root}/.claude-plugin/plugin.json`)
|
|
154
171
|
.then((text) => String(JSON.parse(text).version))
|
|
155
172
|
.catch((failure) => `unknown (${messageOf(failure)})`);
|
|
156
|
-
return `${name} ${modVersion}, @cmodjs/core ${coreVersion}, at ${
|
|
173
|
+
return `${name} ${modVersion}, @cmodjs/core ${coreVersion}, at ${failedAt.toISOString()}\n${message}${description === undefined ? '' : `\n${description}`}${stack}`;
|
|
174
|
+
};
|
|
175
|
+
const text = `${message}\n${description ?? ''}`;
|
|
176
|
+
const isGrantRefusal = text.includes(grantFix);
|
|
177
|
+
const isShownAtOnce = isCritical && !isGrantRefusal;
|
|
178
|
+
const logged = async () => {
|
|
179
|
+
const contact = await contactOf(claude);
|
|
180
|
+
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, isShownAtOnce);
|
|
182
|
+
if (isShownAtOnce)
|
|
183
|
+
return;
|
|
184
|
+
if (shows === undefined || (shows && !isGrantRefusal))
|
|
185
|
+
return show();
|
|
186
|
+
claude.ui.log(`${name}: ${message}${description === undefined ? '' : `: ${description}`}`, { to: 'debug' });
|
|
187
|
+
};
|
|
188
|
+
const show = () => {
|
|
189
|
+
if (hidden.get(id) === hides)
|
|
190
|
+
return;
|
|
191
|
+
hidden.delete(id);
|
|
192
|
+
const shown = entries.get(id);
|
|
193
|
+
if (shown?.hides === hides && shown.trying === undefined && shown.options.description === description) {
|
|
194
|
+
const previous = clockTime(shown.at);
|
|
195
|
+
shown.at = new Date();
|
|
196
|
+
if (clockTime(shown.at) !== previous)
|
|
197
|
+
changed();
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const actions = [...fixes, ...(retry === undefined ? [] : [{ label: 'Retry', onClick: tryAgain }]), { label: 'Report', onClick: startReporting }];
|
|
201
|
+
put('error', message, { id, ...(description === undefined ? {} : { description }), duration: Infinity }, actions, hides);
|
|
157
202
|
};
|
|
158
203
|
const startReporting = async () => {
|
|
159
204
|
const shown = entries.get(id);
|
|
160
205
|
if (shown === undefined)
|
|
161
206
|
return;
|
|
162
|
-
shown.reporting = { contact: await contactOf(claude), details: await details() };
|
|
207
|
+
shown.reporting = { contact: await contactOf(claude), details: await details(shown.at) };
|
|
163
208
|
disarm(shown);
|
|
164
209
|
changed();
|
|
165
210
|
if (bandId === undefined)
|
|
@@ -184,14 +229,14 @@ export function createToaster(claude, name, version, openPermissions) {
|
|
|
184
229
|
}
|
|
185
230
|
}
|
|
186
231
|
};
|
|
187
|
-
const text = `${message}\n${description ?? ''}`;
|
|
188
232
|
const fixes = [
|
|
189
|
-
{ sentence: grantFix, label: 'Settings', onClick: openPermissions },
|
|
190
233
|
{ sentence: installFix, label: 'Plugins', onClick: () => claude.command.run({ command: 'plugin' }) },
|
|
191
234
|
{ sentence: secretFix, label: 'Open /config', onClick: () => claude.command.run({ command: 'config' }) },
|
|
192
235
|
].filter(({ sentence }) => text.includes(sentence));
|
|
193
|
-
|
|
194
|
-
|
|
236
|
+
if (isShownAtOnce)
|
|
237
|
+
show();
|
|
238
|
+
claude.clock.after(0, () => void logged());
|
|
239
|
+
return id;
|
|
195
240
|
};
|
|
196
241
|
const toggle = (entry) => () => {
|
|
197
242
|
entry.isOpen = !entry.isOpen;
|
|
@@ -238,7 +283,7 @@ export function createToaster(claude, name, version, openPermissions) {
|
|
|
238
283
|
const copied = await claude.ui.copy({ text: details });
|
|
239
284
|
say(copied.isCopied ? 'Copied the error.' : `Could not copy it: ${copied.reason}`);
|
|
240
285
|
};
|
|
241
|
-
const report = contact === undefined ? [] : [
|
|
286
|
+
const report = contact === undefined ? [] : [reportLink(contact, name, entry.message, details)];
|
|
242
287
|
return [
|
|
243
288
|
Text({ dimColor: true, children: 'Claude writes up the problem and files it with your tools. You approve each step before anything is posted.' }),
|
|
244
289
|
Box({
|
|
@@ -309,7 +354,7 @@ async function contactOf(claude) {
|
|
|
309
354
|
const address = isObject(author) ? author['email'] : undefined;
|
|
310
355
|
return typeof address === 'string' && address !== '' ? { kind: 'email', address } : undefined;
|
|
311
356
|
}
|
|
312
|
-
function reportLink(contact, name, message, details) {
|
|
357
|
+
export function reportLink(contact, name, message, details) {
|
|
313
358
|
const title = `${name}: ${message}`.slice(0, 120);
|
|
314
359
|
const linkOf = (body) => contact.kind === 'github'
|
|
315
360
|
? `https://github.com/${contact.repository}/issues/new?title=${encodeURIComponent(title)}&body=${encodeURIComponent(body)}`
|
|
@@ -317,9 +362,9 @@ function reportLink(contact, name, message, details) {
|
|
|
317
362
|
let body = details;
|
|
318
363
|
while (linkOf(body).length > linkLimit && body.length > 0)
|
|
319
364
|
body = `${body.slice(0, Math.floor(body.length * 0.8))}…`;
|
|
320
|
-
return linkOf(body);
|
|
365
|
+
return Link({ href: linkOf(body), label: contact.kind === 'github' ? 'Report it on GitHub (opens your browser)' : 'Email the author (opens your mail app)' });
|
|
321
366
|
}
|
|
322
|
-
function reportPrompt(name, contact, details) {
|
|
367
|
+
export function reportPrompt(name, contact, details) {
|
|
323
368
|
const where = contact === undefined
|
|
324
369
|
? `${name} names no place to report it, so find its author from its plugin.json or its marketplace.`
|
|
325
370
|
: contact.kind === 'github'
|
package/runtime/ui.js
CHANGED
|
@@ -605,7 +605,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
605
605
|
await run(...args);
|
|
606
606
|
}
|
|
607
607
|
catch (error) {
|
|
608
|
-
report({ id: known.id, message: 'Its button failed', error });
|
|
608
|
+
report({ id: known.id, message: 'Its button failed', error, isCritical: true });
|
|
609
609
|
}
|
|
610
610
|
};
|
|
611
611
|
if (caller === cmodPluginName)
|
package/src/hotkeys.ts
CHANGED
|
@@ -14,7 +14,7 @@ type Modifiers = 'ctrl' | 'alt' | 'shift' | 'meta' | 'ctrl+alt' | 'ctrl+shift' |
|
|
|
14
14
|
|
|
15
15
|
export type Combo = `${Modifiers}+${Key}`
|
|
16
16
|
|
|
17
|
-
export type HotkeyInit = { readonly title: string; readonly default
|
|
17
|
+
export type HotkeyInit = { readonly title: string; readonly default?: Combo }
|
|
18
18
|
|
|
19
19
|
export type Hotkeys = Readonly<Record<string, HotkeyInit>>
|
|
20
20
|
|
|
@@ -42,6 +42,7 @@ export function checkHotkeys(name: string, hotkeys: Hotkeys): Hotkeys {
|
|
|
42
42
|
const at = `${name}: hotkeys.${key}`
|
|
43
43
|
if (!hotkeyName.test(key)) throw new Error(`${at} is not a hotkey name. Use letters, digits, and _, starting with a letter.`)
|
|
44
44
|
if (declared.title.trim() === '') throw new Error(`${at} needs a title, the label Settings shows beside its combo.`)
|
|
45
|
+
if (declared.default === undefined) continue
|
|
45
46
|
if (!isCombo(declared.default)) throw new Error(`${at} defaults to "${String(declared.default)}", which is not a combo. Give one or two of ctrl, alt, shift, meta in that order, then a key, such as "ctrl+q" or "ctrl+shift+k".`)
|
|
46
47
|
const taken = combos.get(declared.default)
|
|
47
48
|
if (taken !== undefined) throw new Error(`${at} defaults to ${declared.default}, which hotkeys.${taken} has too. Give each hotkey its own combo.`)
|
package/src/jobs/program.ts
CHANGED
|
@@ -44,7 +44,7 @@ export function program(options: { readonly command: readonly string[]; readonly
|
|
|
44
44
|
failure = undefined
|
|
45
45
|
void start()
|
|
46
46
|
}
|
|
47
|
-
report({ id: `program:${executable}`, message: `The ${executable} program stopped`, description: reason, retry })
|
|
47
|
+
report({ id: `program:${executable}`, message: `The ${executable} program stopped`, description: reason, retry, isCritical: true })
|
|
48
48
|
for (const waiter of waiting.splice(0)) waiter.reject(failure)
|
|
49
49
|
}
|
|
50
50
|
|