@rhizogrip/spore-cli 1.42.1 → 1.44.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/bin/spore.js CHANGED
@@ -30,7 +30,7 @@ const DEFAULT_TAIL = 50
30
30
 
31
31
  const argv = minimist(process.argv.slice(2), {
32
32
  string: ['_', 'definition', 'from', 'sporangium', 'at', 'model', 'plugin', 'attach', 'request-id', 'after', 'since', 'until', 'tz', 'by', 'n', 'lines'],
33
- boolean: ['debug', 'help', 'version', 'yes', 'replay', 'json', 'all', 'outdated', 'f', 'clear'],
33
+ boolean: ['debug', 'help', 'version', 'yes', 'replay', 'json', 'all', 'outdated', 'f', 'clear', 'report'],
34
34
  alias: { h: 'help', n: 'lines' }
35
35
  })
36
36
 
@@ -49,7 +49,9 @@ const VERBS = `Usage:
49
49
  spore send <name> -- <message> -- ends the options, for a message that starts with -
50
50
  spore send|attach <name> --json for a program: the turn's events, one JSON object a line
51
51
  spore attach <name> --json --after <seq> the events after <seq>; 0 for the whole log
52
- spore fork <name> --at <call> <new> [--definition <f>] [--replay] carry a turn on from one of its rounds, in a copy
52
+ spore fork <name> <new> a copy as it stands between turns, schedules left behind
53
+ spore fork <name> --at turn:<n> <new> the same, as it stood after turn n
54
+ spore fork <name> --at <call> <new> [--replay] carry a turn on from one of its rounds, in a copy
53
55
  spore attach <name> [-n <lines>] watch a turn that is already going
54
56
  spore stop <name> SIGTERM it, mid-round
55
57
  spore extend <name> wall 30m|cost 1.50|rounds 20 give the running turn more, up to its extend.<limit>
@@ -94,7 +96,8 @@ const VERBS = `Usage:
94
96
  spore config get [<key>] every setting in effect, defaults marked
95
97
  spore config set|add|rm|path where workspaces live, and what your spores may use
96
98
  spore config set model <provider>/<name> the model new spores run on, in your default sporangium
97
- spore doctor what is wrong on this machine, and the command that fixes each`
99
+ spore doctor what is wrong on this machine, and the command that fixes each
100
+ spore doctor --report this machine as a GitHub issue you read, then file or not — spore sends nothing`
98
101
 
99
102
  if (!process.argv.slice(2).length) {
100
103
  console.log(`spore — AI agents you run on your own machines\n\n${VERBS}\n\n spore --help all of it: the flags, and why\n spore --version the installed version\n`)
@@ -115,12 +118,12 @@ ${VERBS}
115
118
  one you are standing in
116
119
  message read from stdin when not given
117
120
  -- ends the options, for a message that starts with -
118
- --definition the .cmk to give it, instead of your default
121
+ --definition the .cmk to give it, instead of your default; for fork, the one the copy runs under
119
122
  --from the spore to cut it from: what it can do, never what it did
120
123
  --json for a program: the answer as JSON, with the same exit code
121
124
  --debug verbose logging on stderr
122
125
 
123
- send, attach and fork exit 0 when the turn answered, 1 when it ended with no answer,
126
+ send, attach and a fork at a call exit 0 when the turn answered, 1 when it ended with no answer,
124
127
  3 when you walked away — Ctrl-C leaves the turn running, spore attach picks it up —
125
128
  and 4 when it wrapped up at a soft limit, its answer saying what remains.
126
129
 
@@ -180,7 +183,7 @@ const SHAPES = {
180
183
  },
181
184
  config: { bare: 'get', subs: { get: withJson(1), set: withJson(2), add: withJson(2), rm: withJson(2), path: withJson(0) } },
182
185
  usage: withJson(1, 'days', 'since', 'until', 'tz', 'by'),
183
- doctor: withJson(0),
186
+ doctor: withJson(0, 'report'),
184
187
  hook: { bare: 'ls', subs: { ls: withJson(0), show: withJson(1) } },
185
188
  tui: { flags: [], most: 1 },
186
189
  here: { flags: ['sporangium', 'model', 'no-git'], most: 1 },
@@ -362,13 +365,17 @@ if (verb === 'stop') {
362
365
 
363
366
  if (verb === 'fork') {
364
367
  const [into] = rest
365
- if (!asked || !argv.at || !into) fail('fork needs a spore, a call and somewhere new — spore fork <name> --at <call> <new> [--definition <f>] [--replay]')
368
+ if (!asked || !into) fail('fork needs a spore and somewhere new — spore fork <name> [--at turn:<n> | --at <call> [--replay]] <new> [--definition <f>]')
366
369
  let made
367
370
  try {
368
371
  made = fork({ run: spore(asked), at: argv.at, into: workspaceFor(into).path, definition: argv.definition, replay: argv.replay, debug: argv.debug })
369
372
  } catch (err) {
370
373
  fail(errorText(err))
371
374
  }
375
+ if (made.pid === undefined) {
376
+ console.error(`spore: forked ${made.from} after turn ${made.turnNo} into ${made.ws} — its next message starts its first turn`)
377
+ process.exit(0)
378
+ }
372
379
  console.error(`spore: forked ${made.from} at ${made.at}, round ${made.rounds} — carrying it on in ${made.ws}`)
373
380
  renderHeader(made.ws, grantOf(made.ws))
374
381
  const ended = await follow(made.ws, { lines: 0, status: true })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhizogrip/spore-cli",
3
- "version": "1.42.1",
3
+ "version": "1.44.0",
4
4
  "author": {
5
5
  "name": "Christophe Le Bars",
6
6
  "email": "clb@toort.net"
@@ -54,7 +54,7 @@
54
54
  "minimist": "^1.2.8"
55
55
  },
56
56
  "optionalDependencies": {
57
- "@rhizogrip/spore": "1.42.1"
57
+ "@rhizogrip/spore": "1.44.0"
58
58
  },
59
59
  "license": "Apache-2.0"
60
60
  }
package/src/dispatch.js CHANGED
@@ -14,7 +14,7 @@ import { homedir } from 'node:os'
14
14
  import { basename, join, resolve } from 'node:path'
15
15
 
16
16
  import { addTo, allowPlugin, annotate, billingFor, bytesText, changeText, define, defaultModel, disallowPlugin, durationText, edit, extend, flush, getKey, jobs, list, listApprovals, listPlugins, log, pause, remake, remove, removeFrom, removeSchedule, requestApproval, runningLines, schedules, setDefaultModel, setKey, setSchedule, settings, show, showPlugin, sql, stateWord, stopJob, switchModel, tick, tickReport, unmetered, unpause, upgrade, usage, wrap, CONFIG_FILE, DEFAULT_SPORANGIUM, errorText } from '@rhizogrip/spore'
17
- import { diagnose, renderDoctor } from './doctor.js'
17
+ import { diagnose, hostReport, renderDoctor, renderReport } from './doctor.js'
18
18
  import { hook } from './hooks.js'
19
19
  import { createServices } from './services.js'
20
20
  import { saidBy, saidText } from '../tui/conversation.js'
@@ -633,7 +633,9 @@ export async function manage (verb, argv) {
633
633
  }
634
634
  if (verb === 'service') return await service(argv, emit)
635
635
  if (verb === 'doctor') {
636
- return emit(await diagnose(), renderDoctor, (report) => (report.findings.some(found => found.severity === 'problem') ? 1 : 0))
636
+ const diagnosed = await diagnose()
637
+ if (argv.report) return emit(hostReport(diagnosed), renderReport)
638
+ return emit(diagnosed, renderDoctor, (report) => (report.findings.some(found => found.severity === 'problem') ? 1 : 0))
637
639
  }
638
640
  if (verb === 'define') {
639
641
  // No default to the current directory, unlike the read verbs: those answer about
package/src/doctor.js CHANGED
@@ -1,4 +1,8 @@
1
- import { doctor, loadMohdelEnvironment, modelFindings } from '@rhizogrip/spore'
1
+ import { createRequire } from 'node:module'
2
+ import { homedir } from 'node:os'
3
+ import { getSystemErrorName } from 'node:util'
4
+
5
+ import { boundary, describeHost, doctor, loadMohdelEnvironment, modelFindings } from '@rhizogrip/spore'
2
6
 
3
7
  import { createServices } from './services.js'
4
8
 
@@ -56,20 +60,69 @@ function serviceFindings (services, needsTick, replies) {
56
60
  export async function diagnose ({ services = createServices() } = {}) {
57
61
  loadMohdelEnvironment()
58
62
  const { findings, needsTick, replies } = doctor()
59
- return { findings: [...findings, ...await modelFindings(), ...serviceFindings(services, needsTick, replies)] }
63
+ const tried = await boundary()
64
+ return { findings: [...findings, ...tried.findings, ...await modelFindings(), ...serviceFindings(services, needsTick, replies)], boundary: tried.boundary, host: describeHost() }
65
+ }
66
+
67
+ const ISSUES = createRequire(import.meta.url)('../package.json').bugs.url
68
+
69
+ /**
70
+ * A diagnosis as a GitHub issue its reader files, or not: `{ title, body, url }`, the body this
71
+ * machine, the boundary as tried and what doctor found on the machine — never a spore, a model or
72
+ * a setting — with the home directory written `~`, and `url` the issue form filled with it.
73
+ */
74
+ export function hostReport ({ host, boundary, findings }) {
75
+ const landlock = host.landlock < 0 ? `not in this kernel (${getSystemErrorName(host.landlock)})` : `ABI ${host.landlock}`
76
+ const rows = [
77
+ ['spore', host.spore],
78
+ ['Node', `${host.node}, SQLite ${host.sqlite}`],
79
+ ['system', `${host.system}, ${host.arch}, in ${host.runsIn}`],
80
+ ['kernel', host.kernel],
81
+ ['Landlock', landlock],
82
+ ['AppArmor', host.appArmor ?? 'no switch for user namespaces'],
83
+ ['namespaces', host.contain.contained ? 'contained' : host.contain.why]
84
+ ]
85
+ const machine = findings.filter(found => found.area === 'machine')
86
+ const body = [
87
+ '| | |',
88
+ '|---|---|',
89
+ ...rows.map(([name, value]) => `| ${name} | ${value} |`),
90
+ '',
91
+ '**Boundary**',
92
+ '',
93
+ ...(boundary.length ? boundary.map(one => `- ${one.outcome} — ${one.tried}${one.outcome === 'refused' ? '' : ` (${one.why})`}`) : ['- not tried']),
94
+ '',
95
+ '**Found on the machine**',
96
+ '',
97
+ ...(machine.length ? machine.map(found => `- ${found.severity}: ${found.subject} — ${found.problem}`) : ['- nothing'])
98
+ ].join('\n').split(homedir()).join('~')
99
+ const title = `Host report: ${host.system}, ${host.kernel}`
100
+ const url = `${ISSUES}/new?${Object.entries({ template: 'host-report.yml', title, report: body }).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&')}`
101
+ return { title, body, url }
102
+ }
103
+
104
+ export function renderReport ({ body, url }) {
105
+ console.log(`${body}\n\nto share it, open this and submit the issue — nothing is sent until you do:\n${url}`)
60
106
  }
61
107
 
62
- export function renderDoctor ({ findings }) {
108
+ const OUTCOME_WIDTH = 9
109
+
110
+ export function renderDoctor ({ findings, boundary }) {
63
111
  for (const area of AREAS) {
64
112
  const here = findings.filter(found => found.area === area)
65
113
  if (!here.length) continue
66
114
  console.log(area)
67
115
  for (const found of here) {
68
116
  console.log(` ${found.severity === 'note' ? 'note: ' : ''}${found.subject} — ${found.problem}`)
69
- if (found.fix) console.log(` ${found.fix}`)
117
+ if (found.fix) console.log(found.fix.split('\n').map(line => ` ${line}`).join('\n'))
70
118
  }
71
119
  }
120
+ if (boundary.length) {
121
+ console.log('boundary — what a turn\'s commands tried on this host')
122
+ for (const one of boundary) console.log(` ${one.outcome.padEnd(OUTCOME_WIDTH)} ${one.tried}${one.outcome === 'refused' ? '' : ` — ${one.why}`}`)
123
+ }
72
124
  const problems = findings.filter(found => found.severity === 'problem').length
73
125
  const notes = findings.length - problems
74
- console.log(findings.length ? `\n${problems} problem${problems === 1 ? '' : 's'}, ${notes} note${notes === 1 ? '' : 's'}` : 'nothing wrong')
126
+ const total = findings.length ? `${problems} problem${problems === 1 ? '' : 's'}, ${notes} note${notes === 1 ? '' : 's'}` : 'nothing wrong'
127
+ console.log(findings.length || boundary.length ? `\n${total}` : total)
75
128
  }
package/src/setup.js CHANGED
@@ -90,7 +90,7 @@ export async function setup () {
90
90
  line('processes', processes.problem)
91
91
  log.message('without them, a turn sees the processes and command lines of every other spore of yours —\nwhich matters only when spores of other people run as this user')
92
92
  if (!await yes('run your spores uncontained?')) {
93
- log.warn(`${processes.fix}, then spore setup again`)
93
+ log.warn(`${processes.fix}\nthen spore setup again`)
94
94
  return 1
95
95
  }
96
96
  setKey('contain', 'off')
@@ -116,8 +116,13 @@ export async function setup () {
116
116
  await tickTimer({ services })
117
117
 
118
118
  const diagnosed = await diagnose({ services })
119
- if (diagnosed.findings.length) renderDoctor(diagnosed)
120
- else line('checked', 'this machine, your config and your spores — nothing to fix')
119
+ if (diagnosed.findings.length) {
120
+ renderDoctor(diagnosed)
121
+ } else {
122
+ line('checked', 'this machine, your config and your spores — nothing to fix')
123
+ const refused = diagnosed.boundary.filter(one => one.outcome === 'refused').length
124
+ if (diagnosed.boundary.length) line('boundary', `a turn's commands tried ${diagnosed.boundary.length} ways out here and were refused ${refused === diagnosed.boundary.length ? 'every one' : refused} — spore doctor lists them`)
125
+ }
121
126
  if (diagnosed.findings.some(one => one.severity === 'problem')) {
122
127
  log.warn('fix those, then spore setup again — spore doctor checks just that part')
123
128
  return 1