@cmodjs/core 4.3.3 → 5.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.
Files changed (64) hide show
  1. package/README.md +1 -1
  2. package/docs/commands.md +20 -31
  3. package/docs/dependencies.md +7 -5
  4. package/docs/index.md +4 -5
  5. package/docs/install-steps.md +12 -14
  6. package/docs/jobs.md +3 -11
  7. package/docs/mod.md +18 -21
  8. package/docs/session.md +11 -11
  9. package/docs/state.md +1 -1
  10. package/docs/testing.md +3 -5
  11. package/docs/ui.md +4 -4
  12. package/jobs/program.d.ts.map +1 -1
  13. package/jobs/program.js +3 -17
  14. package/mod.d.ts +0 -16
  15. package/mod.d.ts.map +1 -1
  16. package/package.json +1 -1
  17. package/records.d.ts +4 -11
  18. package/records.d.ts.map +1 -1
  19. package/records.js +17 -48
  20. package/runtime/announce.d.ts +1 -1
  21. package/runtime/announce.d.ts.map +1 -1
  22. package/runtime/announce.js +2 -3
  23. package/runtime/conversations.d.ts.map +1 -1
  24. package/runtime/conversations.js +3 -46
  25. package/runtime/engine.d.ts +2 -2
  26. package/runtime/engine.d.ts.map +1 -1
  27. package/runtime/installer.d.ts +0 -9
  28. package/runtime/installer.d.ts.map +1 -1
  29. package/runtime/installer.js +1 -15
  30. package/runtime/lifecycle.d.ts +1 -2
  31. package/runtime/lifecycle.d.ts.map +1 -1
  32. package/runtime/lifecycle.js +37 -191
  33. package/runtime/metadata.d.ts +1 -2
  34. package/runtime/metadata.d.ts.map +1 -1
  35. package/runtime/metadata.js +1 -2
  36. package/runtime/sessions.d.ts +3 -7
  37. package/runtime/sessions.d.ts.map +1 -1
  38. package/runtime/sessions.js +10 -34
  39. package/runtime/toaster.d.ts.map +1 -1
  40. package/runtime/toaster.js +6 -9
  41. package/runtime/ui.d.ts +1 -0
  42. package/runtime/ui.d.ts.map +1 -1
  43. package/runtime/ui.js +31 -12
  44. package/src/jobs/program.ts +3 -17
  45. package/src/mod.ts +0 -18
  46. package/src/records.ts +20 -55
  47. package/src/runtime/announce.ts +2 -3
  48. package/src/runtime/conversations.ts +3 -45
  49. package/src/runtime/engine.ts +2 -2
  50. package/src/runtime/installer.ts +1 -37
  51. package/src/runtime/lifecycle.ts +38 -188
  52. package/src/runtime/metadata.ts +0 -3
  53. package/src/runtime/sessions.ts +10 -39
  54. package/src/runtime/toaster.ts +6 -9
  55. package/src/runtime/ui.ts +32 -13
  56. package/src/testing.ts +11 -16
  57. package/testing.d.ts +0 -1
  58. package/testing.d.ts.map +1 -1
  59. package/testing.js +11 -15
  60. package/docs/permissions.md +0 -97
  61. package/runtime/grants.d.ts +0 -34
  62. package/runtime/grants.d.ts.map +0 -1
  63. package/runtime/grants.js +0 -326
  64. package/src/runtime/grants.ts +0 -348
@@ -1,5 +1,5 @@
1
1
  import type { Args, EventResult, Frozen } from 'claude-code'
2
- import { consentPath, coreVersion, dataFolder, isObject, parseConsent, readRecord, readSteps } from '../records.js'
2
+ import { coreVersion, dataFolder, isObject } from '../records.js'
3
3
  import { Message, rowOfAppend, type Row } from '../session/context/turn/message/message.js'
4
4
  import { modNote, Note } from '../session/context/turn/message/note.js'
5
5
  import { Person } from '../session/context/turn/message/sender.js'
@@ -15,11 +15,10 @@ import { formatExit, messageOf } from '../utils/text.js'
15
15
  import { beforeAnswerKeys, foldBefore, installBefore, relayOf, type Decide, type Place } from './before.js'
16
16
  import type { Claude } from './claude.js'
17
17
  import { cmodPluginName } from './dependencies.js'
18
- import { conversationCalls, refusal } from './grants.js'
19
18
  import { readLines, runCmod, spawnCmod } from './programs.js'
20
19
  import type { RoutedHook, Router } from './router.js'
21
20
  import { PassedTimeout } from './deadline.js'
22
- import { actPermission, conversationMethods, everySession, isAct, isHeardBy, isInScope, pickedColor, resultOf, spawnTask, usageOf, type Act, type Listened, type SessionColor } from './sessions.js'
21
+ import { conversationMethods, everySession, isAct, isHeardBy, isInScope, pickedColor, resultOf, spawnTask, usageOf, type Act, type Listened, type SessionColor } from './sessions.js'
23
22
 
24
23
  type Request = Readonly<Record<string, unknown>>
25
24
 
@@ -130,35 +129,6 @@ export function serveConversations({
130
129
 
131
130
  const json = async <Value>(args: readonly string[]): Promise<Value> => JSON.parse(await runCmod(claude, [...args, '--json', '--project', project()], await claude.session.id())) as Value
132
131
 
133
- const isGranted = async (caller: string | undefined, item: string) => {
134
- if (caller === cmodPluginName) return true
135
- if (caller === undefined) return false
136
- const path = consentPath(store)
137
- const text = await claude.fs.read(path).catch(ifMissing('{}'))
138
- return (parseConsent(JSON.parse(text), path)[caller] ?? []).includes(item)
139
- }
140
-
141
- const declaredBy = async (caller: string): Promise<readonly string[] | undefined> => {
142
- const read = (path: string) => claude.fs.read(path).catch(ifMissing(undefined))
143
- const record = await readRecord(read, store, caller)
144
- if (record === undefined) return undefined
145
- if (record.permissions !== null) return record.permissions
146
- const pkg = await read(`${record.root}/package.json`)
147
- return pkg === undefined ? undefined : (readSteps(JSON.parse(pkg))?.permissions ?? [])
148
- }
149
-
150
- const refused = async (caller: string | undefined, call: string, item: string) => {
151
- const declared =
152
- caller === undefined
153
- ? undefined
154
- : await declaredBy(caller).catch((error: unknown) => {
155
- claude.ui.log(`cmod: its refusal of ${caller} names the grant, because the permissions ${caller} declares are unreadable: ${messageOf(error)}`, { to: 'debug' })
156
- return undefined
157
- })
158
- return refusal({ name: caller ?? 'A mod', declared: declared ?? [item], home: undefined }, call, item)
159
- }
160
-
161
-
162
132
  const ended = (id: string) => new Error(`session ${id} has ended`)
163
133
 
164
134
  const isRunning = async (id: string) => (await json<SessionData[]>(['history', 'sessions', '--running', '--all'])).some((each) => each.id === id)
@@ -358,10 +328,7 @@ export function serveConversations({
358
328
  return [...new Map(all.filter((watcher) => watcher.events.includes(event)).map((watcher) => [`${watcher.from}\n${watcher.mod}`, watcher])).values()]
359
329
  }
360
330
 
361
- const askHere = async (mod: string, event: BeforeEvent, change: SessionChange, from = session, isInProject = true) => {
362
- if (from !== session && !(await isGranted(mod, 'conversation'))) throw new Error(await refused(mod, 'before', 'conversation'))
363
- return claude.cmod.call({ to: mod, method: conversationMethods.before, input: { session: from, event, change, isInProject } })
364
- }
331
+ const askHere = async (mod: string, event: BeforeEvent, change: SessionChange, from = session, isInProject = true) => claude.cmod.call({ to: mod, method: conversationMethods.before, input: { session: from, event, change, isInProject } })
365
332
 
366
333
  const isUnderHere = (task: string, ancestor: string) => {
367
334
  for (let at: string | undefined = task, steps = 0; at !== undefined && steps < 64; at = conversation.state.tasks[at]?.parent, steps += 1) if (at === ancestor) return true
@@ -561,13 +528,7 @@ export function serveConversations({
561
528
  return answered(() => askHere(relay.mod, relay.event, relay.change, relay.from, relay.project === project()))
562
529
  }
563
530
 
564
- const checkAct = async (caller: string, action: Act, input: unknown) => {
565
- const needed = actPermission(action, input)
566
- if (needed !== undefined && !(await isGranted(caller, needed))) throw new Error(await refused(caller, action, needed))
567
- }
568
-
569
531
  const perform = async (caller: string, action: Act, input: unknown, task: string | undefined): Promise<unknown> => {
570
- await checkAct(caller, action, input)
571
532
  await starting
572
533
  if (action === 'abort') return abortTurn(input, task)
573
534
  if (task !== undefined) return performInTask(caller, action, input, task)
@@ -654,7 +615,6 @@ export function serveConversations({
654
615
  }
655
616
 
656
617
  const actElsewhere = async (caller: string, target: string, action: Act, input: unknown, task: string | undefined): Promise<unknown> => {
657
- await checkAct(caller, action, input)
658
618
  const isLive = await isRunning(target)
659
619
  if (!isLive && action === 'usage') return json(['history', 'usage', target, ...(task === undefined ? [] : ['--task', task])])
660
620
  if (!isLive && action === 'surfaces') return []
@@ -823,8 +783,6 @@ export function serveConversations({
823
783
  const method = methods[e.method]
824
784
  if (method === undefined) return undefined
825
785
  const input = isObject(e.input) ? e.input : {}
826
- const isDropping = (e.method === conversationMethods.subscribe || e.method === conversationMethods.watchBefore) && Array.isArray(input['subscriptions']) && input['subscriptions'].length === 0
827
- if (e.method !== conversationMethods.act && !isDropping && input['session'] !== (await claude.session.id()) && !(await isGranted(e.caller, 'conversation'))) return { deny: await refused(e.caller, conversationCalls[e.method] ?? e.method, 'conversation') }
828
786
  try {
829
787
  return { value: await method(input, e.caller) }
830
788
  } catch (error) {
@@ -1,4 +1,4 @@
1
- import type { HookStream, ProcessSpawnChunk, ProcessSpawnRequest, ProcessSpawnResult } from 'claude-code'
1
+ import type { HookStream, ProcessSpawnChunk, ProcessSpawnResult } from 'claude-code'
2
2
  import type { Claude } from './claude.js'
3
3
  import type { Pages } from './pages.js'
4
4
  import type { Router } from './router.js'
@@ -13,7 +13,7 @@ export type Engine = {
13
13
  readonly report: (failure: Failure) => void
14
14
  readonly hasPermissionCheck: () => boolean
15
15
  readonly answerInput: <Answer>(run: () => Promise<Answer>, passOn: () => Promise<unknown>) => Promise<Answer>
16
- readonly spawnCmod: (args: readonly string[], program: ProcessSpawnRequest) => Promise<HookStream<ProcessSpawnChunk, ProcessSpawnResult>>
16
+ readonly spawnCmod: (args: readonly string[], env?: Readonly<Record<string, string>>) => HookStream<ProcessSpawnChunk, ProcessSpawnResult>
17
17
  readonly widgets?: Widgets
18
18
  readonly pages?: Pages
19
19
  }
@@ -2,7 +2,7 @@ import type { RenderElement } from 'claude-code'
2
2
  import type { Step } from '../installer.js'
3
3
  import type { Mod } from '../mod.js'
4
4
  import type { Option } from '../options.js'
5
- import { isObject, permissionWords, secretFix } from '../records.js'
5
+ import { isObject, secretFix } from '../records.js'
6
6
  import { Box, elementData, Input, Text, type Handler } from '../ui/elements.js'
7
7
  import { filledButton } from './buttons.js'
8
8
  import type { PageProps } from '../ui/panes.js'
@@ -13,15 +13,6 @@ import { merged, partMethods, stalePress, type DrawnPart, type PartPress, type P
13
13
 
14
14
  export const installPage = 'cmod:install'
15
15
 
16
- export type Consent = {
17
- readonly install: string
18
- readonly uninstall: string
19
- readonly program: string
20
- readonly hotkeys: string
21
- readonly permissions: readonly string[]
22
- readonly updates?: string | undefined
23
- }
24
-
25
16
  type Question = {
26
17
  draw(props: PageProps<undefined>): RenderElement
27
18
  cancel(): void
@@ -30,7 +21,6 @@ type Question = {
30
21
  export type Installer = {
31
22
  answer(method: string, input: unknown): Promise<{ readonly value: unknown }> | undefined
32
23
  hear(shown: ShownPages): void
33
- consent(consent: Consent): Promise<boolean>
34
24
  options(missing: readonly (readonly [string, Option])[], save: (key: string, value: string) => Promise<string | undefined>): Promise<boolean>
35
25
  step<State extends object>(mod: Mod<State>, step: Step<State>, index: number, total: number): Promise<boolean>
36
26
  close(): Promise<void>
@@ -91,10 +81,6 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
91
81
 
92
82
  const dialog = (title: RenderElement, ...children: readonly RenderElement[]) => Box({ flexDirection: 'column', gap: 1, children: [title, ...children] })
93
83
 
94
- const bullet = (text: string) => Box({ gap: 1, children: [Text({ dimColor: true, children: '•' }), Text({ wrap: 'wrap', children: text })] })
95
-
96
- const group = (heading: string, items: readonly string[]) => Box({ flexDirection: 'column', children: [Text({ bold: true, children: heading }), ...items.map(bullet)] })
97
-
98
84
  const draw = (columns: number, isFocused: boolean): DrawnPart => {
99
85
  if (question === undefined && !isOpen) claude().clock.after(0, () => void send({ requests: [{ close: installPage }] }).catch(log('a leftover install page stayed open')))
100
86
  const handlers: Handler[] = []
@@ -139,28 +125,6 @@ export function createInstaller(name: string, claude: () => Claude, waiting: { s
139
125
  isSeen = false
140
126
  question?.cancel()
141
127
  },
142
- consent({ install, uninstall, program, hotkeys, permissions, updates }) {
143
- const changes = [
144
- ...(install === '' ? [] : [`Run ${install} now${uninstall === '' ? '' : `, and ${uninstall} when you remove it`}`]),
145
- ...(install === '' && uninstall !== '' ? [`Run ${uninstall} when you remove it`] : []),
146
- ...(program === '' ? [] : [`Install ${program}, which Claude runs by its name`]),
147
- ...(hotkeys === '' ? [] : [`Bind ${hotkeys}`]),
148
- ...(updates === undefined ? [] : [`Update ${name} automatically from the ${updates} marketplace`]),
149
- ]
150
- return show<boolean>(
151
- (answer) => ({
152
- draw: () =>
153
- dialog(
154
- Text({ bold: true, children: `Install ${name}?` }),
155
- ...(permissions.length === 0 ? [] : [group(`${name} wants to:`, permissions.map(permissionWords))]),
156
- ...(changes.length === 0 ? [] : [group(permissions.length === 0 ? `${name} wants to change your computer:` : 'and change your computer:', changes)]),
157
- Text({ dimColor: true, wrap: 'wrap', children: 'You can turn each permission off later in Settings.' }),
158
- actions(filledButton({ key: 'accept', hotkey: 'a', variant: 'primary', label: 'Accept', onPress: () => answer(true) }), filledButton({ key: 'not-now', hotkey: 'n', label: 'Not now', onPress: () => answer(false) })),
159
- ),
160
- }),
161
- false,
162
- )
163
- },
164
128
  options(missing, save) {
165
129
  const saved = new Map<string, string>()
166
130
  const failures = new Map<string, string>()