@rhizogrip/spore-cli 1.42.0 → 1.43.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
 
@@ -94,7 +94,8 @@ const VERBS = `Usage:
94
94
  spore config get [<key>] every setting in effect, defaults marked
95
95
  spore config set|add|rm|path where workspaces live, and what your spores may use
96
96
  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`
97
+ spore doctor what is wrong on this machine, and the command that fixes each
98
+ spore doctor --report this machine as a GitHub issue you read, then file or not — spore sends nothing`
98
99
 
99
100
  if (!process.argv.slice(2).length) {
100
101
  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`)
@@ -180,7 +181,7 @@ const SHAPES = {
180
181
  },
181
182
  config: { bare: 'get', subs: { get: withJson(1), set: withJson(2), add: withJson(2), rm: withJson(2), path: withJson(0) } },
182
183
  usage: withJson(1, 'days', 'since', 'until', 'tz', 'by'),
183
- doctor: withJson(0),
184
+ doctor: withJson(0, 'report'),
184
185
  hook: { bare: 'ls', subs: { ls: withJson(0), show: withJson(1) } },
185
186
  tui: { flags: [], most: 1 },
186
187
  here: { flags: ['sporangium', 'model', 'no-git'], most: 1 },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rhizogrip/spore-cli",
3
- "version": "1.42.0",
3
+ "version": "1.43.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.0"
57
+ "@rhizogrip/spore": "1.43.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