@cmodjs/core 5.2.1 → 5.4.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 +26 -2
- package/docs/dependencies.md +27 -0
- package/docs/install-steps.md +2 -0
- package/docs/jobs.md +1 -1
- package/docs/mod.md +9 -0
- package/docs/options.md +2 -0
- package/docs/state.md +1 -1
- package/docs/testing.md +2 -2
- package/docs/ui.md +1 -1
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +55 -4
- package/mod.d.ts +4 -0
- package/mod.d.ts.map +1 -1
- package/mod.js +3 -0
- package/options.d.ts +5 -0
- package/options.d.ts.map +1 -1
- package/options.js +52 -0
- package/package.json +1 -1
- package/records.d.ts +2 -2
- package/records.js +2 -2
- package/register.d.ts.map +1 -1
- package/register.js +23 -3
- package/runtime/claude.d.ts +2 -0
- package/runtime/claude.d.ts.map +1 -1
- package/runtime/conversations.js +8 -8
- package/runtime/deadline.d.ts +2 -0
- package/runtime/deadline.d.ts.map +1 -1
- package/runtime/deadline.js +17 -0
- package/runtime/dependencies.d.ts +1 -0
- package/runtime/dependencies.d.ts.map +1 -1
- package/runtime/dependencies.js +1 -0
- package/runtime/device.d.ts +13 -2
- package/runtime/device.d.ts.map +1 -1
- package/runtime/engine.d.ts +2 -0
- package/runtime/engine.d.ts.map +1 -1
- package/runtime/hooks.js +2 -2
- package/runtime/hotkeys.js +1 -1
- package/runtime/installer.js +1 -1
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +106 -75
- package/runtime/metadata.js +1 -1
- package/runtime/options.d.ts.map +1 -1
- package/runtime/options.js +6 -31
- package/runtime/pages.js +3 -3
- package/runtime/programs.d.ts +1 -0
- package/runtime/programs.d.ts.map +1 -1
- package/runtime/programs.js +6 -0
- package/runtime/sessions.js +1 -1
- package/runtime/state.d.ts +1 -0
- package/runtime/state.d.ts.map +1 -1
- package/runtime/state.js +6 -3
- package/runtime/toaster.d.ts +5 -0
- package/runtime/toaster.d.ts.map +1 -1
- package/runtime/toaster.js +27 -11
- package/runtime/ui.d.ts +1 -0
- package/runtime/ui.d.ts.map +1 -1
- package/runtime/ui.js +6 -6
- package/runtime/widgets.js +1 -1
- package/src/jobs/program.ts +60 -4
- package/src/mod.ts +5 -0
- package/src/options.ts +51 -0
- package/src/records.ts +2 -2
- package/src/register.ts +25 -3
- package/src/runtime/claude.ts +2 -0
- package/src/runtime/conversations.ts +8 -8
- package/src/runtime/deadline.ts +16 -0
- package/src/runtime/dependencies.ts +2 -0
- package/src/runtime/device.ts +7 -3
- package/src/runtime/engine.ts +2 -0
- package/src/runtime/hooks.ts +2 -2
- package/src/runtime/hotkeys.ts +1 -1
- package/src/runtime/installer.ts +1 -1
- package/src/runtime/lifecycle.ts +97 -67
- package/src/runtime/metadata.ts +1 -1
- package/src/runtime/options.ts +5 -26
- package/src/runtime/pages.ts +3 -3
- package/src/runtime/programs.ts +7 -0
- package/src/runtime/sessions.ts +1 -1
- package/src/runtime/state.ts +7 -3
- package/src/runtime/toaster.ts +47 -12
- package/src/runtime/ui.ts +6 -6
- package/src/runtime/widgets.ts +1 -1
- package/src/testing/fake-claude.ts +2 -0
- package/src/testing.ts +8 -4
- package/testing/fake-claude.d.ts.map +1 -1
- package/testing/fake-claude.js +2 -0
- package/testing.d.ts.map +1 -1
- package/testing.js +9 -4
package/runtime/options.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { fitsOption, isUnset } from '../options.js';
|
|
2
|
-
import { configFolders
|
|
1
|
+
import { fitsOption, isUnset, projectOptionsOf } from '../options.js';
|
|
2
|
+
import { configFolders } from '../records.js';
|
|
3
3
|
import { listed, messageOf } from '../utils/text.js';
|
|
4
4
|
export class MissingOptions extends Error {
|
|
5
5
|
keys;
|
|
@@ -18,7 +18,7 @@ export function createOptions({ name, declared, fromClaude, claude, report, chan
|
|
|
18
18
|
if (Object.keys(declared).length === 0)
|
|
19
19
|
return new Set();
|
|
20
20
|
const rows = await claude.config.list().catch((error) => {
|
|
21
|
-
claude.ui.
|
|
21
|
+
claude.ui.warn('options:config', `${name} could not read /config, so a project's options.json may override a value your organization set: ${messageOf(error)}`);
|
|
22
22
|
return [];
|
|
23
23
|
});
|
|
24
24
|
return new Set(rows.filter((row) => row.isLocked && row.key.startsWith(`${name}.`)).map((row) => row.key.slice(name.length + 1)));
|
|
@@ -31,34 +31,9 @@ export function createOptions({ name, declared, fromClaude, claude, report, chan
|
|
|
31
31
|
const path = `${project.folder}/options.json`;
|
|
32
32
|
if (!(await claude.fs.exists(path)))
|
|
33
33
|
return {};
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
file = JSON.parse(await claude.fs.read(path));
|
|
38
|
-
}
|
|
39
|
-
catch (error) {
|
|
40
|
-
ignore(`is not JSON (${messageOf(error)}). Fix the file; ${name} uses its other options until then.`);
|
|
41
|
-
return {};
|
|
42
|
-
}
|
|
43
|
-
if (typeof file !== 'object' || file === null || Array.isArray(file)) {
|
|
44
|
-
ignore('is not a JSON object. Write one, such as { "branch": "main" }.');
|
|
45
|
-
return {};
|
|
46
|
-
}
|
|
47
|
-
const kept = {};
|
|
48
|
-
for (const [key, value] of Object.entries(file)) {
|
|
49
|
-
const option = declared[key];
|
|
50
|
-
if (option === undefined)
|
|
51
|
-
ignore(`sets ${key}, which ${name} does not declare. ${Object.keys(declared).length === 0 ? 'Remove it.' : `Remove it, or use one of: ${Object.keys(declared).join(', ')}.`}`);
|
|
52
|
-
else if (option.type === 'secret')
|
|
53
|
-
ignore(`sets ${key}, a secret, and a project file is committed for everyone to read. Remove it. ${secretFix}`);
|
|
54
|
-
else {
|
|
55
|
-
const misfit = fitsOption(option, value);
|
|
56
|
-
if (misfit === undefined)
|
|
57
|
-
kept[key] = value;
|
|
58
|
-
else
|
|
59
|
-
ignore(`sets ${key} to ${JSON.stringify(value)}, and ${option.title} ${misfit}.`);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
34
|
+
const { values: kept, ignored } = projectOptionsOf(name, declared, await claude.fs.read(path));
|
|
35
|
+
for (const reason of ignored)
|
|
36
|
+
report({ id: `options:${path} ${reason}`, message: `Ignores part of ${path}`, description: `${path} ${reason}` });
|
|
62
37
|
return kept;
|
|
63
38
|
};
|
|
64
39
|
return {
|
package/runtime/pages.js
CHANGED
|
@@ -47,7 +47,7 @@ export function servePages({ claude, router, report, widgets, parts, tellStylers
|
|
|
47
47
|
const pending = asking.get(mod) ??
|
|
48
48
|
claude.cmod
|
|
49
49
|
.call({ to: mod, method: partMethods.list, input: null })
|
|
50
|
-
.then((parts) => void declared.set(mod, pagesOf(parts)), (error) => claude.ui.
|
|
50
|
+
.then((parts) => void declared.set(mod, pagesOf(parts)), (error) => claude.ui.warn(`pages:list:${mod}`, `cmod: ${mod} did not list its pages: ${messageOf(error)}`))
|
|
51
51
|
.finally(() => asking.delete(mod));
|
|
52
52
|
asking.set(mod, pending);
|
|
53
53
|
return pending;
|
|
@@ -62,7 +62,7 @@ export function servePages({ claude, router, report, widgets, parts, tellStylers
|
|
|
62
62
|
tellStylers(listed);
|
|
63
63
|
for (const told of declared.keys()) {
|
|
64
64
|
if (told !== cmodPluginName)
|
|
65
|
-
void claude.cmod.call({ to: told, method: partMethods.stylers, input: listed }).catch((error) => claude.ui.
|
|
65
|
+
void claude.cmod.call({ to: told, method: partMethods.stylers, input: listed }).catch((error) => claude.ui.warn(`pages:stylers:${told}`, `cmod: ${told} did not hear which mods style markdown: ${messageOf(error)}`));
|
|
66
66
|
}
|
|
67
67
|
};
|
|
68
68
|
const update = (mod, { parts: listing, redraw, requests, isAsked }) => {
|
|
@@ -123,7 +123,7 @@ export function servePages({ claude, router, report, widgets, parts, tellStylers
|
|
|
123
123
|
press,
|
|
124
124
|
update,
|
|
125
125
|
tell(mod, shown) {
|
|
126
|
-
void claude.cmod.call({ to: mod, method: partMethods.shown, input: plain(shown) }).catch((error) => claude.ui.
|
|
126
|
+
void claude.cmod.call({ to: mod, method: partMethods.shown, input: plain(shown) }).catch((error) => claude.ui.warn(`pages:shown:${mod}`, `cmod: ${mod} did not hear which of its pages show: ${messageOf(error)}`));
|
|
127
127
|
},
|
|
128
128
|
apply(listener) {
|
|
129
129
|
applyTo = listener;
|
package/runtime/programs.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare function readLines(stream: HookStream<ProcessSpawnChunk, ProcessS
|
|
|
11
11
|
lastError: string;
|
|
12
12
|
}>;
|
|
13
13
|
export declare function spawnCmod(claude: Claude, args: readonly string[], session: string, env?: Readonly<Record<string, string>>): HookStream<ProcessSpawnChunk, ProcessSpawnResult>;
|
|
14
|
+
export declare function isHeld(claude: Claude, lock: string, staleMs: number): Promise<boolean>;
|
|
14
15
|
export declare function runCmod(claude: Claude, args: readonly string[], session: string): Promise<string>;
|
|
15
16
|
export declare function locatingPrograms(claude: Claude): Programs;
|
|
16
17
|
//# sourceMappingURL=programs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"programs.d.ts","sourceRoot":"","sources":["../src/runtime/programs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIpF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEzC,MAAM,MAAM,QAAQ,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAAA;AAE5E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAG3D;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAI7E;AAED,wBAAsB,SAAS,CAAC,MAAM,EAAE,UAAU,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,EAAE,MAAM,EAAE,CAAC,I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AAK,IAAI,GAAG,OAAO,CAAC;IAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CAgB9K;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,GAAG,UAAU,CAAC,iBAAiB,EAAE,kBAAkB,CAAC,CAEjL;AAED,wBAAsB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAK5F;AAED,wBAAsB,OAAO,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAKvG;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,QAAQ,CAsBzD"}
|
package/runtime/programs.js
CHANGED
|
@@ -33,6 +33,12 @@ export async function readLines(stream, onLine) {
|
|
|
33
33
|
export function spawnCmod(claude, args, session, env = {}) {
|
|
34
34
|
return claude.process.spawn({ argv: ['cmod', ...args], env: { ...env, CLAUDE_CODE_SESSION_ID: session } });
|
|
35
35
|
}
|
|
36
|
+
export async function isHeld(claude, lock, staleMs) {
|
|
37
|
+
const now = await claude.clock.now();
|
|
38
|
+
const holders = await claude.fs.list(lock).catch(ifMissing([]));
|
|
39
|
+
const touched = await Promise.all(holders.map(async ({ name }) => (await claude.fs.stat(`${lock}/${name}`).catch(ifMissing(undefined)))?.mtimeMs ?? 0));
|
|
40
|
+
return touched.some((at) => now - at < staleMs);
|
|
41
|
+
}
|
|
36
42
|
export async function runCmod(claude, args, session) {
|
|
37
43
|
const lines = [];
|
|
38
44
|
const { code, lastError } = await readLines(spawnCmod(claude, args, session), (line) => void lines.push(line));
|
package/runtime/sessions.js
CHANGED
|
@@ -173,7 +173,7 @@ export function createSessionsClient({ name, claude, report, hookOn, routeOn, pe
|
|
|
173
173
|
if (change.type !== TaskStart)
|
|
174
174
|
return;
|
|
175
175
|
parents.get(session)?.set(change.task.id, change.task.parent);
|
|
176
|
-
void readingParents.get(session)?.then((tree) => tree.set(change.task.id, change.task.parent), (error) => claude.ui.
|
|
176
|
+
void readingParents.get(session)?.then((tree) => tree.set(change.task.id, change.task.parent), (error) => claude.ui.warn('tasks:read', `${name}: the tasks of ${session} stay unread until the next change: ${messageOf(error)}`));
|
|
177
177
|
};
|
|
178
178
|
const add = (into, scope, event, method, args, onChange) => {
|
|
179
179
|
const key = keyOf(scope);
|
package/runtime/state.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export type ModState<State extends object> = {
|
|
|
21
21
|
switchSession(session: string, source: ClassicHookInputs['SessionStart']['source'], transcript: string): Promise<void>;
|
|
22
22
|
};
|
|
23
23
|
export declare function onStateChange(state: object, listener: () => void): Subscription;
|
|
24
|
+
export declare function sessionKeyOf(name: string, key: string, session: string): string;
|
|
24
25
|
export declare function sessionsWith(claude: Pick<Claude, 'store'>, name: string, key: string, value: unknown): Promise<string[]>;
|
|
25
26
|
export declare function createState<State extends object>({ name, initial, session, root, claude, report, changed: redraw, forkParent }: StateOptions): ModState<State>;
|
|
26
27
|
//# sourceMappingURL=state.d.ts.map
|
package/runtime/state.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/runtime/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACzC,OAAO,KAAK,EAAE,OAAO,EAAE,MA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M,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IACnC,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,iBAAiB,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACvH,CAAA;AAQD,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,YAAY,CAK/E;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAE/E;AAED,wBAAsB,YAAY,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAO9H;AAED,wBAAgB,WAAW,CAAC,KAAK,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,EAAE,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,CAoH9J"}
|
package/runtime/state.js
CHANGED
|
@@ -7,8 +7,11 @@ export function onStateChange(state, listener) {
|
|
|
7
7
|
listeners.set(state, own);
|
|
8
8
|
return { remove: () => void own.delete(listener) };
|
|
9
9
|
}
|
|
10
|
+
export function sessionKeyOf(name, key, session) {
|
|
11
|
+
return `${name}.${key}.sessions.${session}`;
|
|
12
|
+
}
|
|
10
13
|
export async function sessionsWith(claude, name, key, value) {
|
|
11
|
-
const prefix =
|
|
14
|
+
const prefix = sessionKeyOf(name, key, '');
|
|
12
15
|
const found = [];
|
|
13
16
|
for (const stored of (await claude.store.keys()).filter((each) => each.startsWith(prefix))) {
|
|
14
17
|
if ((await claude.store.get(stored)) === value)
|
|
@@ -32,7 +35,7 @@ export function createState({ name, initial, session, root, claude, report, chan
|
|
|
32
35
|
turn = Promise.allSettled([run]);
|
|
33
36
|
return run;
|
|
34
37
|
};
|
|
35
|
-
const ownersKey = (lifetime, key) =>
|
|
38
|
+
const ownersKey = (lifetime, key) => (lifetime === 'project' ? `${name}.${key}.projects.` : sessionKeyOf(name, key, ''));
|
|
36
39
|
const storeKey = (lifetime, key, owner) => (lifetime === 'global' ? `${name}.${key}` : `${ownersKey(lifetime, key)}${owner}`);
|
|
37
40
|
const read = (lifetime, key, owner) => claude.store.get(storeKey(lifetime, key, owner));
|
|
38
41
|
const write = async (lifetime, key, value, owner) => {
|
|
@@ -92,7 +95,7 @@ export function createState({ name, initial, session, root, claude, report, chan
|
|
|
92
95
|
if (lifetime !== 'memory') {
|
|
93
96
|
const owner = lifetime === 'project' ? projectRoot : sessionId;
|
|
94
97
|
inTurn(() => write(lifetime, key, value, owner)).catch((error) => {
|
|
95
|
-
report({ id: `state:${lifetime}.${key}`, message: `Could not keep state.${lifetime}.${key}
|
|
98
|
+
report({ id: `state:${lifetime}.${key}`, message: `Could not keep state.${lifetime}.${key}`, error });
|
|
96
99
|
});
|
|
97
100
|
}
|
|
98
101
|
changed();
|
package/runtime/toaster.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type Failure = {
|
|
|
14
14
|
readonly retry?: () => unknown;
|
|
15
15
|
readonly isCritical?: boolean;
|
|
16
16
|
};
|
|
17
|
+
export type LogLevel = 'error' | 'warning';
|
|
17
18
|
export type LoggedFailure = {
|
|
18
19
|
readonly mod: string;
|
|
19
20
|
readonly id: string;
|
|
@@ -23,12 +24,16 @@ export type LoggedFailure = {
|
|
|
23
24
|
readonly isCritical: boolean;
|
|
24
25
|
readonly root: string;
|
|
25
26
|
readonly contact?: Contact;
|
|
27
|
+
readonly level?: LogLevel;
|
|
28
|
+
readonly version?: string;
|
|
29
|
+
readonly core?: string;
|
|
26
30
|
};
|
|
27
31
|
export declare const failedMethod = "cmod:failed";
|
|
28
32
|
export type Toaster = {
|
|
29
33
|
readonly toast: Toast;
|
|
30
34
|
copy(text: string): Promise<void>;
|
|
31
35
|
fail(failure: Failure): ToastId;
|
|
36
|
+
warn(id: string, text: string): void;
|
|
32
37
|
readonly shown: readonly ShownToast[];
|
|
33
38
|
draw(drawn: RenderElement, table: ElementTable, band: RenderPropsOf['AbovePrompt'], bandId: string): RenderElement;
|
|
34
39
|
};
|
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;
|
|
1
|
+
{"version":3,"file":"toaster.d.ts","sourceRoot":"","sources":["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AAS,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAQhG"}
|
package/runtime/toaster.js
CHANGED
|
@@ -31,7 +31,7 @@ export function createToaster(claude, name, version) {
|
|
|
31
31
|
for (const [id, hides] of Object.entries(saved))
|
|
32
32
|
if (typeof hides === 'string' && !hidden.has(id))
|
|
33
33
|
hidden.set(id, hides);
|
|
34
|
-
}, (error) =>
|
|
34
|
+
}, (error) => warn('hidden:read', `${name}: could not read the failures you hid: ${messageOf(error)}`));
|
|
35
35
|
let lastId = 0;
|
|
36
36
|
let frame = 0;
|
|
37
37
|
let spinning;
|
|
@@ -111,7 +111,7 @@ export function createToaster(claude, name, version) {
|
|
|
111
111
|
if (entry.hides === undefined)
|
|
112
112
|
return;
|
|
113
113
|
hidden.set(String(entry.id), entry.hides);
|
|
114
|
-
void claude.store.set(hiddenKey, Object.fromEntries(hidden)).catch((error) =>
|
|
114
|
+
void claude.store.set(hiddenKey, Object.fromEntries(hidden)).catch((error) => warn('hidden:write', `${name}: could not remember the failure you hid: ${messageOf(error)}`));
|
|
115
115
|
};
|
|
116
116
|
const toast = Object.assign(show('default'), {
|
|
117
117
|
success: show('success'),
|
|
@@ -144,6 +144,26 @@ export function createToaster(claude, name, version) {
|
|
|
144
144
|
.then(run)
|
|
145
145
|
.catch((error) => fail({ id: `press:${entry.id}`, message: `${entry.message}: the press failed`, error, isCritical: true }));
|
|
146
146
|
const logFailure = (failure) => claude.cmod.call({ to: cmodPluginName, method: failedMethod, input: failure });
|
|
147
|
+
const modVersion = () => claude.fs
|
|
148
|
+
.read(`${claude.plugin.root}/.claude-plugin/plugin.json`)
|
|
149
|
+
.then((text) => String(JSON.parse(text).version))
|
|
150
|
+
.catch((failure) => `unknown (${messageOf(failure)})`);
|
|
151
|
+
const detailsOf = (version, at, text) => `${name} ${version}, @cmodjs/core ${coreVersion}, at ${at.toISOString()}\n${text}`;
|
|
152
|
+
const warned = new Map();
|
|
153
|
+
const warn = (id, text) => {
|
|
154
|
+
claude.ui.log(text, { to: 'debug' });
|
|
155
|
+
const at = new Date();
|
|
156
|
+
const repeat = `${text}\n${at.toISOString().slice(0, 16)}`;
|
|
157
|
+
if (warned.get(id) === repeat)
|
|
158
|
+
return;
|
|
159
|
+
warned.set(id, repeat);
|
|
160
|
+
claude.clock.after(0, () => {
|
|
161
|
+
void (async () => {
|
|
162
|
+
const version = await modVersion();
|
|
163
|
+
await logFailure({ mod: name, id, message: text, details: detailsOf(version, at, text), at: at.toISOString(), isCritical: false, root: claude.plugin.root, level: 'warning', version, core: coreVersion });
|
|
164
|
+
})().catch(() => undefined);
|
|
165
|
+
});
|
|
166
|
+
};
|
|
147
167
|
const showsToast = async (failure, isShown) => {
|
|
148
168
|
try {
|
|
149
169
|
const logged = logFailure(failure);
|
|
@@ -165,16 +185,11 @@ export function createToaster(claude, name, version) {
|
|
|
165
185
|
return id;
|
|
166
186
|
sent.set(id, repeat);
|
|
167
187
|
const stack = error instanceof Error && error.stack !== undefined ? `\n\n${error.stack}` : '';
|
|
168
|
-
const details = async (failedAt) => {
|
|
169
|
-
const modVersion = await claude.fs
|
|
170
|
-
.read(`${claude.plugin.root}/.claude-plugin/plugin.json`)
|
|
171
|
-
.then((text) => String(JSON.parse(text).version))
|
|
172
|
-
.catch((failure) => `unknown (${messageOf(failure)})`);
|
|
173
|
-
return `${name} ${modVersion}, @cmodjs/core ${coreVersion}, at ${failedAt.toISOString()}\n${message}${description === undefined ? '' : `\n${description}`}${stack}`;
|
|
174
|
-
};
|
|
188
|
+
const details = async (failedAt) => detailsOf(await modVersion(), failedAt, `${message}${description === undefined ? '' : `\n${description}`}${stack}`);
|
|
175
189
|
const logged = async () => {
|
|
176
190
|
const contact = await contactOf(claude);
|
|
177
|
-
const
|
|
191
|
+
const version = await modVersion();
|
|
192
|
+
const failure = { mod: name, id, message, details: detailsOf(version, at, `${message}${description === undefined ? '' : `\n${description}`}${stack}`), at: at.toISOString(), isCritical, root: claude.plugin.root, ...(contact === undefined ? {} : { contact }), level: 'error', version, core: coreVersion };
|
|
178
193
|
const shows = await showsToast(failure, isCritical);
|
|
179
194
|
if (isCritical)
|
|
180
195
|
return;
|
|
@@ -208,7 +223,7 @@ export function createToaster(claude, name, version) {
|
|
|
208
223
|
return;
|
|
209
224
|
const focused = await claude.ui.focus({ requestId: bandId, key: `toast:${id}:ask-claude` });
|
|
210
225
|
if ('deny' in focused)
|
|
211
|
-
|
|
226
|
+
warn('report:focus', `${name}: the Report choices did not take the keys: ${String(focused.deny)}`);
|
|
212
227
|
};
|
|
213
228
|
const tryAgain = async () => {
|
|
214
229
|
const shown = entries.get(id);
|
|
@@ -300,6 +315,7 @@ export function createToaster(claude, name, version) {
|
|
|
300
315
|
toast,
|
|
301
316
|
copy,
|
|
302
317
|
fail,
|
|
318
|
+
warn,
|
|
303
319
|
get shown() {
|
|
304
320
|
return [...entries.values()].map(({ type, message, options }) => ({ type, message, ...(typeof options.description === 'string' ? { description: options.description } : {}) }));
|
|
305
321
|
},
|
package/runtime/ui.d.ts
CHANGED
|
@@ -117,5 +117,6 @@ export type UiArea<State extends object> = {
|
|
|
117
117
|
changed(): void;
|
|
118
118
|
restorePanes(): Promise<void>;
|
|
119
119
|
};
|
|
120
|
+
export declare const keptDrawInputs = 200;
|
|
120
121
|
export declare function createUi<State extends object>({ name, claude, router, report, announce, mod, borrowed, nextDraw }: UiOptions<State>): UiArea<State>;
|
|
121
122
|
//# sourceMappingURL=ui.d.ts.map
|
package/runtime/ui.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui.d.ts","sourceRoot":"","sources":["../src/runtime/ui.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,EAAE,aAAa,EAAgB,aAAa,EAAE,MAAM,aAAa,CAAA;AACzG,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAE1C,OAAO,EAAW,KAAK,IAAI,EAAmC,KAAK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AAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,GAAG,SAAS,CAAA;IACxG,UAAU,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,EAAE,aAAa,KAAK,aAAa,CAAC,GAAG,SAAS,CAAA;IACpG,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,IAAI,CAAA;IAC1C,OAAO,IAAI,IAAI,CAAA;IACf,OAAO,IAAI,IAAI,CAAA;IACf,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CAC9B,CAAA;AAED,eAAO,MAAM,cAAc,MAAM,CAAA;AAEjC,wBAAgB,QAAQ,CAAC,KAAK,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAgjBnJ"}
|
package/runtime/ui.js
CHANGED
|
@@ -111,7 +111,7 @@ export function merged(updates) {
|
|
|
111
111
|
const isRedrawn = updates.some((update) => update.redraw === true);
|
|
112
112
|
return { ...(parts === undefined ? {} : { parts }), ...(isRedrawn ? { redraw: true } : {}), ...(requests.length === 0 ? {} : { requests }) };
|
|
113
113
|
}
|
|
114
|
-
const keptDrawInputs = 200;
|
|
114
|
+
export const keptDrawInputs = 200;
|
|
115
115
|
export function createUi({ name, claude, router, report, announce, mod, borrowed, nextDraw }) {
|
|
116
116
|
const panes = new Map();
|
|
117
117
|
const paneLogs = new Map();
|
|
@@ -131,7 +131,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
131
131
|
paneStates.set(id, { isShown: open.isShown, isFocused: open.isFocused });
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
|
-
const readPanes = () => syncPanes().catch((error) => claude.ui.
|
|
134
|
+
const readPanes = () => syncPanes().catch((error) => claude.ui.warn('panes:read', `${name} keeps its panes' open, shown, and focused state from before: ${messageOf(error)}`));
|
|
135
135
|
const requestedSizes = new Map();
|
|
136
136
|
const styles = new Set();
|
|
137
137
|
const markdownRenders = new Map();
|
|
@@ -185,7 +185,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
185
185
|
return true;
|
|
186
186
|
}
|
|
187
187
|
catch (error) {
|
|
188
|
-
claude.ui.
|
|
188
|
+
claude.ui.warn(`drawing:${key}`, `${name}: the ${key} drawing threw, so the cmod plugin asks for it again: ${messageOf(error)}`);
|
|
189
189
|
return true;
|
|
190
190
|
}
|
|
191
191
|
const latest = sent.draws.at(-1);
|
|
@@ -219,7 +219,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
219
219
|
unheldRequests += 1;
|
|
220
220
|
if (isObject(answer) && name !== cmodPluginName)
|
|
221
221
|
hear(answer['stylers'], false);
|
|
222
|
-
}, (error) => claude.ui.
|
|
222
|
+
}, (error) => claude.ui.warn('parts:tell', `${name}: the cmod plugin did not hear about its pages and widgets: ${messageOf(error)}`));
|
|
223
223
|
};
|
|
224
224
|
if (!isAsked)
|
|
225
225
|
return Promise.resolve().then(tell);
|
|
@@ -353,7 +353,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
353
353
|
await openAt(pane, size);
|
|
354
354
|
}
|
|
355
355
|
catch (error) {
|
|
356
|
-
claude.ui.
|
|
356
|
+
claude.ui.warn(`pane:resize:${pane.id}`, `${name}: the ${pane.title} pane kept its size: ${messageOf(error)}`);
|
|
357
357
|
}
|
|
358
358
|
};
|
|
359
359
|
const handle = async (pane, handler, run) => {
|
|
@@ -455,7 +455,7 @@ export function createUi({ name, claude, router, report, announce, mod, borrowed
|
|
|
455
455
|
panes.delete(init.id);
|
|
456
456
|
paneLogs.delete(init.id);
|
|
457
457
|
if (openPanes.has(init.id))
|
|
458
|
-
void claude.ui.close({ id: init.id }).catch((error) => claude.ui.
|
|
458
|
+
void claude.ui.close({ id: init.id }).catch((error) => claude.ui.warn(`pane:close:${init.id}`, `${name}: the ${init.title} pane stayed open: ${messageOf(error)}`));
|
|
459
459
|
openPanes.delete(init.id);
|
|
460
460
|
paneStates.delete(init.id);
|
|
461
461
|
},
|
package/runtime/widgets.js
CHANGED
|
@@ -122,7 +122,7 @@ export function serveWidgets({ claude, router, store, report, turnClosedBy, part
|
|
|
122
122
|
}
|
|
123
123
|
catch (error) {
|
|
124
124
|
declared.delete(mod);
|
|
125
|
-
claude.ui.
|
|
125
|
+
claude.ui.warn(`widgets:list:${mod}`, `cmod: ${mod} did not list its widgets: ${messageOf(error)}`);
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
128
|
const recheck = async () => {
|
package/src/jobs/program.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { Job } from '../mod.js'
|
|
2
|
+
import { instancePath, storeFolder } from '../records.js'
|
|
2
3
|
import { engineOf } from '../runtime/engine.js'
|
|
4
|
+
import { isHeld } from '../runtime/programs.js'
|
|
5
|
+
import { ifMissing } from '../utils/paths.js'
|
|
3
6
|
import { messageOf } from '../utils/text.js'
|
|
4
7
|
import { basename } from '../vendor.js'
|
|
5
8
|
|
|
@@ -12,10 +15,16 @@ type Address = Awaited<ReturnType<Program['ready']>>
|
|
|
12
15
|
|
|
13
16
|
const backoffSeconds = [1, 2, 4, 8, 16] as const
|
|
14
17
|
|
|
18
|
+
const leaseCheckMs = 5000
|
|
19
|
+
|
|
20
|
+
const staleMs = 15_000
|
|
21
|
+
|
|
22
|
+
const retryWithinMs = 1000
|
|
23
|
+
|
|
15
24
|
export function program(options: { readonly command: readonly string[]; readonly environment?: Record<string, string>; readonly singleInstance?: boolean }): Job<Program> {
|
|
16
25
|
const { command, environment, singleInstance = false } = options
|
|
17
26
|
return ({ mod, announce, reserveName }) => {
|
|
18
|
-
const { claude, report, spawnCmod } = engineOf(mod)
|
|
27
|
+
const { claude, report, spawnCmod, watches } = engineOf(mod)
|
|
19
28
|
const [executable] = command
|
|
20
29
|
if (executable === undefined) throw new Error(`${mod.name}: the program has no command. Name the program on PATH and its arguments, such as ['preview-server', '--port', '0'].`)
|
|
21
30
|
if (singleInstance) reserveName('program', basename(executable), `${mod.name}: the single instance of ${executable} is already added. Give each singleInstance program its own executable.`)
|
|
@@ -25,8 +34,17 @@ export function program(options: { readonly command: readonly string[]; readonly
|
|
|
25
34
|
let failure: Error | undefined
|
|
26
35
|
let exits = 0
|
|
27
36
|
const waiting: { resolve: (address: Address) => void; reject: (error: Error) => void }[] = []
|
|
37
|
+
let isFollowing = false
|
|
38
|
+
let isWatching = false
|
|
39
|
+
let instance: Promise<string> | undefined
|
|
40
|
+
let leaseCheck: Promise<void> | undefined
|
|
41
|
+
|
|
42
|
+
const spawn = () => (singleInstance ? spawnCmod(['program', mod.name, '--no-wait', '--', ...command], environment) : claude.process.spawn(request))
|
|
28
43
|
|
|
29
|
-
const
|
|
44
|
+
const instanceFile = () =>
|
|
45
|
+
(instance ??= Promise.all([claude.env.home(), claude.env.dataHome()]).then(([home, dataHome]) => instancePath(storeFolder({ HOME: home, XDG_DATA_HOME: dataHome }), mod.name, basename(executable))))
|
|
46
|
+
|
|
47
|
+
const following = (run: Promise<unknown>) => void run.catch((error: unknown) => report({ id: `program:${executable}:follow`, message: `Could not follow the ${executable} program`, error }))
|
|
30
48
|
|
|
31
49
|
const stop = (reason: string) => {
|
|
32
50
|
address = undefined
|
|
@@ -48,26 +66,64 @@ export function program(options: { readonly command: readonly string[]; readonly
|
|
|
48
66
|
for (const waiter of waiting.splice(0)) waiter.resolve(next)
|
|
49
67
|
}
|
|
50
68
|
|
|
69
|
+
const checkLease = (file: string) =>
|
|
70
|
+
(leaseCheck ??= (async () => {
|
|
71
|
+
if (!isFollowing || (await isHeld(claude, `${file}.lock`, staleMs))) return
|
|
72
|
+
isFollowing = false
|
|
73
|
+
void start()
|
|
74
|
+
})().finally(() => {
|
|
75
|
+
leaseCheck = undefined
|
|
76
|
+
}))
|
|
77
|
+
|
|
78
|
+
const track = async (file: string) => {
|
|
79
|
+
if (!isFollowing) return
|
|
80
|
+
const recorded = await claude.fs.read(file).catch(ifMissing(undefined))
|
|
81
|
+
const next = recorded === undefined ? undefined : addressOf(String((JSON.parse(recorded) as { readonly address?: unknown }).address).trim())
|
|
82
|
+
if (next !== undefined) return show(next)
|
|
83
|
+
address = undefined
|
|
84
|
+
state = 'starting'
|
|
85
|
+
claude.clock.after(Math.random() * retryWithinMs, () => following(checkLease(file)))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const follow = async (file: string) => {
|
|
89
|
+
isFollowing = true
|
|
90
|
+
if (!isWatching) {
|
|
91
|
+
isWatching = true
|
|
92
|
+
watches.add([file], () => following(track(file)))
|
|
93
|
+
claude.clock.every(leaseCheckMs, () => following(checkLease(file)))
|
|
94
|
+
}
|
|
95
|
+
await track(file)
|
|
96
|
+
}
|
|
97
|
+
|
|
51
98
|
const start = async () => {
|
|
99
|
+
isFollowing = false
|
|
100
|
+
address = undefined
|
|
52
101
|
state = 'starting'
|
|
53
102
|
let pending = ''
|
|
54
103
|
let lastError = ''
|
|
104
|
+
let isShown = false
|
|
55
105
|
try {
|
|
106
|
+
if (singleInstance) {
|
|
107
|
+
const file = await instanceFile()
|
|
108
|
+
if (await isHeld(claude, `${file}.lock`, staleMs)) return await follow(file)
|
|
109
|
+
}
|
|
56
110
|
for await (const piece of await spawn()) {
|
|
57
111
|
if (piece.stream === 'stderr') {
|
|
58
112
|
lastError = piece.text.trim().split('\n').at(-1) ?? lastError
|
|
59
113
|
continue
|
|
60
114
|
}
|
|
61
|
-
if (
|
|
115
|
+
if (isShown) continue
|
|
62
116
|
const lines = `${pending}${piece.text}`.split('\n')
|
|
63
117
|
pending = lines.pop() ?? ''
|
|
64
|
-
for (const line of
|
|
118
|
+
for (const line of lines.slice(0, 1)) {
|
|
119
|
+
if (singleInstance && line.trim() === 'held') return await follow(await instanceFile())
|
|
65
120
|
const next = addressOf(line.trim())
|
|
66
121
|
if (next === undefined) {
|
|
67
122
|
stop(`its first line is "${line.trim()}". Write 127.0.0.1:<port> or unix:<socket path> as the first line on standard output.`)
|
|
68
123
|
return
|
|
69
124
|
}
|
|
70
125
|
show(next)
|
|
126
|
+
isShown = true
|
|
71
127
|
}
|
|
72
128
|
}
|
|
73
129
|
} catch (error) {
|
package/src/mod.ts
CHANGED
|
@@ -140,6 +140,7 @@ export type Imports = {
|
|
|
140
140
|
readonly http: { fetch(url: string, init?: HttpInit): Promise<HttpResponse> }
|
|
141
141
|
readonly device: { read(): Promise<Device> }
|
|
142
142
|
readonly clipboard: { write(text: string): Promise<void> }
|
|
143
|
+
readonly mods: { isLoaded(name: string): Promise<boolean> }
|
|
143
144
|
}
|
|
144
145
|
|
|
145
146
|
export const sessions: Imports['sessions'] = {
|
|
@@ -205,6 +206,10 @@ export const clipboard: Imports['clipboard'] = {
|
|
|
205
206
|
write: (text) => bound().clipboard.write(text),
|
|
206
207
|
}
|
|
207
208
|
|
|
209
|
+
export const mods: Imports['mods'] = {
|
|
210
|
+
isLoaded: (name) => bound().mods.isLoaded(name),
|
|
211
|
+
}
|
|
212
|
+
|
|
208
213
|
export type Mod<State extends object = Record<never, never>, Declared extends Options = Options, Keys extends Hotkeys = Hotkeys> = {
|
|
209
214
|
readonly name: string
|
|
210
215
|
readonly folder: string
|
package/src/options.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { isObject, secretFix } from './records.js'
|
|
2
|
+
import { messageOf } from './utils/text.js'
|
|
3
|
+
|
|
1
4
|
export type OptionType = 'text' | 'secret' | 'number' | 'toggle' | 'choice' | 'folder' | 'file' | 'list'
|
|
2
5
|
|
|
3
6
|
export type OptionValue = string | number | boolean | readonly string[]
|
|
@@ -71,6 +74,54 @@ export function userConfigOf(options: Options): Record<string, UserConfigField>
|
|
|
71
74
|
)
|
|
72
75
|
}
|
|
73
76
|
|
|
77
|
+
const optionTypes: Readonly<Record<UserConfigField['type'], OptionType>> = { string: 'text', number: 'number', boolean: 'toggle', directory: 'folder', file: 'file' }
|
|
78
|
+
|
|
79
|
+
export function optionsOf(userConfig: Readonly<Record<string, unknown>>): Options {
|
|
80
|
+
return Object.fromEntries(
|
|
81
|
+
Object.entries(userConfig).flatMap(([key, field]): [string, Option][] => {
|
|
82
|
+
if (!isObject(field) || typeof field['type'] !== 'string' || !Object.hasOwn(optionTypes, field['type'])) return []
|
|
83
|
+
const choices = Array.isArray(field['options']) ? field['options'].filter((choice): choice is string => typeof choice === 'string') : undefined
|
|
84
|
+
const type: OptionType = field['sensitive'] === true ? 'secret' : field['multiple'] === true ? 'list' : choices !== undefined ? 'choice' : optionTypes[field['type'] as UserConfigField['type']]
|
|
85
|
+
return [
|
|
86
|
+
[
|
|
87
|
+
key,
|
|
88
|
+
{
|
|
89
|
+
type,
|
|
90
|
+
title: typeof field['title'] === 'string' ? field['title'] : key,
|
|
91
|
+
description: typeof field['description'] === 'string' ? field['description'] : '',
|
|
92
|
+
...(typeof field['min'] === 'number' ? { min: field['min'] } : {}),
|
|
93
|
+
...(typeof field['max'] === 'number' ? { max: field['max'] } : {}),
|
|
94
|
+
...(choices === undefined ? {} : { choices }),
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
]
|
|
98
|
+
}),
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function projectOptionsOf(name: string, declared: Options, text: string): { readonly values: Record<string, unknown>; readonly ignored: readonly string[] } {
|
|
103
|
+
let file: unknown
|
|
104
|
+
try {
|
|
105
|
+
file = JSON.parse(text)
|
|
106
|
+
} catch (error) {
|
|
107
|
+
return { values: {}, ignored: [`is not JSON (${messageOf(error)}). Fix the file; ${name} uses its other options until then.`] }
|
|
108
|
+
}
|
|
109
|
+
if (!isObject(file)) return { values: {}, ignored: ['is not a JSON object. Write one, such as { "branch": "main" }.'] }
|
|
110
|
+
const values: Record<string, unknown> = {}
|
|
111
|
+
const ignored: string[] = []
|
|
112
|
+
for (const [key, value] of Object.entries(file)) {
|
|
113
|
+
const option = declared[key]
|
|
114
|
+
if (option === undefined) ignored.push(`sets ${key}, which ${name} does not declare. ${Object.keys(declared).length === 0 ? 'Remove it.' : `Remove it, or use one of: ${Object.keys(declared).join(', ')}.`}`)
|
|
115
|
+
else if (option.type === 'secret') ignored.push(`sets ${key}, a secret, and a project file is committed for everyone to read. Remove it. ${secretFix}`)
|
|
116
|
+
else {
|
|
117
|
+
const misfit = fitsOption(option, value)
|
|
118
|
+
if (misfit === undefined) values[key] = value
|
|
119
|
+
else ignored.push(`sets ${key} to ${JSON.stringify(value)}, and ${option.title} ${misfit}.`)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return { values, ignored }
|
|
123
|
+
}
|
|
124
|
+
|
|
74
125
|
export function isUnset(value: unknown): boolean {
|
|
75
126
|
return value === undefined || value === '' || (Array.isArray(value) && value.length === 0)
|
|
76
127
|
}
|
package/src/records.ts
CHANGED
|
@@ -307,9 +307,9 @@ function readHotkeys(hotkeys: unknown): Steps {
|
|
|
307
307
|
return { hotkeys: checkHotkeys('package.json "cmod"', hotkeys as Record<string, HotkeyInit>) }
|
|
308
308
|
}
|
|
309
309
|
|
|
310
|
-
export const coreVersion = '5.
|
|
310
|
+
export const coreVersion = '5.4.0'
|
|
311
311
|
|
|
312
|
-
export const oldestCmodVersion = '5.
|
|
312
|
+
export const oldestCmodVersion = '5.4.0'
|
|
313
313
|
|
|
314
314
|
export function hotkeyCommand(mod: string, hotkey: string): string {
|
|
315
315
|
return `${mod}--${hotkey}`
|