@cmodjs/core 6.3.0 → 8.0.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 +123 -65
- package/docs/dependencies.md +189 -4
- package/docs/index.md +56 -12
- package/docs/install-steps.md +20 -17
- package/docs/jobs.md +43 -16
- package/docs/mod.md +43 -27
- package/docs/options.md +2 -2
- package/docs/session.md +58 -32
- package/docs/testing.md +88 -24
- package/docs/ui.md +128 -58
- package/installer.d.ts +2 -2
- package/jobs/context.js +1 -1
- package/jobs/program.d.ts +4 -1
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +79 -20
- package/mod.d.ts +59 -9
- package/mod.d.ts.map +1 -1
- package/mod.js +5 -3
- package/package.json +1 -1
- package/records.d.ts +15 -2
- package/records.d.ts.map +1 -1
- package/records.js +24 -10
- package/register.d.ts.map +1 -1
- package/register.js +7 -4
- package/rpc.d.ts +7 -0
- package/rpc.d.ts.map +1 -0
- package/rpc.js +59 -0
- package/runtime/bound.d.ts +1 -0
- package/runtime/bound.d.ts.map +1 -1
- package/runtime/bound.js +10 -0
- package/runtime/bun.d.ts +20 -0
- package/runtime/bun.d.ts.map +1 -0
- package/runtime/bun.js +20 -0
- package/runtime/claude.d.ts +1 -0
- package/runtime/claude.d.ts.map +1 -1
- package/runtime/conversations.d.ts +12 -1
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +472 -362
- package/runtime/deadline.d.ts +4 -3
- package/runtime/deadline.d.ts.map +1 -1
- package/runtime/deadline.js +10 -4
- package/runtime/engine.d.ts +5 -4
- package/runtime/engine.d.ts.map +1 -1
- package/runtime/installer.d.ts +3 -3
- package/runtime/installer.d.ts.map +1 -1
- package/runtime/installer.js +10 -9
- package/runtime/interfaces.d.ts +262 -0
- package/runtime/interfaces.d.ts.map +1 -0
- package/runtime/interfaces.js +935 -0
- package/runtime/lifecycle.d.ts +3 -3
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +83 -52
- package/runtime/options.d.ts.map +1 -1
- package/runtime/options.js +2 -6
- package/runtime/parts.d.ts +64 -1
- package/runtime/parts.d.ts.map +1 -1
- package/runtime/parts.js +311 -4
- package/runtime/programs.d.ts +1 -0
- package/runtime/programs.d.ts.map +1 -1
- package/runtime/programs.js +5 -3
- package/runtime/rpc.d.ts +111 -0
- package/runtime/rpc.d.ts.map +1 -0
- package/runtime/rpc.js +387 -0
- package/runtime/sessions.d.ts +6 -4
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +59 -80
- package/runtime/toaster.js +1 -1
- package/runtime/ui.d.ts +23 -10
- package/runtime/ui.d.ts.map +1 -1
- package/runtime/ui.js +63 -52
- package/runtime/web.d.ts +0 -73
- package/runtime/web.d.ts.map +1 -1
- package/runtime/web.js +9 -5
- package/runtime/widgets.d.ts +4 -2
- package/runtime/widgets.d.ts.map +1 -1
- package/runtime/widgets.js +17 -16
- package/session/conversation.d.ts +7 -1
- package/session/conversation.d.ts.map +1 -1
- package/session/session.d.ts +31 -7
- package/session/session.d.ts.map +1 -1
- package/session/session.js +1 -0
- package/src/installer.ts +2 -2
- package/src/jobs/context.ts +1 -1
- package/src/jobs/program.ts +76 -21
- package/src/mod.ts +51 -10
- package/src/records.ts +33 -9
- package/src/register.ts +7 -4
- package/src/rpc.ts +67 -0
- package/src/runtime/bound.ts +10 -0
- package/src/runtime/bun.ts +40 -0
- package/src/runtime/claude.ts +1 -0
- package/src/runtime/conversations.ts +470 -352
- package/src/runtime/deadline.ts +13 -6
- package/src/runtime/engine.ts +5 -4
- package/src/runtime/installer.ts +13 -12
- package/src/runtime/interfaces.ts +1161 -0
- package/src/runtime/lifecycle.ts +102 -59
- package/src/runtime/options.ts +2 -5
- package/src/runtime/parts.ts +364 -5
- package/src/runtime/programs.ts +6 -3
- package/src/runtime/rpc.ts +457 -0
- package/src/runtime/sessions.ts +63 -83
- package/src/runtime/toaster.ts +1 -1
- package/src/runtime/ui.ts +82 -61
- package/src/runtime/web.ts +10 -39
- package/src/runtime/widgets.ts +20 -18
- package/src/session/conversation.ts +7 -1
- package/src/session/session.ts +22 -7
- package/src/testing/fake-claude.ts +38 -7
- package/src/testing/fake-serve.ts +144 -0
- package/src/testing/fake-sessions.ts +21 -6
- package/src/testing.ts +156 -68
- package/src/ui/areas.ts +2 -2
- package/src/ui/elements.ts +21 -16
- package/src/ui/panes.ts +14 -7
- package/testing/fake-claude.d.ts +6 -0
- package/testing/fake-claude.d.ts.map +1 -1
- package/testing/fake-claude.js +34 -7
- package/testing/fake-serve.d.ts +39 -0
- package/testing/fake-serve.d.ts.map +1 -0
- package/testing/fake-serve.js +110 -0
- package/testing/fake-sessions.d.ts.map +1 -1
- package/testing/fake-sessions.js +22 -6
- package/testing.d.ts +21 -4
- package/testing.d.ts.map +1 -1
- package/testing.js +138 -56
- package/ui/areas.d.ts +3 -1
- package/ui/areas.d.ts.map +1 -1
- package/ui/elements.d.ts +18 -9
- package/ui/elements.d.ts.map +1 -1
- package/ui/elements.js +9 -8
- package/ui/panes.d.ts +10 -6
- package/ui/panes.d.ts.map +1 -1
- package/ui/panes.js +5 -3
- package/runtime/pages.d.ts +0 -32
- package/runtime/pages.d.ts.map +0 -1
- package/runtime/pages.js +0 -142
- package/src/runtime/pages.ts +0 -183
package/src/runtime/deadline.ts
CHANGED
|
@@ -7,6 +7,8 @@ export const longestMs = 600_000
|
|
|
7
7
|
|
|
8
8
|
export const toolDeadline: Deadline = { ms: 30000, job: 'tool' }
|
|
9
9
|
|
|
10
|
+
export const callDeadline: Deadline = { ms: 30_000 }
|
|
11
|
+
|
|
10
12
|
export type ListenOptions = { readonly timeoutMs?: number; readonly onFailure?: 'pass' | 'refuse' }
|
|
11
13
|
|
|
12
14
|
export type ListenTime = { readonly deadline: number; readonly signal: AbortSignal }
|
|
@@ -19,9 +21,9 @@ export class PassedTimeout extends Error {}
|
|
|
19
21
|
|
|
20
22
|
const timers = globalThis as unknown as { setTimeout(run: () => void, ms: number): unknown; clearTimeout(timer: unknown): void }
|
|
21
23
|
|
|
22
|
-
export function listenerOf(name: string, method: string, args: readonly unknown[]): { readonly matcher: unknown; readonly listener:
|
|
24
|
+
export function listenerOf<Listener = (payload: never, time: ListenTime) => unknown>(name: string, method: string, args: readonly unknown[]): { readonly matcher: unknown; readonly listener: Listener; readonly options: ListenOptions } {
|
|
23
25
|
const hasMatcher = typeof args[1] === 'function'
|
|
24
|
-
const listener = (hasMatcher ? args[1] : args[0]) as
|
|
26
|
+
const listener = (hasMatcher ? args[1] : args[0]) as Listener
|
|
25
27
|
const options = ((hasMatcher ? args[2] : args[1]) ?? {}) as ListenOptions
|
|
26
28
|
if (typeof listener !== 'function') throw new Error(`${name}: ${method} takes a listener, or a matcher and then a listener.`)
|
|
27
29
|
const { timeoutMs, onFailure } = options as { readonly timeoutMs?: unknown; readonly onFailure?: unknown }
|
|
@@ -68,11 +70,16 @@ export function settledAfterAbort<Value>(work: Promise<Value>, signal: AbortSign
|
|
|
68
70
|
})
|
|
69
71
|
}
|
|
70
72
|
|
|
71
|
-
export function beforeDeadline<Value>(
|
|
73
|
+
export function beforeDeadline<Value>(clock: Pick<Claude['clock'], 'after'>, { ms, job }: Deadline, call: string, run: (signal: AbortSignal) => Promise<Value>): Promise<Value> {
|
|
74
|
+
const passed = new AbortController()
|
|
72
75
|
return new Promise<Value>((resolve, reject) => {
|
|
73
|
-
const
|
|
74
|
-
const timer =
|
|
75
|
-
|
|
76
|
+
const deadline = job === undefined ? `its ${ms / 1000} s deadline` : `the ${ms / 1000} s deadline of ${job}`
|
|
77
|
+
const timer = clock.after(ms, () => {
|
|
78
|
+
const error = new Error(`${call} passed ${deadline}`)
|
|
79
|
+
reject(error)
|
|
80
|
+
passed.abort(error)
|
|
81
|
+
})
|
|
82
|
+
run(passed.signal).then(
|
|
76
83
|
(value) => {
|
|
77
84
|
timer.cancel()
|
|
78
85
|
resolve(value)
|
package/src/runtime/engine.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { HookStream, ProcessSpawnChunk, ProcessSpawnResult } from 'claude-code'
|
|
2
2
|
import type { Claude } from './claude.js'
|
|
3
|
-
import type {
|
|
3
|
+
import type { Providers } from './interfaces.js'
|
|
4
|
+
import type { Parts } from './parts.js'
|
|
4
5
|
import type { Router } from './router.js'
|
|
5
|
-
import type { Subscription } from '../utils/subscription.js'
|
|
6
6
|
import type { Failure } from './toaster.js'
|
|
7
7
|
import type { ToolCalls } from './tool-calls.js'
|
|
8
8
|
import type { Watches } from './watches.js'
|
|
@@ -18,9 +18,10 @@ export type Engine = {
|
|
|
18
18
|
readonly spawnCmod: (args: readonly string[], env?: Readonly<Record<string, string>>) => HookStream<ProcessSpawnChunk, ProcessSpawnResult>
|
|
19
19
|
readonly isInstalledCopy: () => Promise<boolean>
|
|
20
20
|
readonly watches: Watches
|
|
21
|
-
readonly
|
|
21
|
+
readonly interfaces: Providers
|
|
22
22
|
readonly widgets?: Widgets
|
|
23
|
-
readonly
|
|
23
|
+
readonly parts?: Parts
|
|
24
|
+
readonly onServeUnreached: (listener: () => void) => void
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
const engines = new WeakMap<object, Engine>()
|
package/src/runtime/installer.ts
CHANGED
|
@@ -5,22 +5,22 @@ import type { Option } from '../options.js'
|
|
|
5
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
|
-
import type {
|
|
8
|
+
import type { ViewProps } from '../ui/panes.js'
|
|
9
9
|
import { messageOf } from '../utils/text.js'
|
|
10
10
|
import type { Claude } from './claude.js'
|
|
11
11
|
import { cmodPluginName, withBareRefusals } from './dependencies.js'
|
|
12
|
-
import { merged, partMethods, stalePress, type DrawnPart, type PartPress, type PartsUpdate, type
|
|
12
|
+
import { merged, partMethods, stalePress, type DrawnPart, type PartPress, type PartsUpdate, type ShownParts } from './ui.js'
|
|
13
13
|
|
|
14
|
-
export const
|
|
14
|
+
export const installView = 'cmod:install'
|
|
15
15
|
|
|
16
16
|
type Question = {
|
|
17
|
-
draw(props:
|
|
17
|
+
draw(props: ViewProps<undefined>): RenderElement
|
|
18
18
|
cancel(): void
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
export type Installer = {
|
|
22
22
|
answer(method: string, input: unknown): Promise<{ readonly value: unknown }> | undefined
|
|
23
|
-
hear(shown:
|
|
23
|
+
hear(shown: ShownParts): void
|
|
24
24
|
options(missing: readonly (readonly [string, Option])[], save: (key: string, value: string) => Promise<string | undefined>): Promise<boolean>
|
|
25
25
|
step<State extends object>(mod: Mod<State>, step: Step<State>, index: number, total: number): Promise<boolean>
|
|
26
26
|
close(): Promise<void>
|
|
@@ -46,7 +46,7 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
|
|
|
46
46
|
|
|
47
47
|
const log = (what: string) => (error: unknown) => claude().ui.warn('installer:page', `${name}: ${what}: ${messageOf(error)}`)
|
|
48
48
|
|
|
49
|
-
const open = (isAsked: boolean) => send({ requests: [{ open:
|
|
49
|
+
const open = (isAsked: boolean) => send({ requests: [{ open: installView, focus: true }], ...(isAsked ? { isAsked: true } : {}) })
|
|
50
50
|
|
|
51
51
|
const show = async <Answer>(next: string, build: (answer: (value: Answer) => void) => Omit<Question, 'cancel'>, cancelled: Answer): Promise<Answer> => {
|
|
52
52
|
question?.cancel()
|
|
@@ -82,10 +82,10 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
|
|
|
82
82
|
|
|
83
83
|
const dialog = (title: RenderElement, ...children: readonly RenderElement[]) => Box({ flexDirection: 'column', gap: 1, children: [title, ...children] })
|
|
84
84
|
|
|
85
|
-
const draw = (
|
|
86
|
-
if (question === undefined && !isOpen) claude().clock.after(0, () => void send({ requests: [{ close:
|
|
85
|
+
const draw = (props: ViewProps<undefined>): DrawnPart => {
|
|
86
|
+
if (question === undefined && !isOpen) claude().clock.after(0, () => void send({ requests: [{ close: installView }] }).catch(log('a leftover install view stayed open')))
|
|
87
87
|
const handlers: Handler[] = []
|
|
88
|
-
const tree = elementData(question?.draw(
|
|
88
|
+
const tree = elementData(question?.draw(props) ?? Text({ dimColor: true, children: `${name} needs nothing from you now.` }), (run) => handlers.push(run) - 1)
|
|
89
89
|
const drawn = nextDraw()
|
|
90
90
|
draws.set(drawn, handlers)
|
|
91
91
|
for (const kept of draws.keys()) if (draws.size > keptDraws) draws.delete(kept)
|
|
@@ -112,12 +112,13 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
|
|
|
112
112
|
|
|
113
113
|
return {
|
|
114
114
|
answer(method, input) {
|
|
115
|
-
|
|
115
|
+
const { page, ...props } = (isObject(input) ? input : {}) as Readonly<Record<string, unknown>>
|
|
116
|
+
if (method === partMethods.draw && page === installView) return Promise.resolve({ value: draw({ ...(props as ViewProps<unknown>), params: undefined }) })
|
|
116
117
|
if (method === partMethods.press && isObject(input) && typeof input['draw'] === 'number' && draws.has(input['draw'])) return press(input as PartPress).then((value) => ({ value }))
|
|
117
118
|
return undefined
|
|
118
119
|
},
|
|
119
120
|
hear(shown) {
|
|
120
|
-
if (shown.open.some((each) => each.id ===
|
|
121
|
+
if (shown.open.some((each) => each.id === installView)) {
|
|
121
122
|
isSeen = isOpen
|
|
122
123
|
return
|
|
123
124
|
}
|
|
@@ -206,7 +207,7 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
|
|
|
206
207
|
if (!isOpen) return
|
|
207
208
|
isOpen = false
|
|
208
209
|
isSeen = false
|
|
209
|
-
await send({ requests: [{ close:
|
|
210
|
+
await send({ requests: [{ close: installView }] }).catch(log('the install view stayed open'))
|
|
210
211
|
},
|
|
211
212
|
changed() {
|
|
212
213
|
if (question !== undefined && isOpen) redraw()
|