rvlib-shipkit 2.33.0 → 2.35.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/CHANGELOG.md +36 -0
- package/README.md +7 -0
- package/package.json +1 -1
- package/src/advisors/advisor-view.ts +1 -0
- package/src/advisors/sync.ts +4 -1
- package/src/agent-time/accounts-usage.ts +5 -0
- package/src/agent-time/render.ts +4 -2
- package/src/cli/cmd_BackupTargets.ts +49 -8
- package/src/cli/cmd_Commands.ts +3 -2
- package/src/cli/cmd_Init.ts +1 -1
- package/src/cli/cmd_Media.ts +1 -1
- package/src/cli/cmd_Orchestrator.ts +3 -3
- package/src/cli/cmd_Setup.ts +11 -2
- package/src/cli/cmd_Shot.ts +2 -2
- package/src/cli/cmd_Start.ts +6 -6
- package/src/cli/cmd_Time.ts +4 -2
- package/src/cli/family-pages.ts +11 -1
- package/src/cli/house-pages.ts +34 -0
- package/src/core/memory-watch.ts +1 -1
- package/src/gate/gate-checks.ts +7 -5
- package/src/home/backup-status.ts +54 -13
- package/src/home/backup-verdict.ts +1 -0
- package/src/home/configuration-route.ts +281 -0
- package/src/home/configuration-shape.ts +167 -0
- package/src/home/daemon-jobs.ts +5 -0
- package/src/home/home-routes.ts +9 -2
- package/src/home/house-bucket.ts +14 -0
- package/src/home/serve-web.ts +1 -1
- package/src/home/this-house.ts +68 -0
- package/src/home/via-hub.ts +2 -1
- package/src/hq/backup-targets.ts +58 -5
- package/src/hq/hq-local.ts +1 -1
- package/src/http/owner-word.ts +1 -0
- package/src/media-store/backup/bucket-target.ts +58 -0
- package/src/media-store/backup/target-send.ts +7 -4
- package/src/media-store/space.ts +2 -0
- package/src/review/cells.ts +6 -2
- package/src/review/store.ts +2 -1
- package/src/scaffold/project-scaffold.ts +2 -2
- package/src/scaffold/starter-house.ts +8 -6
- package/src/secrets/read.ts +1 -1
- package/src/serve/hub-app/auto-text.tsx +3 -1
- package/src/serve/hub-app/backups-view.tsx +4 -2
- package/src/serve/hub-app/columns.ts +5 -0
- package/src/serve/hub-app/configuration-st.ts +102 -0
- package/src/serve/hub-app/configuration-view.tsx +145 -0
- package/src/serve/hub-app/configuration.css +27 -0
- package/src/serve/hub-app/configure-link.tsx +16 -0
- package/src/serve/hub-app/database-view.tsx +3 -3
- package/src/serve/hub-app/home-pages.ts +2 -0
- package/src/serve/hub-app/home-st.ts +15 -4
- package/src/serve/hub-app/home.html +1 -0
- package/src/serve/hub-app/hub-app.tsx +2 -0
- package/src/serve/hub-app/icons.tsx +2 -0
- package/src/serve/hub-app/identities-view.tsx +2 -1
- package/src/serve/hub-app/index.html +1 -0
- package/src/serve/hub-app/machines-view.tsx +2 -0
- package/src/serve/hub-app/place-path.ts +1 -1
- package/src/serve/hub-app/projects-svc.ts +2 -1
- package/src/serve/hub-app/review/review-thread.tsx +2 -1
- package/src/serve/hub-app/review/thread-st.ts +8 -2
- package/src/serve/hub-app/review/tone-bar.tsx +4 -2
- package/src/serve/hub-app/secrets-page.tsx +2 -0
- package/src/serve/hub-app/space-view.tsx +2 -0
- package/src/serve/hub-app/vault-view.tsx +2 -0
- package/src/setup-house.ts +9 -9
- package/src/start-repo.ts +27 -30
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// machine is red whatever else is green, and the headline is the cells': a cell not proven is never green
|
|
11
11
|
import { machineGet, machineSet } from '../core/machine-db.ts'
|
|
12
12
|
import { ageWords } from '../core/words.ts'
|
|
13
|
-
import type
|
|
13
|
+
import { configBucket, ownBucket, type BackupTarget } from '../hq/backup-targets.ts'
|
|
14
14
|
import { type Drill, healthWords, REPLICA_BEHIND_MS, replicaLag, type ReplicaHealth, type ReplicaPlace } from '../hq/replica.ts'
|
|
15
15
|
import type { TargetSent } from '../media-store/backup/target-send.ts'
|
|
16
16
|
import { timeMachineFacts, type TimeMachineFacts } from '../media-store/backup/facts.ts'
|
|
@@ -30,7 +30,7 @@ export type Place = { id: string; label: string; where: string; kind: 'mac' | 'd
|
|
|
30
30
|
export type StoreRow = { row: string; id: StoreId; machine: string; name: string; what: string; state: CellState; line: string; stale?: true }
|
|
31
31
|
/** `machine`: where the judgement was made (the hq's machine), `at` its time. `client`: set where a client drew it,
|
|
32
32
|
* read from the hq; `stale` says the hq did not answer and how old the table is: never green, never red then */
|
|
33
|
-
export type BackupStatus = { at: number; machine: string; places: Place[]; stores: StoreRow[]; cells: Cell[]; alarms: string[]; worst: CellState; client?: { machine: string; readAt: number }; stale?: string }
|
|
33
|
+
export type BackupStatus = { notSetUp?: true; at: number; machine: string; places: Place[]; stores: StoreRow[]; cells: Cell[]; alarms: string[]; worst: CellState; client?: { machine: string; readAt: number }; stale?: string }
|
|
34
34
|
|
|
35
35
|
/** the red cells that ring the band and the alarm: a store with no working copy rings too; another red cell (a copy
|
|
36
36
|
* behind while another works) is red in the matrix only */
|
|
@@ -59,6 +59,14 @@ export type BackupInputs = {
|
|
|
59
59
|
vaultNear: { count: number; newest: number | null }
|
|
60
60
|
timeMachine: TimeMachineFacts
|
|
61
61
|
secondPlaceKey: boolean | null
|
|
62
|
+
/** a vault runs on this machine, or ran: false is a keychain only machine, which has no vault to copy. Unsaid: true */
|
|
63
|
+
vault?: boolean
|
|
64
|
+
/** the house has a Space, or its config does not say: false is a house with no media bucket, which has no Space to
|
|
65
|
+
* copy. Unsaid: true */
|
|
66
|
+
space?: boolean
|
|
67
|
+
/** a target, a copy or a drill was ever kept here, or the config names a place: false is a machine where no backup
|
|
68
|
+
* was set up yet, which is said once and rings no band. Unsaid: true */
|
|
69
|
+
setUp?: boolean
|
|
62
70
|
}
|
|
63
71
|
|
|
64
72
|
const ago = (at: number, now: number): string => `${ageWords(at, now)}`
|
|
@@ -113,9 +121,9 @@ function cellOf(store: StoreId, p: Place, d: BackupInputs, machine: string): Dra
|
|
|
113
121
|
const c = (state: CellState, short: string, text: string, proof: string | null = null, fix: string | null = null): Draft => ({ state, short, text, proof, fix })
|
|
114
122
|
const shortOf = (state: CellState, at: number): string => (state === 'danger' ? `${ago(at, now)}, stale` : ago(at, now))
|
|
115
123
|
const target = d.targets.find((x) => x.id === p.id)
|
|
116
|
-
const space = target
|
|
124
|
+
const space = target != null && configBucket(target.address) === 'mediaSpace'
|
|
117
125
|
// the Space is at its provider, on no disk of a machine: its one copy off it is the second place
|
|
118
|
-
if (store === 'space' && !(target
|
|
126
|
+
if (store === 'space' && !(target != null && configBucket(target.address) === 'spaceCopy')) return c('dim', space ? 'itself' : 'not here', space ? 'the Space itself, at its provider' : `the Space is not copied to ${p.label}: its copy off its provider is the second place`)
|
|
119
127
|
if (p.kind === 'mac') {
|
|
120
128
|
if (store === 'vault') return c('dim', 'live', `the live vault on ${machine}${d.vaultNear.count > 0 ? `, ${d.vaultNear.count} sealed snapshots beside it${d.vaultNear.newest == null ? '' : `, the newest ${ago(d.vaultNear.newest, now)}`}` : ''}`, 'the same disk: no help if it dies')
|
|
121
129
|
return c('dim', 'live', `the live hq.sqlite on ${machine}`, 'the same disk: no help if it dies')
|
|
@@ -142,8 +150,8 @@ function cellOf(store: StoreId, p: Place, d: BackupInputs, machine: string): Dra
|
|
|
142
150
|
}
|
|
143
151
|
return stream === 'mediaSpace' ? streamCell(d) : notStreamed(stream)
|
|
144
152
|
}
|
|
145
|
-
const second = t.address
|
|
146
|
-
if (second && d.secondPlaceKey === false) return c('warn', 'no key yet', 'no key yet: nothing goes there', null, '
|
|
153
|
+
const second = configBucket(t.address) === 'spaceCopy'
|
|
154
|
+
if (second && d.secondPlaceKey === false) return c('warn', 'no key yet', 'no key yet: nothing goes there', null, 'store the two secrets that serve.spaceCopy.key names (sk secret set)')
|
|
147
155
|
if (second && store === 'hq' && stream === 'spaceCopy') return streamCell(d)
|
|
148
156
|
if (store === 'vault') return sentCell(d.get<TargetSent>(`target-sent:vault:${p.id}`), now, BOUNDS.vault, BOUNDS.vault + 2 * H, 'sk daemon job backup targets')
|
|
149
157
|
if (store === 'hq') return sentCell(d.get<TargetSent>(`target-sent:hq:${p.id}`), now, BOUNDS.hqCopy, BOUNDS.hqCopyDanger, 'sk daemon job backup targets')
|
|
@@ -152,7 +160,7 @@ function cellOf(store: StoreId, p: Place, d: BackupInputs, machine: string): Dra
|
|
|
152
160
|
const proof = d.get<Proof>('space-copy-proof')
|
|
153
161
|
const copy = (x: Draft): Draft => ({ ...x, of: 'space copy' })
|
|
154
162
|
if (proof == null) return copy(d.get<boolean>('space-copy') === true ? c('warn', 'not yet', 'the first copy of the Space runs each night until it is whole: no proof yet', null, 'sk space') : c('warn', 'not yet', 'the Space is not copied there: the nightly copy is off', null, 'sk space copy --auto on'))
|
|
155
|
-
const first = d.targets.find((x) => x.address
|
|
163
|
+
const first = d.targets.find((x) => configBucket(x.address) === 'mediaSpace')?.label ?? 'the Space'
|
|
156
164
|
const of = `the nightly copy of ${first}`
|
|
157
165
|
if (!proof.ok) return copy(c('danger', 'proof FAILED', `${of} failed its proof ${ago(proof.at, now)}`, proof.why[0] ?? 'the proof failed', 'sk space proof'))
|
|
158
166
|
const age = now - proof.at
|
|
@@ -171,7 +179,11 @@ function cellOf(store: StoreId, p: Place, d: BackupInputs, machine: string): Dra
|
|
|
171
179
|
return c('dim', 'not here', `nothing of ${store} goes to ${p.label}`)
|
|
172
180
|
}
|
|
173
181
|
|
|
174
|
-
const whereOf = (t: BackupTarget): string =>
|
|
182
|
+
const whereOf = (t: BackupTarget): string => {
|
|
183
|
+
const own = ownBucket(t.address)
|
|
184
|
+
if (own != null) return `the bucket ${own.bucket} at ${new URL(own.endpoint).host} (s3)`
|
|
185
|
+
return t.address.kind === 'ssh' ? `${t.address.host}:${t.address.folder}` : configBucket(t.address) === 'mediaSpace' ? 'the private Space (s3)' : 'the second place (s3)'
|
|
186
|
+
}
|
|
175
187
|
|
|
176
188
|
/** the table and its alarms: every cell, each row's verdict, every reason to be red */
|
|
177
189
|
export function backupStatus(d: BackupInputs): BackupStatus {
|
|
@@ -190,6 +202,7 @@ export function backupStatus(d: BackupInputs): BackupStatus {
|
|
|
190
202
|
const stores: StoreRow[] = []
|
|
191
203
|
const alarms: string[] = []
|
|
192
204
|
for (const s of STORES) {
|
|
205
|
+
if ((s.id === 'vault' && d.vault === false) || (s.id === 'space' && d.space === false)) continue
|
|
193
206
|
const row = `${judge}/${s.id}`
|
|
194
207
|
const mine = places.map((p): Cell => {
|
|
195
208
|
// a record that does not read leaves its cell orange, never the whole table thrown
|
|
@@ -209,15 +222,38 @@ export function backupStatus(d: BackupInputs): BackupStatus {
|
|
|
209
222
|
// the Space is its provider's: its second copy missing is orange, a broken one red, never « no copy »
|
|
210
223
|
const none = good.length === 0 && s.id !== 'space'
|
|
211
224
|
// a copy there but not proven (never restored, behind) is said as such: the fix differs from a copy gone
|
|
212
|
-
if (none) alarms.unshift(off.some((c) => c.state === 'warn') ? `${label}: NO proven copy off ${judge}` : `${label}: NO working copy off ${judge}`)
|
|
225
|
+
if (none && d.setUp !== false) alarms.unshift(off.some((c) => c.state === 'warn') ? `${label}: NO proven copy off ${judge}` : `${label}: NO working copy off ${judge}`)
|
|
213
226
|
for (const c of off.filter((x) => x.state === 'danger' && BROKEN.has(x.short))) alarms.push(`${label} on ${places.find((p) => p.id === c.place)!.label}: ${c.text}`)
|
|
214
|
-
const state: CellState = none ? 'danger' : off.some((c) => c.state === 'danger') ? 'danger' : off.some((c) => c.state === 'warn') || good.length === 0 ? 'warn' : 'ok'
|
|
227
|
+
const state: CellState = none && d.setUp === false ? 'warn' : none ? 'danger' : off.some((c) => c.state === 'danger') ? 'danger' : off.some((c) => c.state === 'warn') || good.length === 0 ? 'warn' : 'ok'
|
|
215
228
|
stores.push({ row, id: s.id, machine: judge, name: s.name, what: s.what, state, line: `${good.length} of ${off.length} copies off ${judge} work` })
|
|
216
229
|
}
|
|
217
230
|
// the headline is the cells': a cell not proven (unknown, never drilled, behind) keeps it from green
|
|
218
231
|
const unproven = cells.some((c) => c.state === 'warn' || c.state === 'danger') || stores.some((r) => r.state !== 'ok')
|
|
219
232
|
const worst: CellState = alarms.length > 0 ? 'danger' : unproven ? 'warn' : 'ok'
|
|
220
|
-
return { at: d.now, machine: judge, places, stores, cells, alarms, worst }
|
|
233
|
+
return { ...(d.setUp === false ? { notSetUp: true as const } : {}), at: d.now, machine: judge, places, stores, cells, alarms, worst }
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/** how long a first target waits for its first send before its silence rings */
|
|
237
|
+
export const FIRST_SEND_MS = 30 * 60_000
|
|
238
|
+
|
|
239
|
+
/** whether a backup was ever set up here: a record any send, snapshot or drill kept, a place the config names, or a
|
|
240
|
+
* target old enough that its first send is overdue. A first target added a moment ago is none yet: the daemon's next
|
|
241
|
+
* look sends to it */
|
|
242
|
+
export const everSetUp = (o: { targets: readonly BackupTarget[]; kept: boolean; names: boolean; now: number }): boolean => o.kept || o.names || o.targets.some((t) => o.now - t.at > FIRST_SEND_MS)
|
|
243
|
+
|
|
244
|
+
/** whether the house config names a place for backups, and a Space; a config that does not load may name both: only
|
|
245
|
+
* one read and empty says that none was ever set up */
|
|
246
|
+
async function namesPlace(): Promise<{ any: boolean; space: boolean }> {
|
|
247
|
+
try {
|
|
248
|
+
const { houseRootOf } = await import('./home-start.ts')
|
|
249
|
+
const { loadRepoConfig } = await import('../repo-config.ts')
|
|
250
|
+
const house = houseRootOf(process.cwd())
|
|
251
|
+
if (house == null) return { any: true, space: true }
|
|
252
|
+
const s = (await loadRepoConfig(house)).serve
|
|
253
|
+
return { any: s?.mediaSpace != null || s?.spaceCopy != null || s?.hqReplica != null, space: s?.mediaSpace != null }
|
|
254
|
+
} catch {
|
|
255
|
+
return { any: true, space: true }
|
|
256
|
+
}
|
|
221
257
|
}
|
|
222
258
|
|
|
223
259
|
/** every input, read on the machine that carries the hq: the targets of its hq, the kept records, Litestream's files,
|
|
@@ -254,7 +290,9 @@ export async function readBackupInputs(now = Date.now()): Promise<BackupInputs>
|
|
|
254
290
|
} catch {
|
|
255
291
|
count = 0
|
|
256
292
|
}
|
|
257
|
-
const
|
|
293
|
+
const names = await namesPlace()
|
|
294
|
+
const copyId = targets.find((t) => configBucket(t.address) === 'spaceCopy')?.id
|
|
295
|
+
const second = copyId == null ? null : machineGet<TargetSent>(`target-sent:vault:${copyId}`)
|
|
258
296
|
return {
|
|
259
297
|
now,
|
|
260
298
|
machine,
|
|
@@ -264,6 +302,9 @@ export async function readBackupInputs(now = Date.now()): Promise<BackupInputs>
|
|
|
264
302
|
vaultNear: { count, newest },
|
|
265
303
|
timeMachine: await timeMachineFacts(now),
|
|
266
304
|
secondPlaceKey: second == null ? null : !('failed' in second && second.failed.startsWith('no key yet')),
|
|
305
|
+
vault: (await import('../secrets/read.ts')).vaultHere() || count > 0 || machineGet('vault-snapshot-sent') != null,
|
|
306
|
+
space: names.space || targets.some((t) => configBucket(t.address) != null),
|
|
307
|
+
setUp: everSetUp({ targets, kept: folder != null || machineGet('vault-snapshot-sent') != null || machineGet('hq-drill') != null || targets.some((t) => ['vault', 'hq'].some((s) => machineGet(`target-sent:${s}:${t.id}`) != null)), names: names.any, now }),
|
|
267
308
|
}
|
|
268
309
|
}
|
|
269
310
|
|
|
@@ -295,7 +336,7 @@ export const alarmKeys = (s: BackupStatus): string[] =>
|
|
|
295
336
|
s.stale != null
|
|
296
337
|
? []
|
|
297
338
|
: [
|
|
298
|
-
...s.stores.filter((r) => r.stale !== true && r.id !== 'space' && !s.cells.some((c) => c.row === r.row && c.state === 'ok' && c.off)).map((r) => `${r.row}:none`),
|
|
339
|
+
...s.stores.filter((r) => s.notSetUp !== true && r.stale !== true && r.id !== 'space' && !s.cells.some((c) => c.row === r.row && c.state === 'ok' && c.off)).map((r) => `${r.row}:none`),
|
|
299
340
|
...s.cells.filter((c) => c.state === 'danger' && BROKEN.has(c.short) && c.off && s.stores.find((r) => r.row === c.row)?.stale !== true).map((c) => `${c.row}@${c.place}`),
|
|
300
341
|
]
|
|
301
342
|
|
|
@@ -7,6 +7,7 @@ export const rowName = (r: Pick<StoreRow, 'name'>): string => r.name
|
|
|
7
7
|
|
|
8
8
|
export function verdictWords(s: BackupStatus): string {
|
|
9
9
|
if (s.stale != null) return `not read: ${s.stale}`
|
|
10
|
+
if (s.notSetUp === true) return 'no copy has left this machine yet: what it keeps is on its own disk alone'
|
|
10
11
|
if (s.worst === 'danger') return 'a backup is NOT working'
|
|
11
12
|
if (s.worst === 'warn') return 'not every copy is fresh and proven: the orange lines say what to fix'
|
|
12
13
|
return 'every copy is fresh and proven'
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
// the configuration page's routes on the home: what is set on this machine (GET, read only), and two acts of his click,
|
|
2
|
+
// a secret stored and a backup target added, tried or switched. Every act is the owning store's own verb.
|
|
3
|
+
//
|
|
4
|
+
// The one constraint a reader breaks first: an act never replaces anything in silence. A secret already held, and a
|
|
5
|
+
// target whose id exists, are refused unless the click says so (a secret) or never from here (a target's address). A
|
|
6
|
+
// value is a word of the one request: never in an answer, a log, an error or a url
|
|
7
|
+
import { homedir } from 'os'
|
|
8
|
+
import { existsSync, readFileSync } from 'fs'
|
|
9
|
+
import { basename, dirname, join } from 'path'
|
|
10
|
+
import { accountProblem, storeValue } from '../collections/actions.ts'
|
|
11
|
+
import { addressProblem, ownBucket, type BackupTarget, type BucketAddress, type TargetAddress, type TargetRefused } from '../hq/backup-targets.ts'
|
|
12
|
+
import { DOOR_KEY_HEADER } from '../http/door-forward.ts'
|
|
13
|
+
import { HOP_HEADER } from '../http/hop-names.ts'
|
|
14
|
+
import type { SecretStore } from '../secrets/manager.ts'
|
|
15
|
+
import { SECRET_NAME } from '../secrets/name.ts'
|
|
16
|
+
import { isTemplate } from '../secrets/name-template.ts'
|
|
17
|
+
import type { Held } from '../secrets/held.ts'
|
|
18
|
+
import { terminalRefusal } from '../serve/terminal-guard.ts'
|
|
19
|
+
import { configurationPage, type ConfigInputs, type ConfigPage, type ConfigTarget } from './configuration-shape.ts'
|
|
20
|
+
|
|
21
|
+
export const CONFIGURATION_PATH = '/api/home/configuration'
|
|
22
|
+
|
|
23
|
+
const VALUE_MAX = 16_384
|
|
24
|
+
const NO_STORE = { 'cache-control': 'no-store' }
|
|
25
|
+
const answer = (body: unknown, status = 200): Response => Response.json(body, { status, headers: NO_STORE })
|
|
26
|
+
const refuse = (why: string, status = 400): Response => answer({ refused: why }, status)
|
|
27
|
+
|
|
28
|
+
/** why a click may not change a setting here, null when it may: this machine's own browser on its own hub alone */
|
|
29
|
+
export function configurationRefusal(req: Request, peer: string | null): string | null {
|
|
30
|
+
if (req.headers.has(HOP_HEADER) || req.headers.has(DOOR_KEY_HEADER)) return "refused: a setting of this machine is changed at this machine's own hub, never through the hq's proxy or a hop"
|
|
31
|
+
return terminalRefusal(req, peer, 'a setting of this machine')
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** the reads and the stores the acts go through; a test passes its own */
|
|
35
|
+
export type ConfigurationDeps = {
|
|
36
|
+
page: () => Promise<ConfigPage>
|
|
37
|
+
held: (name: string) => Promise<Held>
|
|
38
|
+
/** the house repo the secrets are stored for */
|
|
39
|
+
root: string
|
|
40
|
+
store: SecretStore
|
|
41
|
+
targets: () => BackupTarget[] | null
|
|
42
|
+
put: (t: { id: string; label: string; address: TargetAddress }) => BackupTarget | TargetRefused | null
|
|
43
|
+
on: (id: string, on: boolean) => BackupTarget | TargetRefused | null
|
|
44
|
+
/** an object written and read back: null when it came back the same, else why */
|
|
45
|
+
tryBucket: (a: BucketAddress) => Promise<string | null>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const text = (v: unknown): string => (typeof v === 'string' ? v.trim() : '')
|
|
49
|
+
|
|
50
|
+
/** why a value is not stored, null when it may be */
|
|
51
|
+
function valueProblem(name: string, value: string): string | null {
|
|
52
|
+
if (value === '') return `${name}: an empty value is not stored`
|
|
53
|
+
if (value.length > VALUE_MAX) return `${name}: longer than ${VALUE_MAX} characters; store it with sk secret set ${name} < <file>`
|
|
54
|
+
return /[\r\n]/.test(value) ? `${name}: a value of several lines; store it with sk secret set ${name} < <file>` : null
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
async function storeSecret(d: ConfigurationDeps, b: Record<string, unknown>): Promise<Response> {
|
|
58
|
+
const name = text(b['name'])
|
|
59
|
+
const value = text(b['value'])
|
|
60
|
+
const account = text(b['account'])
|
|
61
|
+
if (!SECRET_NAME.test(name) || isTemplate(name)) return refuse('a secret is named with letters, digits, dots, dashes and slashes: backup/key')
|
|
62
|
+
const problem = valueProblem(name, value) ?? (account === '' ? null : accountProblem(account))
|
|
63
|
+
if (problem != null) return refuse(problem)
|
|
64
|
+
const held = await d.held(name)
|
|
65
|
+
if (held.held === 'unknown') return refuse(`${name}: whether it is stored could not be read (${held.why}), so nothing was stored`, 409)
|
|
66
|
+
if (held.held === 'stored' && b['replace'] !== true) return refuse(`${name} is stored already: tick replace to store a new value over it`, 409)
|
|
67
|
+
try {
|
|
68
|
+
await storeValue({ root: d.root, name, value, account: account === '' ? undefined : account, store: d.store })
|
|
69
|
+
} catch (e) {
|
|
70
|
+
// storeValue throws a fixed line that holds no value
|
|
71
|
+
return refuse((e as Error).message, 502)
|
|
72
|
+
}
|
|
73
|
+
return answer({ stored: name })
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** a bucket with its key: both halves stored under `backup/<id>/`, then the row that names them */
|
|
77
|
+
async function addBucket(d: ConfigurationDeps, b: Record<string, unknown>): Promise<Response> {
|
|
78
|
+
const id = text(b['id'])
|
|
79
|
+
const keyId = text(b['keyId'])
|
|
80
|
+
const keySecret = text(b['keySecret'])
|
|
81
|
+
const all = d.targets()
|
|
82
|
+
if (all == null) return refuse('this machine carries no hq: add the target on the one that does', 409)
|
|
83
|
+
if (all.some((t) => t.id === id)) return refuse(`a target ${JSON.stringify(id)} exists: its address is changed with sk backup targets add`, 409)
|
|
84
|
+
const key = { accessKeyId: `backup/${id}/key-id`, secretAccessKey: `backup/${id}/key-secret` }
|
|
85
|
+
const address: BucketAddress = { kind: 's3', endpoint: text(b['endpoint']).replace(/\/$/, ''), bucket: text(b['bucket']), region: text(b['region']) === '' ? 'auto' : text(b['region']), ...(b['inHost'] === true ? {} : { path: true }), key }
|
|
86
|
+
const problem = (/^[a-z0-9][a-z0-9-]{0,39}$/.test(id) ? null : 'a name of lowercase letters, digits and dashes') ?? addressProblem(address) ?? valueProblem('the access key id', keyId) ?? valueProblem('the secret access key', keySecret)
|
|
87
|
+
if (problem != null) return refuse(problem)
|
|
88
|
+
for (const [name, value] of [[key.accessKeyId, keyId], [key.secretAccessKey, keySecret]] as const) {
|
|
89
|
+
const held = await d.held(name)
|
|
90
|
+
if (held.held !== 'missing') return refuse(`${name} is ${held.held === 'stored' ? 'stored already' : 'not readable here'}: pick another name for the target`, 409)
|
|
91
|
+
try {
|
|
92
|
+
await storeValue({ root: d.root, name, value, store: d.store })
|
|
93
|
+
} catch (e) {
|
|
94
|
+
return refuse(`${(e as Error).message}; the target was not added`, 502)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const r = d.put({ id, label: text(b['label']) === '' ? id : text(b['label']), address })
|
|
98
|
+
if (r == null) return refuse('this machine carries no hq: the key is stored, the target was not added', 409)
|
|
99
|
+
return 'refused' in r ? refuse(`${r.refused}; its key is stored, the target was not added`) : answer({ added: r.id })
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function addMachine(d: ConfigurationDeps, b: Record<string, unknown>): Response {
|
|
103
|
+
const id = text(b['id'])
|
|
104
|
+
const all = d.targets()
|
|
105
|
+
if (all == null) return refuse('this machine carries no hq: add the target on the one that does', 409)
|
|
106
|
+
if (all.some((t) => t.id === id)) return refuse(`a target ${JSON.stringify(id)} exists: its address is changed with sk backup targets add`, 409)
|
|
107
|
+
const r = d.put({ id, label: text(b['label']) === '' ? id : text(b['label']), address: { kind: 'ssh', host: text(b['host']), folder: text(b['folder']) } })
|
|
108
|
+
return r == null ? refuse('this machine carries no hq', 409) : 'refused' in r ? refuse(r.refused) : answer({ added: r.id })
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** `GET` the page; `POST /secret`, `/bucket`, `/machine`, `/switch`, `/try`: his click. Null for any other path */
|
|
112
|
+
export async function configurationRoute(req: Request, path: string, peer: string | null, deps: () => Promise<ConfigurationDeps>): Promise<Response | null> {
|
|
113
|
+
if (path !== CONFIGURATION_PATH && !path.startsWith(`${CONFIGURATION_PATH}/`)) return null
|
|
114
|
+
if (req.method === 'GET' && path === CONFIGURATION_PATH) {
|
|
115
|
+
try {
|
|
116
|
+
return answer(await (await deps()).page())
|
|
117
|
+
} catch {
|
|
118
|
+
// our own words: an error of a store may quote what it read
|
|
119
|
+
return refuse('the settings of this machine could not be read: sk check says why', 503)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const why = configurationRefusal(req, peer)
|
|
123
|
+
if (why != null) return refuse(why, 403)
|
|
124
|
+
const b = (await req.json().catch(() => null)) as Record<string, unknown> | null
|
|
125
|
+
if (b == null || typeof b !== 'object' || Array.isArray(b)) return refuse('the body is no json object')
|
|
126
|
+
const d = await deps()
|
|
127
|
+
switch (path.slice(CONFIGURATION_PATH.length + 1)) {
|
|
128
|
+
case 'secret':
|
|
129
|
+
return storeSecret(d, b)
|
|
130
|
+
case 'bucket':
|
|
131
|
+
return addBucket(d, b)
|
|
132
|
+
case 'machine':
|
|
133
|
+
return addMachine(d, b)
|
|
134
|
+
case 'switch': {
|
|
135
|
+
const r = typeof b['id'] === 'string' && typeof b['on'] === 'boolean' ? d.on(b['id'], b['on']) : { refused: 'a switch names its target and on or off' }
|
|
136
|
+
return r == null ? refuse('this machine carries no hq', 409) : 'refused' in r ? refuse(r.refused) : answer({ id: r.id, on: r.on })
|
|
137
|
+
}
|
|
138
|
+
case 'try': {
|
|
139
|
+
const t = d.targets()?.find((x) => x.id === b['id'])
|
|
140
|
+
const own = t == null ? null : ownBucket(t.address)
|
|
141
|
+
if (own == null) return refuse('only a bucket added by hand is tried from here')
|
|
142
|
+
const problem = await d.tryBucket(own)
|
|
143
|
+
return problem == null ? answer({ tried: t!.id }) : refuse(problem, 502)
|
|
144
|
+
}
|
|
145
|
+
default:
|
|
146
|
+
return refuse('no such act', 404)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** « missing » of `heldHere` proven by the stores a write would change, else unknown. `heldHere` says missing of any
|
|
151
|
+
* read that gave no value, a refused keychain item and a vault that does not answer included, and a keychain write
|
|
152
|
+
* deletes the other items of the name: a write that must not replace needs the absence itself. `vaultLacks`: null with
|
|
153
|
+
* no vault in reach */
|
|
154
|
+
export async function provenHeld(first: Held, o: { manager: boolean; vaultLacks: (() => Promise<boolean>) | null; keychainLacks: () => boolean }): Promise<Held> {
|
|
155
|
+
if (first.held !== 'missing') return first
|
|
156
|
+
const unknown = (why: string): Held => ({ held: 'unknown', why })
|
|
157
|
+
if (o.manager) return unknown("this house's own secret manager never says why it gives no value: use sk secret set")
|
|
158
|
+
try {
|
|
159
|
+
if (o.vaultLacks != null && !(await o.vaultLacks())) return unknown('the vault holds it, or has no place for it')
|
|
160
|
+
return o.keychainLacks() ? first : unknown('the keychain holds an item of this name that was not read')
|
|
161
|
+
} catch {
|
|
162
|
+
// our own words: a store's error may quote what it read
|
|
163
|
+
return unknown('its store did not answer')
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** the logins gh keeps, from its hosts file: the `user:` lines alone, never a token */
|
|
168
|
+
export const ghUsers = (hosts: string): string[] => [...new Set([...hosts.matchAll(/^\s+user:\s*([A-Za-z0-9-]+)\s*$/gm)].map((m) => m[1]!))]
|
|
169
|
+
|
|
170
|
+
const tilde = (p: string, home: string): string => (p === home || p.startsWith(`${home}/`) ? `~${p.slice(home.length)}` : p)
|
|
171
|
+
const whereOf = (a: TargetAddress): string => {
|
|
172
|
+
const own = ownBucket(a)
|
|
173
|
+
if (own != null) return `the bucket ${own.bucket} at ${new URL(own.endpoint).host}`
|
|
174
|
+
return a.kind === 'ssh' ? `${a.host}:${a.folder}` : 'config' in a ? `the bucket of serve.${a.config}` : ''
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** every input of the page on this machine, for the house at `root`; each part fails alone */
|
|
178
|
+
export async function readConfigInputs(root: string): Promise<ConfigInputs> {
|
|
179
|
+
const home = homedir()
|
|
180
|
+
const [{ loadRepoConfig }, { houseRepos }, hq, local, { machineName, tailnetName }, { discoverConfigRoots }, { vaultHere, vaultReach, heldHere }, { accountLabel }, { readAccounts }] = await Promise.all([
|
|
181
|
+
import('../repo-config.ts'),
|
|
182
|
+
import('../house/project-gutter.ts'),
|
|
183
|
+
import('../hq/hq-role.ts'),
|
|
184
|
+
import('../hq/hq-local.ts'),
|
|
185
|
+
import('./machine-host.ts'),
|
|
186
|
+
import('../reflect/prompt-corpus.ts'),
|
|
187
|
+
import('../secrets/read.ts'),
|
|
188
|
+
import('../agent-time/accounts-usage.ts'),
|
|
189
|
+
import('../agent-time/accounts-usage-disk.ts'),
|
|
190
|
+
])
|
|
191
|
+
const accounts = readAccounts()
|
|
192
|
+
let configWhy: string | null = null
|
|
193
|
+
const config = await loadRepoConfig(root).catch((e: unknown) => ((configWhy = (e as Error).message.split('\n')[0] ?? 'it throws'), null))
|
|
194
|
+
const { listTargets } = await import('../hq/backup-targets.ts')
|
|
195
|
+
const store = hq.carriesHq() ? local.carriedHq() : null
|
|
196
|
+
const rows = store == null ? null : listTargets(store.db)
|
|
197
|
+
const targets: ConfigTarget[] | null = rows?.map((t) => ({ id: t.id, label: t.label, on: t.on, where: whereOf(t.address), own: ownBucket(t.address) != null })) ?? null
|
|
198
|
+
const s = config?.serve
|
|
199
|
+
const named = new Map<string, string>()
|
|
200
|
+
const name = (key: { accessKeyId: string; secretAccessKey: string } | undefined, by: string): void => {
|
|
201
|
+
for (const x of key == null ? [] : [key.accessKeyId, key.secretAccessKey]) if (!named.has(x)) named.set(x, by)
|
|
202
|
+
}
|
|
203
|
+
for (const t of rows ?? []) name(ownBucket(t.address)?.key, `the target ${t.label}`)
|
|
204
|
+
name(s?.mediaSpace?.key, 'the media store')
|
|
205
|
+
name(s?.spaceCopy?.key, 'its copy')
|
|
206
|
+
name(s?.hqReplica?.key, "the hq's live copy")
|
|
207
|
+
const held = await heldHere({ names: [...named.keys()], cwd: root }).catch((): Record<string, Held> => ({}))
|
|
208
|
+
const backups = await import('./backup-status.ts').then(async ({ backupsHere }) => backupsHere()).catch(() => null)
|
|
209
|
+
const { verdictWords } = await import('./backup-verdict.ts')
|
|
210
|
+
const machines = await local.machinesPage().then((r) => ('refused' in r ? null : r.machines.length), () => null)
|
|
211
|
+
const identities = await import('../identities/identities.ts').then(({ loadIdentities }) => loadIdentities({ cwd: root })).then((r) => r.identities.map((x) => x.id), () => [])
|
|
212
|
+
const hosts = join(home, '.config', 'gh', 'hosts.yml')
|
|
213
|
+
return {
|
|
214
|
+
machine: machineName(),
|
|
215
|
+
house: existsSync(root) ? { path: tilde(root, home), repos: houseRepos(root, home).repos.length } : null,
|
|
216
|
+
configWhy,
|
|
217
|
+
identities,
|
|
218
|
+
targets,
|
|
219
|
+
backups: backups == null ? null : { words: verdictWords(backups), worst: backups.worst, notSetUp: backups.notSetUp === true },
|
|
220
|
+
named: [...named].map(([n, by]) => ({ name: n, by, held: held[n]?.held === 'stored' ? true : held[n]?.held === 'missing' ? false : null })),
|
|
221
|
+
registered: config?.creds?.length ?? 0,
|
|
222
|
+
claude: { bin: Bun.which('claude') != null, accounts: discoverConfigRoots(home).map((r) => basename(dirname(r.projects))).map((folder) => ({ name: accountLabel(folder, accounts), folder })) },
|
|
223
|
+
github: { bin: Bun.which('gh') != null, users: existsSync(hosts) ? ghUsers(readFileSync(hosts, 'utf8')) : [] },
|
|
224
|
+
hq: { role: hq.hqRole(), machines },
|
|
225
|
+
media: s?.mediaSpace == null ? null : { bucket: s.mediaSpace.bucket, region: s.mediaSpace.region },
|
|
226
|
+
vault: vaultHere() ? 'here' : (await vaultReach().catch(() => null)) != null ? 'master' : 'none',
|
|
227
|
+
remote: tailnetName(),
|
|
228
|
+
notify: (config?.notifyCommand ?? '') !== '',
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** the acts and the reads of this machine, for the house at `root` */
|
|
233
|
+
export async function configurationHere(root: string): Promise<ConfigurationDeps> {
|
|
234
|
+
const [{ carriesHq }, { carriedHq }, t, { managerStore, managerTemplate, secretsWhere }, { heldHere, vaultApi, vaultPathFor, vaultReach }, { keychainReader }, { KV_MOUNT }] = await Promise.all([
|
|
235
|
+
import('../hq/hq-role.ts'),
|
|
236
|
+
import('../hq/hq-local.ts'),
|
|
237
|
+
import('../hq/backup-targets.ts'),
|
|
238
|
+
import('../secrets/manager.ts'),
|
|
239
|
+
import('../secrets/read.ts'),
|
|
240
|
+
import('../secrets/keychain.ts'),
|
|
241
|
+
import('../vault/layout.ts'),
|
|
242
|
+
])
|
|
243
|
+
const db = () => (carriesHq() ? (carriedHq()?.db ?? null) : null)
|
|
244
|
+
return {
|
|
245
|
+
root,
|
|
246
|
+
page: async () => configurationPage(await readConfigInputs(root)),
|
|
247
|
+
held: async (name) => {
|
|
248
|
+
const first = (await heldHere({ names: [name], cwd: root }))[name] ?? { held: 'unknown' as const, why: 'the store did not answer' }
|
|
249
|
+
const w = await secretsWhere(root)
|
|
250
|
+
const reach = await vaultReach()
|
|
251
|
+
return provenHeld(first, {
|
|
252
|
+
manager: managerTemplate(w, 'credsReadCommand') != null || managerTemplate(w, 'credsCommand') != null,
|
|
253
|
+
vaultLacks: reach == null ? null : async () => {
|
|
254
|
+
const path = vaultPathFor(w, name)
|
|
255
|
+
const vault = await vaultApi()
|
|
256
|
+
if (vault == null) throw new Error('no vault answers')
|
|
257
|
+
return path != null && (await vault.writtenAt(KV_MOUNT, path)) == null
|
|
258
|
+
},
|
|
259
|
+
keychainLacks: () => keychainReader().read(name) == null,
|
|
260
|
+
})
|
|
261
|
+
},
|
|
262
|
+
store: managerStore(root),
|
|
263
|
+
targets: () => {
|
|
264
|
+
const d = db()
|
|
265
|
+
return d == null ? null : t.listTargets(d)
|
|
266
|
+
},
|
|
267
|
+
put: (x) => {
|
|
268
|
+
const d = db()
|
|
269
|
+
return d == null ? null : t.putTarget(d, x, Date.now())
|
|
270
|
+
},
|
|
271
|
+
on: (id, on) => {
|
|
272
|
+
const d = db()
|
|
273
|
+
return d == null ? null : t.setTargetOn(d, id, on)
|
|
274
|
+
},
|
|
275
|
+
tryBucket: async (a) => {
|
|
276
|
+
const [{ bucketProblem }, { houseBucket }, { machineName }] = await Promise.all([import('../media-store/backup/bucket-target.ts'), import('./house-bucket.ts'), import('./machine-host.ts')])
|
|
277
|
+
const c = await houseBucket(a)
|
|
278
|
+
return 'why' in c ? c.why : bucketProblem(c, machineName())
|
|
279
|
+
},
|
|
280
|
+
}
|
|
281
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// the configuration page's answer: every thing a person can set on this machine, its state now, and the act that sets
|
|
2
|
+
// it. Pure: the route reads (configuration-route.ts), the hub draws, a test feeds made up inputs.
|
|
3
|
+
//
|
|
4
|
+
// The one constraint a reader breaks first: no second store. A topic's state is read from the store that owns it, and
|
|
5
|
+
// its act is that store's own verb. No value of a secret is ever an input here: names and whether each is held
|
|
6
|
+
import type { Fact } from './vault-words.ts'
|
|
7
|
+
|
|
8
|
+
/** the topics, in the order a new person meets them; each id is its address, `/configuration#<id>` */
|
|
9
|
+
export const CONFIG_TOPICS = ['backups', 'secrets', 'claude', 'github', 'house', 'identities', 'machines', 'media', 'vault', 'remote', 'notifications'] as const
|
|
10
|
+
export type ConfigTopicId = (typeof CONFIG_TOPICS)[number]
|
|
11
|
+
|
|
12
|
+
/** set: it works as far as this machine can read; missing: shipkit is poorer without it; optional: fine as it is;
|
|
13
|
+
* broken: set, and not working */
|
|
14
|
+
export type ConfigState = 'set' | 'missing' | 'optional' | 'broken'
|
|
15
|
+
|
|
16
|
+
export type ConfigTopic = {
|
|
17
|
+
id: ConfigTopicId
|
|
18
|
+
state: ConfigState
|
|
19
|
+
/** one line: where it stands */
|
|
20
|
+
line: string
|
|
21
|
+
facts: Fact[]
|
|
22
|
+
/** the acts that set it, in the console; a form of the page when the topic has one stands before them */
|
|
23
|
+
acts: { what: string; command: string }[]
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type ConfigTarget = { id: string; label: string; on: boolean; where: string; /** a bucket the row holds itself: the page can try it */ own: boolean }
|
|
27
|
+
|
|
28
|
+
export type ConfigInputs = {
|
|
29
|
+
machine: string
|
|
30
|
+
house: { path: string; repos: number } | null
|
|
31
|
+
/** the house config did not load, and why */
|
|
32
|
+
configWhy: string | null
|
|
33
|
+
identities: string[]
|
|
34
|
+
/** null: the list is another machine's (this one joined its hq) or could not be read */
|
|
35
|
+
targets: ConfigTarget[] | null
|
|
36
|
+
/** the backup status: its headline, its worst, whether anything was ever set up */
|
|
37
|
+
backups: { words: string; worst: 'ok' | 'warn' | 'danger' | 'dim'; notSetUp: boolean } | null
|
|
38
|
+
/** the secrets the places set here name, and whether each is held; never a value */
|
|
39
|
+
named: { name: string; by: string; held: boolean | null }[]
|
|
40
|
+
/** how many names the house registers */
|
|
41
|
+
registered: number
|
|
42
|
+
claude: { bin: boolean; accounts: { name: string; folder: string }[] }
|
|
43
|
+
github: { bin: boolean; users: string[] }
|
|
44
|
+
hq: { role: 'carries' | 'joined' | null; machines: number | null }
|
|
45
|
+
media: { bucket: string; region: string } | null
|
|
46
|
+
vault: 'here' | 'master' | 'none'
|
|
47
|
+
remote: string | null
|
|
48
|
+
notify: boolean
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type ConfigPage = { at: number; machine: string; targets: ConfigTarget[] | null; topics: ConfigTopic[] }
|
|
52
|
+
|
|
53
|
+
const ok = (text: string): Fact => ({ text, tone: 'ok' })
|
|
54
|
+
const dim = (text: string): Fact => ({ text, tone: 'dim' })
|
|
55
|
+
const warn = (text: string): Fact => ({ text, tone: 'warn' })
|
|
56
|
+
const list = (xs: readonly string[]): string => xs.join(', ')
|
|
57
|
+
const n = (count: number, one: string, many = `${one}s`): string => `${count} ${count === 1 ? one : many}`
|
|
58
|
+
|
|
59
|
+
function backups(i: ConfigInputs): ConfigTopic {
|
|
60
|
+
const acts = [
|
|
61
|
+
{ what: 'the newest copy, back on the disk', command: 'sk backup targets get <id> --to ~/restored' },
|
|
62
|
+
]
|
|
63
|
+
if (i.targets == null) return { id: 'backups', state: i.hq.role === 'joined' ? 'optional' : 'broken', line: i.hq.role === 'joined' ? 'the list is kept on the machine that carries the hq' : 'the list of targets could not be read', facts: [dim('open this page on the machine that carries the hq to change it')], acts: [] }
|
|
64
|
+
const facts = i.targets.map((t) => (t.on ? ok : dim)(`${t.label}, ${t.where}${t.on ? '' : ': off'}`))
|
|
65
|
+
const b = i.backups
|
|
66
|
+
// the status judges: the list alone never says that a copy works
|
|
67
|
+
const state: ConfigState = i.targets.length === 0 || b?.notSetUp === true ? 'missing' : b?.worst === 'ok' ? 'set' : 'broken'
|
|
68
|
+
const first = i.targets.some((t) => t.on) ? 'no copy has left this machine yet: the daemon sends the first one at its next look' : 'every target is off: no copy leaves this machine'
|
|
69
|
+
return { id: 'backups', state, line: i.targets.length === 0 ? 'no target yet: what this machine keeps is on its own disk alone' : b == null ? 'the backup status does not answer' : b.notSetUp ? first : b.words, facts, acts }
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function secrets(i: ConfigInputs): ConfigTopic {
|
|
73
|
+
const missing = i.named.filter((x) => x.held === false)
|
|
74
|
+
const unread = i.named.filter((x) => x.held == null)
|
|
75
|
+
const where = i.vault === 'none' ? "this Mac's keychain" : i.vault === 'here' ? 'the vault on this machine' : 'the vault on the machine that carries the hq'
|
|
76
|
+
return {
|
|
77
|
+
id: 'secrets',
|
|
78
|
+
state: missing.length > 0 ? 'broken' : 'set',
|
|
79
|
+
line: missing.length > 0 ? `${n(missing.length, 'secret')} named by a setting ${missing.length === 1 ? 'is' : 'are'} not stored` : `kept in ${where}`,
|
|
80
|
+
facts: [
|
|
81
|
+
...(i.registered === 0 ? [] : [dim(`${n(i.registered, 'name')} in the house registry`)]),
|
|
82
|
+
...i.named.map((x): Fact => (x.held === true ? ok(`${x.name}: stored, for ${x.by}`) : x.held == null ? dim(`${x.name}: not read, for ${x.by}`) : warn(`${x.name}: not stored, for ${x.by}`))),
|
|
83
|
+
...(unread.length > 0 ? [dim('a name not read is out of the reach of this house, or its store did not answer')] : []),
|
|
84
|
+
],
|
|
85
|
+
acts: [{ what: 'store one from a terminal, its value asked and never shown', command: 'sk secret set <name>' }, { what: 'the names this repo may read', command: 'sk secret list' }],
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function claude(i: ConfigInputs): ConfigTopic {
|
|
90
|
+
const { bin, accounts } = i.claude
|
|
91
|
+
return {
|
|
92
|
+
id: 'claude',
|
|
93
|
+
state: accounts.length > 0 ? 'set' : 'missing',
|
|
94
|
+
line: accounts.length > 0 ? `${n(accounts.length, 'account')} on this machine` : bin ? 'Claude Code is installed, no session was started yet' : 'Claude Code is not installed',
|
|
95
|
+
facts: accounts.map((a) => ok(`${a.name}, in ~/${a.folder}`)),
|
|
96
|
+
acts: [
|
|
97
|
+
{ what: 'another account: start Claude Code once in its own folder and log in; shipkit finds every ~/.claude-<name>', command: 'CLAUDE_CONFIG_DIR="$HOME/.claude-work" claude' },
|
|
98
|
+
],
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** the page, from what was read */
|
|
103
|
+
export function configurationPage(i: ConfigInputs, at = Date.now()): ConfigPage {
|
|
104
|
+
const config = i.configWhy == null ? [] : [warn(`the house config does not load: ${i.configWhy}`)]
|
|
105
|
+
const topics: ConfigTopic[] = [
|
|
106
|
+
backups(i),
|
|
107
|
+
secrets(i),
|
|
108
|
+
claude(i),
|
|
109
|
+
{
|
|
110
|
+
id: 'github',
|
|
111
|
+
state: i.github.users.length > 0 ? 'set' : 'optional',
|
|
112
|
+
line: i.github.users.length > 0 ? `logged in as ${list(i.github.users)}` : i.github.bin ? 'gh is installed, no account is logged in' : 'gh is not installed: a repo takes any git remote by hand',
|
|
113
|
+
facts: [],
|
|
114
|
+
acts: [...(i.github.bin ? [] : [{ what: 'the GitHub cli', command: 'brew install gh' }]), { what: 'log in', command: 'gh auth login' }, { what: 'a remote of any host, for a repo', command: 'git remote add origin <url>' }],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: 'house',
|
|
118
|
+
state: i.house == null ? 'missing' : i.configWhy != null ? 'broken' : 'set',
|
|
119
|
+
line: i.house == null ? 'no house on this machine' : `${i.house.path}, ${n(i.house.repos, 'repo')}`,
|
|
120
|
+
facts: [...config, ...(i.house == null ? [] : [dim('its wiki loads first in every repo; its repo.config.ts holds the settings of every topic with no form here')])],
|
|
121
|
+
acts: [{ what: 'make one, and wire the repo you stand in', command: 'sk setup' }, { what: 'every key of its config', command: 'sk config-keys' }],
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
id: 'identities',
|
|
125
|
+
state: i.identities.length > 0 ? 'set' : 'optional',
|
|
126
|
+
line: i.identities.length > 0 ? list(i.identities) : 'none: no repo has to name one',
|
|
127
|
+
facts: [dim('an identity is a folder of the house wiki: the name, the handles and the voice a repo uses in public')],
|
|
128
|
+
acts: [{ what: 'the identities of this house', command: 'sk identities' }],
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: 'machines',
|
|
132
|
+
state: i.hq.role == null ? 'broken' : 'set',
|
|
133
|
+
line: i.hq.role === 'carries' ? `this machine carries the hq${i.hq.machines == null ? '' : `, ${n(i.hq.machines, 'machine')} in it`}` : i.hq.role === 'joined' ? 'this machine joined the hq of another' : 'its role toward an hq is not known yet: the daemon settles it at its start',
|
|
134
|
+
facts: [],
|
|
135
|
+
acts: [{ what: 'a join code for another Mac, here', command: 'sk hq invite' }, { what: 'join, on the other Mac', command: 'sk hq join <url> <code>' }],
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
id: 'media',
|
|
139
|
+
state: i.media == null ? 'optional' : 'set',
|
|
140
|
+
line: i.media == null ? 'no bucket: every file stays on this machine' : `the bucket ${i.media.bucket}, ${i.media.region}`,
|
|
141
|
+
facts: [dim('a private S3 bucket that keeps the media of every repo')],
|
|
142
|
+
acts: [{ what: 'in the house config', command: "serve: { mediaSpace: { endpoint: 'https://s3.example.com', bucket: 'my-media', region: 'us-east-1', path: true, key: { accessKeyId: 'media/id', secretAccessKey: 'media/secret' } } }" }],
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
id: 'vault',
|
|
146
|
+
state: i.vault === 'none' ? 'optional' : 'set',
|
|
147
|
+
line: i.vault === 'here' ? 'runs on this machine' : i.vault === 'master' ? 'read from the machine that carries the hq' : "none: secrets are in this Mac's keychain, which is enough for one Mac",
|
|
148
|
+
facts: [dim('a vault is for several machines that share their secrets')],
|
|
149
|
+
acts: [{ what: 'how it stands', command: 'sk vault status' }],
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
id: 'remote',
|
|
153
|
+
state: i.remote == null ? 'optional' : 'set',
|
|
154
|
+
line: i.remote == null ? 'this machine only: no tailnet name is known' : `reached at ${i.remote} on your tailnet`,
|
|
155
|
+
facts: [dim('with Tailscale on this Mac and on a phone, the hub opens on the phone')],
|
|
156
|
+
acts: [{ what: 'Tailscale, once installed', command: 'tailscale up' }],
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: 'notifications',
|
|
160
|
+
state: i.notify ? 'set' : 'optional',
|
|
161
|
+
line: i.notify ? 'a command of the house config sends them' : 'none off this machine',
|
|
162
|
+
facts: [],
|
|
163
|
+
acts: [{ what: 'in the house config: a command that takes a line', command: "notifyCommand: 'my-notify {message}'" }],
|
|
164
|
+
},
|
|
165
|
+
]
|
|
166
|
+
return { at, machine: i.machine, targets: i.targets, topics }
|
|
167
|
+
}
|
package/src/home/daemon-jobs.ts
CHANGED
|
@@ -67,6 +67,11 @@ async function targetsJob(now: number): Promise<string[]> {
|
|
|
67
67
|
if ('why' in ends) return { why: `no key yet: ${ends.why}` }
|
|
68
68
|
return { put: async (key, bytes) => void (await putStream(ends.to, key, new Blob([bytes.slice()]).stream(), { max: bytes.length })) }
|
|
69
69
|
},
|
|
70
|
+
bucket: async (a) => {
|
|
71
|
+
const [{ bucketPut }, { houseBucket }] = await Promise.all([import('../media-store/backup/bucket-target.ts'), import('./house-bucket.ts')])
|
|
72
|
+
const c = await houseBucket(a)
|
|
73
|
+
return 'why' in c ? c : { put: (key, bytes) => bucketPut(c, key, bytes) }
|
|
74
|
+
},
|
|
70
75
|
},
|
|
71
76
|
})
|
|
72
77
|
}
|