rvlib-shipkit 2.27.0 → 2.28.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 +16 -0
- package/package.json +1 -1
- package/src/agent-time/hooks.ts +10 -3
- package/src/agent-time/live.ts +11 -5
- package/src/agent-time/registry.ts +289 -0
- package/src/agent-time/store.ts +2 -2
- package/src/annex/born.ts +2 -2
- package/src/annex/offload.ts +12 -11
- package/src/asks/ask-after.ts +6 -2
- package/src/asks/ask-bar-fold.ts +57 -0
- package/src/asks/ask-migrate.ts +280 -0
- package/src/asks/ask-steps-fold.ts +166 -0
- package/src/asks/ask-store.ts +586 -0
- package/src/assets/kits/identity-kit.ts +106 -38
- package/src/assets/kits/poster-thumbnail.ts +282 -0
- package/src/checks/SK003-claude-md-shape.check.ts +92 -25
- package/src/checks/SK004-gitignore-policy.check.ts +8 -4
- package/src/checks/SK013-one-way-in-policy.check.ts +10 -0
- package/src/checks/SK026-asks-autoclose.check.ts +9 -23
- package/src/checks/SK038-speaks-as.check.ts +3 -3
- package/src/checks/SK042-post-kinds.check.ts +26 -24
- package/src/checks/SK049-thread-answers-hook.check.ts +81 -0
- package/src/checks/SK050-retired-commands.check.ts +127 -0
- package/src/cli/cmd_Asks.ts +204 -53
- package/src/cli/cmd_Backup.ts +151 -8
- package/src/cli/cmd_Calls.ts +1 -0
- package/src/cli/cmd_Commands.ts +140 -34
- package/src/cli/cmd_Contracts.ts +1 -0
- package/src/cli/cmd_Keys.ts +1 -0
- package/src/cli/cmd_Lanes.ts +15 -4
- package/src/cli/cmd_Messages.ts +152 -1
- package/src/cli/cmd_Needs.ts +1 -0
- package/src/cli/cmd_Review.ts +931 -229
- package/src/cli/cmd_Secret.ts +255 -34
- package/src/cli/cmd_Social.ts +36 -33
- package/src/cli/cmd_SocialDrafts.ts +235 -0
- package/src/cli/cmd_Sound.ts +22 -1
- package/src/cli/cmd_Start.ts +3 -2
- package/src/cli/cmd_ThreadHolds.ts +34 -0
- package/src/cli/cmd_ThreadKinds.ts +146 -0
- package/src/cli/cmd_ThreadReflect.ts +83 -0
- package/src/cli/cmd_ThreadSyncNeeds.ts +62 -0
- package/src/cli/cmd_Vault.ts +1 -1
- package/src/cli/cmd_When.ts +1 -0
- package/src/cli/family-help.ts +2 -2
- package/src/cli/family-pages.ts +1 -1
- package/src/cli/kit/builtins.ts +1 -0
- package/src/cli/kit/verb.ts +6 -2
- package/src/cli/registry.ts +21 -2
- package/src/cli.ts +5 -2
- package/src/collections/actions.ts +25 -74
- package/src/collections/collection-types.ts +9 -5
- package/src/collections/md-body.ts +5 -3
- package/src/collections/pings.ts +13 -6
- package/src/collections/providers.ts +53 -61
- package/src/collections/reflections.ts +9 -4
- package/src/core/discover-checks.ts +18 -3
- package/src/core/git.ts +31 -0
- package/src/core/house-layout.ts +17 -0
- package/src/core/layout.ts +10 -5
- package/src/core/locked-write.ts +4 -1
- package/src/core/machine-db.ts +5 -3
- package/src/core/migrate-layout.ts +8 -10
- package/src/home/activity.ts +8 -15
- package/src/home/daemon-jobs.ts +13 -1
- package/src/home/home-paths.ts +6 -3
- package/src/home/home-routes.ts +8 -0
- package/src/home/inbox-shape.ts +233 -100
- package/src/home/inbox.ts +26 -71
- package/src/home/machine-fold.ts +10 -15
- package/src/home/machine-host.ts +19 -1
- package/src/home/other-macs.ts +2 -2
- package/src/home/serve-web.ts +6 -5
- package/src/home/space-page.ts +1 -1
- package/src/home/vault-page.ts +51 -17
- package/src/home/vault-words.ts +2 -2
- package/src/hooks/one-way-in-guard.ts +24 -2
- package/src/hq/files-send.ts +27 -28
- package/src/hq/hq-db.ts +4 -1
- package/src/hq/hq-local.ts +37 -4
- package/src/hq/hq-routes.ts +10 -2
- package/src/hq/hq-store.ts +6 -2
- package/src/hq/kinds/ask.ts +6 -6
- package/src/hq/outbox.ts +5 -3
- package/src/hq/replica.ts +1 -2
- package/src/hq/vault-route.ts +112 -0
- package/src/identities/collection.ts +2 -2
- package/src/identities/identities.ts +9 -8
- package/src/identities/machine-route.ts +8 -3
- package/src/ledger/db.ts +8 -1
- package/src/media-store/backup/daemon.ts +48 -8
- package/src/media-store/backup/keys.ts +1 -1
- package/src/media-store/backup/manifest.ts +20 -2
- package/src/media-store/backup/prune.ts +365 -0
- package/src/media-store/backup/retention.ts +122 -0
- package/src/media-store/backup/run.ts +14 -8
- package/src/media-store/backup/sources.ts +18 -17
- package/src/media-store/backup/thread-copy.ts +340 -0
- package/src/media-store/copy/config.ts +3 -4
- package/src/media-store/copy/store.ts +2 -2
- package/src/media-store/db.ts +2 -2
- package/src/media-store/forget.ts +118 -0
- package/src/media-store/purge.ts +3 -2
- package/src/media-store/space-listing.ts +20 -4
- package/src/media-store/space.ts +6 -5
- package/src/messages/guard.ts +49 -0
- package/src/messages/model.ts +1 -1
- package/src/messages/objects.ts +201 -0
- package/src/messages/routes.ts +2 -2
- package/src/messages/score.ts +1 -1
- package/src/messages/write.ts +285 -0
- package/src/pages/frame-client.ts +181 -4
- package/src/reflections/reflections-queue.ts +1 -1
- package/src/release/gate-checkout.ts +2 -1
- package/src/release/git-facts.ts +3 -2
- package/src/release/public-clean.ts +3 -2
- package/src/repo-config.ts +40 -18
- package/src/review/anim.ts +1 -1
- package/src/review/answer-kinds.ts +131 -0
- package/src/review/band.ts +53 -0
- package/src/review/branch-hold.ts +84 -0
- package/src/review/card-db.ts +16 -6
- package/src/review/card-rows.ts +4 -3
- package/src/review/cells.ts +297 -65
- package/src/review/close.ts +92 -0
- package/src/review/draft-card.ts +8 -16
- package/src/review/draft-model.ts +2 -2
- package/src/review/events.ts +171 -0
- package/src/review/format.ts +128 -14
- package/src/review/glyphs.ts +63 -0
- package/src/review/gone.ts +1 -1
- package/src/review/holds-sync.ts +62 -0
- package/src/review/holds.ts +85 -0
- package/src/review/house-kind-defs.ts +41 -0
- package/src/review/inbox-hook.ts +22 -9
- package/src/review/inbox-read.ts +201 -0
- package/src/review/instructions.ts +199 -0
- package/src/review/kind-apply.ts +61 -0
- package/src/review/kind-catalog.ts +96 -0
- package/src/review/kinds.ts +278 -0
- package/src/review/lane-ask.ts +109 -0
- package/src/review/model.ts +396 -86
- package/src/review/move.ts +3 -3
- package/src/review/need-address.ts +15 -0
- package/src/review/need-threads.ts +93 -0
- package/src/review/object-card.ts +48 -0
- package/src/review/object-read.ts +31 -0
- package/src/review/owner-verdict.ts +36 -0
- package/src/review/parties.ts +182 -0
- package/src/review/previews.ts +3 -1
- package/src/review/projections.ts +235 -0
- package/src/review/referring.ts +54 -0
- package/src/review/reflection-object.ts +195 -0
- package/src/review/routes.ts +137 -32
- package/src/review/secret-route.ts +80 -0
- package/src/review/snooze.ts +38 -0
- package/src/review/stage-card.ts +4 -4
- package/src/review/store.ts +366 -85
- package/src/review/supersede.ts +116 -0
- package/src/review/take-back.ts +52 -0
- package/src/review/thread-fold.ts +20 -7
- package/src/review/threads.ts +236 -39
- package/src/review/traces.ts +218 -0
- package/src/review/trailer-card.ts +2 -2
- package/src/review/unit.ts +71 -5
- package/src/review/verdict-items.ts +73 -0
- package/src/review/verdict-write.ts +15 -0
- package/src/review/wait.ts +85 -0
- package/src/review/watchers.ts +22 -9
- package/src/scaffold/files/claude-settings-local.json +2 -0
- package/src/secrets/archive-mark.ts +52 -0
- package/src/secrets/archive.ts +83 -0
- package/src/secrets/copy.ts +14 -14
- package/src/secrets/keychain-write.ts +48 -0
- package/src/secrets/keychain.ts +8 -5
- package/src/secrets/lapse-mark.ts +33 -0
- package/src/secrets/lapse.ts +60 -0
- package/src/secrets/list.ts +16 -22
- package/src/secrets/manager.ts +31 -16
- package/src/secrets/read.ts +161 -33
- package/src/secrets/tail.ts +31 -0
- package/src/serve/hub-app/asks-page.tsx +2 -1
- package/src/serve/hub-app/auto-text.tsx +14 -6
- package/src/serve/hub-app/benign-errors.ts +15 -1
- package/src/serve/hub-app/card-head.tsx +49 -0
- package/src/serve/hub-app/check-view.tsx +3 -2
- package/src/serve/hub-app/code-copy.ts +35 -0
- package/src/serve/hub-app/col-card.tsx +31 -40
- package/src/serve/hub-app/col-list-page.tsx +5 -2
- package/src/serve/hub-app/col-tables-view.tsx +7 -4
- package/src/serve/hub-app/col-tables.ts +5 -5
- package/src/serve/hub-app/cols-svc.ts +4 -79
- package/src/serve/hub-app/commands/commands-page.tsx +2 -1
- package/src/serve/hub-app/controls.css +83 -0
- package/src/serve/hub-app/frames-st.ts +17 -1
- package/src/serve/hub-app/git-view.tsx +3 -2
- package/src/serve/hub-app/home-st.ts +57 -6
- package/src/serve/hub-app/home-strip.css +1 -6
- package/src/serve/hub-app/home-strip.tsx +2 -1
- package/src/serve/hub-app/home.html +3 -0
- package/src/serve/hub-app/house-wiki-view.tsx +20 -0
- package/src/serve/hub-app/hub-app.tsx +48 -32
- package/src/serve/hub-app/hub-types.ts +2 -0
- package/src/serve/hub-app/hub.css +50 -61
- package/src/serve/hub-app/icons.tsx +14 -4
- package/src/serve/hub-app/identities-view.tsx +4 -3
- package/src/serve/hub-app/inbox-st.ts +203 -42
- package/src/serve/hub-app/inbox-view.tsx +189 -101
- package/src/serve/hub-app/inbox.css +47 -44
- package/src/serve/hub-app/index.html +3 -0
- package/src/serve/hub-app/instructions.css +30 -0
- package/src/serve/hub-app/keys.ts +5 -3
- package/src/serve/hub-app/machine-st.ts +2 -2
- package/src/serve/hub-app/machines-view.tsx +4 -11
- package/src/serve/hub-app/machines.css +0 -9
- package/src/serve/hub-app/markdown.css +51 -0
- package/src/serve/hub-app/md-copy.tsx +18 -40
- package/src/serve/hub-app/md.ts +25 -9
- package/src/serve/hub-app/media-view.tsx +2 -2
- package/src/serve/hub-app/messages/messages-page.tsx +2 -1
- package/src/serve/hub-app/messages/messages-st.ts +1 -1
- package/src/serve/hub-app/messages.css +0 -1
- package/src/serve/hub-app/objects.css +51 -0
- package/src/serve/hub-app/page-keys.ts +1 -1
- package/src/serve/hub-app/pages-frames.tsx +11 -1
- package/src/serve/hub-app/palette-st.ts +4 -4
- package/src/serve/hub-app/pane-boundary.tsx +72 -0
- package/src/serve/hub-app/pane-errors.ts +54 -0
- package/src/serve/hub-app/plan-view.tsx +3 -2
- package/src/serve/hub-app/planned-view.tsx +3 -3
- package/src/serve/hub-app/planned.css +0 -4
- package/src/serve/hub-app/processes-view.tsx +3 -2
- package/src/serve/hub-app/project-list.css +5 -13
- package/src/serve/hub-app/project-list.tsx +3 -6
- package/src/serve/hub-app/projects-svc.ts +6 -2
- package/src/serve/hub-app/readme.css +9 -15
- package/src/serve/hub-app/reflections-page.tsx +54 -1
- package/src/serve/hub-app/releases/releases-page.tsx +3 -2
- package/src/serve/hub-app/releases.css +0 -1
- package/src/serve/hub-app/review/code-colors.ts +30 -0
- package/src/serve/hub-app/review/diff-view.tsx +75 -0
- package/src/serve/hub-app/review/dock.tsx +104 -0
- package/src/serve/hub-app/review/draft-card.tsx +2 -2
- package/src/serve/hub-app/review/group-block.tsx +209 -0
- package/src/serve/hub-app/review/instructions-view.tsx +116 -0
- package/src/serve/hub-app/review/item-verdict.tsx +38 -0
- package/src/serve/hub-app/review/kind-states.tsx +193 -0
- package/src/serve/hub-app/review/kind-view.tsx +1 -37
- package/src/serve/hub-app/review/kit.tsx +57 -54
- package/src/serve/hub-app/review/lane-bar.tsx +64 -0
- package/src/serve/hub-app/review/object-card.tsx +62 -0
- package/src/serve/hub-app/review/object-panel.tsx +179 -0
- package/src/serve/hub-app/review/question-views.tsx +385 -0
- package/src/serve/hub-app/review/review-cells.tsx +86 -105
- package/src/serve/hub-app/review/review-list.tsx +104 -47
- package/src/serve/hub-app/review/review-page.tsx +5 -4
- package/src/serve/hub-app/review/review-st.ts +68 -28
- package/src/serve/hub-app/review/review-thread.tsx +171 -40
- package/src/serve/hub-app/review/review-views.tsx +35 -31
- package/src/serve/hub-app/review/thread-close.tsx +124 -0
- package/src/serve/hub-app/review/thread-control.tsx +4 -4
- package/src/serve/hub-app/review/thread-st.ts +222 -22
- package/src/serve/hub-app/review/trailer-card.tsx +1 -1
- package/src/serve/hub-app/review/trailer-timeline.tsx +2 -2
- package/src/serve/hub-app/review.css +216 -57
- package/src/serve/hub-app/section-head.tsx +51 -0
- package/src/serve/hub-app/social/calendar.tsx +5 -11
- package/src/serve/hub-app/social/comms-page.tsx +23 -10
- package/src/serve/hub-app/social/kit.tsx +8 -15
- package/src/serve/hub-app/social/next-release.tsx +3 -5
- package/src/serve/hub-app/social/post-card.tsx +3 -0
- package/src/serve/hub-app/social/post-page.tsx +80 -0
- package/src/serve/hub-app/social/problems.tsx +5 -9
- package/src/serve/hub-app/social/social-model.ts +13 -5
- package/src/serve/hub-app/social/social-page.tsx +1 -1
- package/src/serve/hub-app/social/social-st.ts +42 -5
- package/src/serve/hub-app/social.css +7 -17
- package/src/serve/hub-app/space.css +1 -1
- package/src/serve/hub-app/stores/stores-page.tsx +6 -2
- package/src/serve/hub-app/thread-row.tsx +101 -0
- package/src/serve/hub-app/time-ago.tsx +3 -2
- package/src/serve/hub-app/time-view.tsx +2 -1
- package/src/serve/hub-app/time.css +2 -5
- package/src/serve/hub-app/tree-row.tsx +1 -9
- package/src/serve/hub-app/vault-view.tsx +4 -4
- package/src/serve/hub-app/veille/veille-page.tsx +2 -11
- package/src/serve/hub-app/veille.css +0 -1
- package/src/serve/hub-app/waiting-svc.ts +4 -4
- package/src/serve/hub-app/when-view.tsx +6 -3
- package/src/serve/hub-app/wiki-st.ts +30 -4
- package/src/serve/hub-app/wikis-view.tsx +4 -3
- package/src/serve/hub-runtime.ts +20 -6
- package/src/serve/project-gutter-route.ts +16 -6
- package/src/serve/project-gutter.ts +6 -53
- package/src/serve/same-origin.ts +3 -0
- package/src/serve/secret-gate.ts +21 -0
- package/src/serve/serve-hub.ts +29 -20
- package/src/serve/tailnet-caller.ts +117 -0
- package/src/shipkit.ts +2 -2
- package/src/site/desk.ts +2 -2
- package/src/smoke/run-smoke.ts +3 -4
- package/src/social/brands.ts +4 -0
- package/src/social/card-drafts.ts +11 -19
- package/src/social/desk-index.ts +34 -13
- package/src/social/drafts.ts +4 -4
- package/src/social/import-drafts.ts +244 -0
- package/src/social/kind-pages.ts +3 -3
- package/src/social/kinds.ts +1 -1
- package/src/social/load.ts +89 -64
- package/src/social/media-kind.ts +68 -161
- package/src/social/media-of.ts +5 -4
- package/src/social/open.ts +3 -2
- package/src/social/post-object.ts +120 -0
- package/src/social/post-sources.ts +136 -0
- package/src/social/post-text.ts +103 -0
- package/src/social/posts.ts +378 -0
- package/src/social/presence.ts +7 -5
- package/src/social/publish/index.ts +17 -5
- package/src/social/publish/secret.ts +2 -2
- package/src/social/release-stage.ts +58 -57
- package/src/social/routes.ts +64 -24
- package/src/social/stage.ts +42 -57
- package/src/social/text.ts +4 -3
- package/src/social/thumbnail.ts +135 -43
- package/src/social/tracker.ts +1 -1
- package/src/social/writes.ts +12 -29
- package/src/stores/desk.ts +16 -11
- package/src/stores/unit.ts +2 -2
- package/src/trailer/sound/eleven.ts +33 -3
- package/src/urls/rows.ts +1 -1
- package/src/vault/vault-http.ts +11 -3
- package/src/vault/vault-import.ts +6 -1
- package/src/veille/identity.ts +2 -2
- package/src/wiki/graph-pages.ts +13 -1
- package/src/wiki/scan-md.ts +1 -1
- package/src/asks/asks-queue.ts +0 -424
- package/src/messages/suggest.ts +0 -96
- package/src/social/migrate.ts +0 -123
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// the asks of a repo's `.shipkit/asks/` files moved into its thread store (asks/ask-store.ts), every fact of each file,
|
|
2
|
+
// open, done and declined: a thread opened for an ask that has none, the facts and the status added to one that has.
|
|
3
|
+
// Re-runnable: an ask whose thread already says what its file says is left alone. The files stay on disk: their
|
|
4
|
+
// repo's agent removes them by git once `sk asks migrate` compares every field equal
|
|
5
|
+
import { existsSync, lstatSync, readdirSync, readFileSync, statSync } from 'fs'
|
|
6
|
+
import { join } from 'path'
|
|
7
|
+
import { ASK_FILES_DIR } from '../core/layout.ts'
|
|
8
|
+
import { mutateLease, withMutateLease } from '../core/locked-write.ts'
|
|
9
|
+
import { askKindOf, type AskHead, type ReviewItem } from '../review/model.ts'
|
|
10
|
+
import { appendMessage, openThread, readAll, storeDir, updateHead } from '../review/store.ts'
|
|
11
|
+
import { askStateOf, asideUntil, membersOf, threadOfAddress, type Thread } from '../review/threads.ts'
|
|
12
|
+
import { afterMs } from './ask-after.ts'
|
|
13
|
+
import { askAddress, askOfThread, isClosed, parseWaits, postQuestions, questionsOf, type Ask, type AskStatus } from './ask-store.ts'
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/** one ask file as it reads: `rel` its path under the folder (`done/003-x.md`), `closedFrom` where its closed day came
|
|
17
|
+
* from when the file names none */
|
|
18
|
+
export type FileAsk = {
|
|
19
|
+
rel: string
|
|
20
|
+
id: string
|
|
21
|
+
status: AskStatus
|
|
22
|
+
head: AskHead
|
|
23
|
+
closed: string | null
|
|
24
|
+
closedFrom: 'file' | 'git' | 'mtime' | null
|
|
25
|
+
after: string | null
|
|
26
|
+
title: string
|
|
27
|
+
body: string
|
|
28
|
+
why: string | null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const splitFront = (md: string): { head: string[]; body: string[] } | null => {
|
|
32
|
+
const lines = md.split(/\r?\n/)
|
|
33
|
+
const end = lines[0]?.trim() === '---' ? lines.findIndex((l, i) => i > 0 && l.trim() === '---') : -1
|
|
34
|
+
return end === -1 ? null : { head: lines.slice(1, end), body: lines.slice(end + 1) }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** the day git last committed the file, null when git cannot say */
|
|
38
|
+
function gitDay(root: string, path: string): string | null {
|
|
39
|
+
const p = Bun.spawnSync(['git', '-C', root, 'log', '-1', '--format=%cs', '--', path], { stdout: 'pipe', stderr: 'ignore' })
|
|
40
|
+
const d = p.stdout.toString().trim()
|
|
41
|
+
return p.exitCode === 0 && /^\d{4}-\d{2}-\d{2}$/.test(d) ? d : null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** one ask file read: its front matter only for its keys, never its body. Throws, the file named, on a key that names
|
|
45
|
+
* nothing (a kind, a day, a status, a `waits:` with no words) */
|
|
46
|
+
export function readAskFile(root: string, rel: string): FileAsk {
|
|
47
|
+
const md = readFileSync(join(root, ASK_FILES_DIR, rel), 'utf8')
|
|
48
|
+
const f = splitFront(md)
|
|
49
|
+
if (f == null) throw new Error(`${rel}: no front matter`)
|
|
50
|
+
const fm = (key: string): string | null => f.head.join('\n').match(new RegExp(`^${key}:\\s*(.+)$`, 'm'))?.[1]?.trim() ?? null
|
|
51
|
+
const unq = (v: string | null): string | null => (v == null ? null : v.replace(/^"(.*)"$/, '$1'))
|
|
52
|
+
const status = fm('status') ?? 'open'
|
|
53
|
+
if (status !== 'open' && !isClosed(status)) throw new Error(`${rel}: status '${status}' is none of open, done, declined`)
|
|
54
|
+
const rawKind = fm('kind') ?? 'action'
|
|
55
|
+
const kind = askKindOf(rawKind)
|
|
56
|
+
if (kind == null) throw new Error(`${rel}: kind '${rawKind}' is no ask kind`)
|
|
57
|
+
const created = fm('created')
|
|
58
|
+
if (created == null || !/^\d{4}-\d{2}-\d{2}$/.test(created)) throw new Error(`${rel}: created '${created}' is no day`)
|
|
59
|
+
const day = (k: string): string | null => {
|
|
60
|
+
const v = fm(k)
|
|
61
|
+
if (v != null && !/^\d{4}-\d{2}-\d{2}$/.test(v)) throw new Error(`${rel}: ${k} '${v}' is no day`)
|
|
62
|
+
return v
|
|
63
|
+
}
|
|
64
|
+
const after = fm('after')
|
|
65
|
+
if (after != null && afterMs(after) == null) throw new Error(`${rel}: after '${after}' names no moment`)
|
|
66
|
+
const secrets = (fm('secret') ?? '').split(/[\s,]+/).filter((n) => n !== '')
|
|
67
|
+
const logins = (fm('login') ?? '').split(/[\s,]+/).filter((n) => n !== '')
|
|
68
|
+
const waits = parseWaits(fm('waits'), rel)
|
|
69
|
+
const check = fm('check')
|
|
70
|
+
const pinged = day('pinged')
|
|
71
|
+
const body = f.body.join('\n').trim()
|
|
72
|
+
const id = rel.replace(/^(done|declined)\//, '').replace(/\.md$/, '')
|
|
73
|
+
let closed = day('closed')
|
|
74
|
+
let closedFrom: FileAsk['closedFrom'] = closed != null ? 'file' : null
|
|
75
|
+
if (isClosed(status) && closed == null) {
|
|
76
|
+
const path = join(ASK_FILES_DIR, rel)
|
|
77
|
+
closed = gitDay(root, path)
|
|
78
|
+
closedFrom = 'git'
|
|
79
|
+
if (closed == null) {
|
|
80
|
+
const m = statSync(join(root, path)).mtime
|
|
81
|
+
closed = `${m.getFullYear()}-${String(m.getMonth() + 1).padStart(2, '0')}-${String(m.getDate()).padStart(2, '0')}`
|
|
82
|
+
closedFrom = 'mtime'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const declined = /^\*\*Declined\*\* by the owner on [\d-]+(?::\s*(.+))?$/m.exec(body)?.[1]?.trim() ?? null
|
|
86
|
+
const proof = /^\*\*Proof\*\*:\s*(\S+)/m.exec(body)?.[1] ?? null
|
|
87
|
+
return {
|
|
88
|
+
rel,
|
|
89
|
+
id,
|
|
90
|
+
status,
|
|
91
|
+
head: {
|
|
92
|
+
kind,
|
|
93
|
+
created,
|
|
94
|
+
blocks: unq(fm('blocks')) || '-',
|
|
95
|
+
...(check != null ? { check } : {}),
|
|
96
|
+
...(waits.length > 0 ? { waits } : {}),
|
|
97
|
+
...(secrets.length > 0 ? { secrets } : {}),
|
|
98
|
+
...(logins.length > 0 ? { logins } : {}),
|
|
99
|
+
...(pinged != null ? { pinged } : {}),
|
|
100
|
+
},
|
|
101
|
+
closed: isClosed(status) ? closed : null,
|
|
102
|
+
closedFrom: isClosed(status) ? closedFrom : null,
|
|
103
|
+
after,
|
|
104
|
+
title: /^# (.+)$/m.exec(body)?.[1]?.trim() ?? id,
|
|
105
|
+
body,
|
|
106
|
+
why: status === 'declined' ? declined : status === 'done' && proof != null ? `proof: ${proof}` : null,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const mdIn = (dir: string): string[] => {
|
|
111
|
+
try {
|
|
112
|
+
if (!lstatSync(dir).isDirectory()) return []
|
|
113
|
+
return readdirSync(dir).filter((f) => f.endsWith('.md') && f !== 'README.md').sort()
|
|
114
|
+
} catch {
|
|
115
|
+
return []
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** every ask file of a repo, open and archived, by its path under the folder; a file that does not read is named in
|
|
120
|
+
* `broken`. A copy of one ask in two folders is one ask: its archived copy */
|
|
121
|
+
export function askFiles(root: string): { asks: FileAsk[]; broken: string[] } {
|
|
122
|
+
const dir = join(root, ASK_FILES_DIR)
|
|
123
|
+
if (!existsSync(dir)) return { asks: [], broken: [] }
|
|
124
|
+
const by = new Map<string, FileAsk>()
|
|
125
|
+
const broken: string[] = []
|
|
126
|
+
for (const sub of ['', 'done/', 'declined/'])
|
|
127
|
+
for (const f of mdIn(join(dir, sub)))
|
|
128
|
+
try {
|
|
129
|
+
const a = readAskFile(root, `${sub}${f}`)
|
|
130
|
+
if (!by.has(a.id) || sub !== '') by.set(a.id, a)
|
|
131
|
+
} catch (e) {
|
|
132
|
+
broken.push((e as Error).message)
|
|
133
|
+
}
|
|
134
|
+
return { asks: [...by.values()].sort((a, b) => a.id.localeCompare(b.id)), broken }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** noon of a local day: a message dated then reads as that day in every time zone of the house */
|
|
138
|
+
const noonOf = (day: string): Date => new Date(`${day}T12:00:00`)
|
|
139
|
+
|
|
140
|
+
const same = (a: unknown, b: unknown): boolean => JSON.stringify(a) === JSON.stringify(b)
|
|
141
|
+
|
|
142
|
+
/** `owned`: its thread already held its facts before this run, so the store is its record: nothing of the file is
|
|
143
|
+
* written on it, and `what` names each field the store moved since */
|
|
144
|
+
export type MigrateLine = { id: string; did: 'opened' | 'updated' | 'owned'; what: string[] }
|
|
145
|
+
|
|
146
|
+
/** one repo's asks into its thread store, under the repo's asks lease; `go` false says what it would do and writes
|
|
147
|
+
* nothing. An ask whose thread holds its facts already is never written again: his decline or « done » in the store
|
|
148
|
+
* after a first run stays, whatever the file still says */
|
|
149
|
+
export async function migrateAsks(root: string, o: { go: boolean; lane?: string; now?: Date }): Promise<{ lines: MigrateLine[]; broken: string[] }> {
|
|
150
|
+
const leased = await withMutateLease(mutateLease(root, 'asks'), { label: 'asks migrate', print: () => {}, maxWaitMs: 45_000 }, () => migrateBody(root, o))
|
|
151
|
+
if (!leased.ok) throw new Error(`asks of ${root} not moved: ${leased.warn}`)
|
|
152
|
+
return leased.value
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
async function migrateBody(root: string, o: { go: boolean; lane?: string; now?: Date }): Promise<{ lines: MigrateLine[]; broken: string[] }> {
|
|
156
|
+
const store = storeDir(root)
|
|
157
|
+
const { asks, broken } = askFiles(root)
|
|
158
|
+
const now = o.now ?? new Date()
|
|
159
|
+
const who = o.lane ?? 'agent'
|
|
160
|
+
const lines: MigrateLine[] = []
|
|
161
|
+
const items = readAll(store).items
|
|
162
|
+
for (const f of asks) {
|
|
163
|
+
const address = askAddress(f.id)
|
|
164
|
+
const t = threadOfAddress(address, readAll(store).items)
|
|
165
|
+
if (t === null) {
|
|
166
|
+
if (o.go) await openFrom(store, f, who, now)
|
|
167
|
+
lines.push({ id: f.id, did: 'opened', what: [`a thread, ${f.status}${f.closedFrom != null && f.closedFrom !== 'file' ? ` (closed day from ${f.closedFrom})` : ''}`] })
|
|
168
|
+
continue
|
|
169
|
+
}
|
|
170
|
+
const h = t.head.item
|
|
171
|
+
if (h.ask !== undefined) {
|
|
172
|
+
// a run stopped between its two writes: the store never said a status, nor asked a question, so its file still is its record there
|
|
173
|
+
const finish: string[] = []
|
|
174
|
+
if (f.status !== 'open' && askStateOf(t) === null) {
|
|
175
|
+
finish.push(`its close, ${f.status}`)
|
|
176
|
+
if (o.go) appendMessage(store, h.id, { who: f.status === 'declined' ? 'owner' : who, askState: { state: f.status, why: f.why ?? `its record in git said ${f.status}${guessed(f)}` } }, { now: closeAt(t, f, now) })
|
|
177
|
+
}
|
|
178
|
+
if (f.status === 'open' && askStateOf(t) === null && neverAsked(t, f)) {
|
|
179
|
+
finish.push('its questions')
|
|
180
|
+
if (o.go) await postQuestions(store, h.id, wordsOf(f), { who, now })
|
|
181
|
+
}
|
|
182
|
+
if (finish.length > 0) lines.push({ id: f.id, did: 'updated', what: finish })
|
|
183
|
+
else lines.push({ id: f.id, did: 'owned', what: compareAsks(root, [f], items, now).map((d) => d.field) })
|
|
184
|
+
continue
|
|
185
|
+
}
|
|
186
|
+
const what = ['its facts']
|
|
187
|
+
if ((h.what ?? '').trim() !== f.body) what.push('its words as the file says them now')
|
|
188
|
+
if (o.go) updateHead(store, h.id, (cur) => (cur.ask !== undefined ? cur : { ...cur, ask: f.head, what: f.body }))
|
|
189
|
+
const was = askStateOf(t)?.state ?? 'open'
|
|
190
|
+
if (was !== f.status) {
|
|
191
|
+
what.push(`its status ${was} → ${f.status}`)
|
|
192
|
+
if (o.go) appendMessage(store, h.id, { who: f.status === 'declined' ? 'owner' : who, askState: { state: f.status, why: f.why ?? `its record in git said ${f.status}${guessed(f)}` } }, { now: closeAt(t, f, now) })
|
|
193
|
+
}
|
|
194
|
+
const until = f.status === 'open' && f.after != null ? afterMs(f.after) : null
|
|
195
|
+
if (until != null && until > now.getTime() && asideUntil(t, now) === null) {
|
|
196
|
+
what.push(`set aside until ${f.after}`)
|
|
197
|
+
if (o.go) appendMessage(store, h.id, { who, snooze: { until: new Date(until).toISOString() } }, { now })
|
|
198
|
+
}
|
|
199
|
+
if (f.status === 'open' && neverAsked(t, f)) {
|
|
200
|
+
what.push('its questions')
|
|
201
|
+
if (o.go) await postQuestions(store, h.id, wordsOf(f), { who, now })
|
|
202
|
+
}
|
|
203
|
+
lines.push({ id: f.id, did: 'updated', what })
|
|
204
|
+
}
|
|
205
|
+
return { lines, broken }
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/** the ask has questions to ask and its thread asked none: a run stopped before it posted them */
|
|
209
|
+
const neverAsked = (t: Thread, f: FileAsk): boolean =>
|
|
210
|
+
questionsOf(wordsOf(f)).length > 0 && !membersOf(t).some((x) => x.thread.some((m) => m.ask !== undefined))
|
|
211
|
+
|
|
212
|
+
const wordsOf = (f: FileAsk) => ({ kind: f.head.kind, title: f.title, body: f.body, secrets: f.head.secrets ?? [], logins: f.head.logins ?? [] })
|
|
213
|
+
|
|
214
|
+
/** what a closed day read from git or from the file's time says of itself */
|
|
215
|
+
const guessed = (f: FileAsk): string => (f.closedFrom === 'git' || f.closedFrom === 'mtime' ? `, its closed day read from ${f.closedFrom === 'git' ? "git's last commit of it" : "the file's time"}` : '')
|
|
216
|
+
|
|
217
|
+
/** when a close said now is dated: its closed day at noon, after every message the thread holds */
|
|
218
|
+
function closeAt(t: Thread, f: FileAsk, now: Date): Date {
|
|
219
|
+
if (f.closed == null) return now
|
|
220
|
+
const newest = Math.max(0, ...membersOf(t).flatMap((x) => [Date.parse(x.item.created), ...x.thread.map((m) => Date.parse(m.at))]))
|
|
221
|
+
return new Date(Math.max(noonOf(f.closed).getTime(), newest + 1))
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
async function openFrom(store: string, f: FileAsk, who: string, now: Date): Promise<void> {
|
|
225
|
+
const born = noonOf(f.head.created)
|
|
226
|
+
const x = await openThread(store, askAddress(f.id), { title: f.title, what: f.body, ask: f.head, now: born, ...(who !== 'agent' ? { lane: who } : {}) })
|
|
227
|
+
if (f.status === 'open') {
|
|
228
|
+
await postQuestions(store, x.id, wordsOf(f), { who, now: born })
|
|
229
|
+
const until = f.after != null ? afterMs(f.after) : null
|
|
230
|
+
if (until != null && until > now.getTime()) appendMessage(store, x.id, { who, snooze: { until: new Date(until).toISOString() } }, { now })
|
|
231
|
+
return
|
|
232
|
+
}
|
|
233
|
+
const why = f.why ?? (guessed(f) !== '' ? guessed(f).slice(2) : '')
|
|
234
|
+
appendMessage(store, x.id, { who: f.status === 'declined' ? 'owner' : who, askState: { state: f.status, ...(why !== '' ? { why } : {}) } }, { now: noonOf(f.closed!) })
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export type FieldDiff = { id: string; field: string; file: unknown; store: unknown }
|
|
238
|
+
|
|
239
|
+
/** every field of every ask file against its ask in the store: an empty list, the store says what the files say */
|
|
240
|
+
export function compareAsks(root: string, files: readonly FileAsk[], items: readonly ReviewItem[] = readAll(storeDir(root)).items, now = new Date()): FieldDiff[] {
|
|
241
|
+
const out: FieldDiff[] = []
|
|
242
|
+
for (const f of files) {
|
|
243
|
+
const t = threadOfAddress(askAddress(f.id), items)
|
|
244
|
+
const a: Ask | null = t === null ? null : askOfThread(t, now)
|
|
245
|
+
if (a === null) {
|
|
246
|
+
out.push({ id: f.id, field: 'ask', file: f.rel, store: t === null ? 'no thread' : 'a thread with no ask facts' })
|
|
247
|
+
continue
|
|
248
|
+
}
|
|
249
|
+
const until = f.status === 'open' && f.after != null ? afterMs(f.after) : null
|
|
250
|
+
const want: Record<string, unknown> = {
|
|
251
|
+
status: f.status,
|
|
252
|
+
kind: f.head.kind,
|
|
253
|
+
created: f.head.created,
|
|
254
|
+
// a closed day the file never wrote was read from git: the day a thread already said wins over it
|
|
255
|
+
...(f.closedFrom === 'file' || f.status === 'open' ? { closed: f.closed } : {}),
|
|
256
|
+
blocks: f.head.blocks,
|
|
257
|
+
check: f.head.check ?? null,
|
|
258
|
+
waits: f.head.waits ?? [],
|
|
259
|
+
secrets: f.head.secrets ?? [],
|
|
260
|
+
logins: f.head.logins ?? [],
|
|
261
|
+
title: f.title,
|
|
262
|
+
body: f.body,
|
|
263
|
+
afterAt: until != null && until > now.getTime() ? until : null,
|
|
264
|
+
...(f.why != null ? { why: f.why } : {}),
|
|
265
|
+
}
|
|
266
|
+
for (const [k, v] of Object.entries(want)) {
|
|
267
|
+
const got = (a as unknown as Record<string, unknown>)[k]
|
|
268
|
+
if (!same(k === 'body' ? (got as string).trim() : got, v)) out.push({ id: f.id, field: k, file: v, store: got })
|
|
269
|
+
}
|
|
270
|
+
if (f.head.pinged != null && a.pinged !== f.head.pinged) out.push({ id: f.id, field: 'pinged', file: f.head.pinged, store: a.pinged })
|
|
271
|
+
}
|
|
272
|
+
return out
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** a repo's asks counted by status */
|
|
276
|
+
export const countsOf = (xs: readonly { status: AskStatus }[]): Record<AskStatus, number> => ({
|
|
277
|
+
open: xs.filter((x) => x.status === 'open').length,
|
|
278
|
+
done: xs.filter((x) => x.status === 'done').length,
|
|
279
|
+
declined: xs.filter((x) => x.status === 'declined').length,
|
|
280
|
+
})
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// the asks made before their instructions held their steps (wiki tools/shipkit/threads-asks.md, An ask's thread): their
|
|
2
|
+
// words on the head or in an instructions message, their steps a separate checklist question « The steps ». Each open
|
|
3
|
+
// one gets its words again as one instructions message whose steps are its own checklist, read by the grammar they were
|
|
4
|
+
// written in (only a `## N.` heading a step), his ticks kept by step title as steps done before he looked (no message is
|
|
5
|
+
// ever written in his name), the generated title and done lines dropped (the check stays a fact), the old checklist and
|
|
6
|
+
// the old words folded. An ask whose steps would read otherwise than its old checklist, beyond a step that told the
|
|
7
|
+
// agent, is left as it is and named. Re-runnable: an ask whose standing instructions carry their steps is left alone
|
|
8
|
+
import { mutateLease, withMutateLease } from '../core/locked-write.ts'
|
|
9
|
+
import { tellsTheAgent } from '../review/instructions.ts'
|
|
10
|
+
import { partyOf, type AskHead, type Message } from '../review/model.ts'
|
|
11
|
+
import { appendMessage, readAll, storeDir } from '../review/store.ts'
|
|
12
|
+
import { membersOf, orderedThreads, type Thread } from '../review/threads.ts'
|
|
13
|
+
import { currentInstructions, replacersOf } from '../review/supersede.ts'
|
|
14
|
+
import { askOpen } from '../review/answer-kinds.ts'
|
|
15
|
+
import { parseInstructions } from '../review/instructions.ts'
|
|
16
|
+
import { askOfThread, instructionsMessage, isClosed, postFields, stepKey, stepsAskOf, tickedTitles } from './ask-store.ts'
|
|
17
|
+
|
|
18
|
+
/** the old checklists of an ask's thread that its steps were: an agent's « The steps », not superseded */
|
|
19
|
+
const oldChecklists = (t: Thread): Message[] => {
|
|
20
|
+
const gone = replacersOf(membersOf(t))
|
|
21
|
+
return membersOf(t).flatMap((x) => x.thread.filter((m) => partyOf(m.who) === 'agent' && m.instructions === undefined && m.ask?.kind === 'checklist' && m.text === 'The steps' && !gone.has(m.id)))
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** the words without what an older `sk ask` generated around them: the `# <title>` line (the thread names it) and the
|
|
25
|
+
* `**Done when**` line of its check (a fact the hub folds under the steps) */
|
|
26
|
+
function cleanWords(body: string, title: string, check: string | null): string {
|
|
27
|
+
let out = body.trim()
|
|
28
|
+
if (out.startsWith(`# ${title}`)) out = out.slice(`# ${title}`.length)
|
|
29
|
+
if (check !== null) out = out.replace(`**Done when**: \`${check}\` exits 0`, '')
|
|
30
|
+
return out.replace(/\n{3,}/g, '\n\n').trim()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** an open secret field an agent asked beside the steps: moved into the step that names it */
|
|
34
|
+
const looseSecrets = (t: Thread): { id: string; name: string; login: boolean }[] => {
|
|
35
|
+
const members = membersOf(t)
|
|
36
|
+
const gone = replacersOf(members)
|
|
37
|
+
return members.flatMap((x) =>
|
|
38
|
+
x.thread.flatMap((m) => (partyOf(m.who) === 'agent' && m.step === undefined && m.ask?.kind === 'secret' && m.ask.secret && !gone.has(m.id) && askOpen(x.thread, m) ? [{ id: m.id, name: m.ask.secret.name, login: m.ask.secret.login === true }] : [])),
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** the lines outside a copy block that type `<tool> secret set <name>` in a terminal: the field in the step does it now */
|
|
43
|
+
const sentences = (line: string): string[] => line.split(/(?<=[.!?:])\s+/)
|
|
44
|
+
|
|
45
|
+
/** the step's words with the terminal way of storing these secrets gone (a copy block of `secret set <name>` lines
|
|
46
|
+
* alone, its lead in sentence « … paste it at the prompt: », a line that is the command alone), and `fields` (their
|
|
47
|
+
* field blocks) where the copy block was, else at the end. A sentence of prose that names the command keeps its words:
|
|
48
|
+
* only the field draws the box, and nothing he was told is lost */
|
|
49
|
+
export function moveStoreIntoFields(md: string, names: readonly string[], fields: string): string {
|
|
50
|
+
const esc = (s: string): string => s.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&')
|
|
51
|
+
const store = new RegExp(`secret set\\s+(${names.map(esc).join('|')})(\\s|$|\`|<)`)
|
|
52
|
+
const bare = new RegExp(`^\\s*[!$>]?\\s*(\\S*sk\\s+secret|\\S+-secret)\\s+set\\s+(${names.map(esc).join('|')})\\s*(<\\s*\\S+)?\\s*$`)
|
|
53
|
+
const out: string[] = []
|
|
54
|
+
let placed = false
|
|
55
|
+
const lines = md.split('\n')
|
|
56
|
+
for (let i = 0; i < lines.length; i++) {
|
|
57
|
+
const open = /^\s{0,3}(`{3,}|~{3,})\s*\S*\s*$/.exec(lines[i]!)
|
|
58
|
+
if (!open) {
|
|
59
|
+
if (!bare.test(lines[i]!)) out.push(lines[i]!)
|
|
60
|
+
continue
|
|
61
|
+
}
|
|
62
|
+
const end = lines.findIndex((l, k) => k > i && l.trim() === open[1])
|
|
63
|
+
if (end < 0) {
|
|
64
|
+
out.push(...lines.slice(i))
|
|
65
|
+
break
|
|
66
|
+
}
|
|
67
|
+
const inner = lines.slice(i + 1, end)
|
|
68
|
+
const kept = inner.filter((l) => !store.test(l))
|
|
69
|
+
if (kept.some((l) => l.trim() !== '')) out.push(lines[i]!, ...kept, lines[end]!)
|
|
70
|
+
else if (kept.length < inner.length) {
|
|
71
|
+
// the copy block held store lines only: it goes, the sentence that led into it too, the fields in its place
|
|
72
|
+
while (out.length > 0 && out.at(-1)!.trim() === '') out.pop()
|
|
73
|
+
const lead = out.at(-1)
|
|
74
|
+
if (lead !== undefined && /:\s*$/.test(lead)) {
|
|
75
|
+
const rest = sentences(lead).slice(0, -1).join(' ')
|
|
76
|
+
if (rest.trim() === '') out.pop()
|
|
77
|
+
else out[out.length - 1] = rest
|
|
78
|
+
}
|
|
79
|
+
if (!placed) out.push('', fields, '')
|
|
80
|
+
placed = true
|
|
81
|
+
} else out.push(lines[i]!, ...inner, lines[end]!)
|
|
82
|
+
i = end
|
|
83
|
+
}
|
|
84
|
+
if (!placed) out.push('', fields)
|
|
85
|
+
return out.join('\n').replace(/\n{3,}/g, '\n\n').trim()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** the `**Answer**:` line an older scaffold wrote under every ask: it says nothing the ask bar and « how the agent
|
|
89
|
+
* checks » do not; an Answer line with words of its own stays */
|
|
90
|
+
const ANSWER_TEMPLATE = /^\s*\*\*Answer\*\*\s*:\s*_?\(fill in \/ check off\b.*\)_?\s*$/i
|
|
91
|
+
const flat = (s: string): string => s.replace(/\s+/g, ' ').trim()
|
|
92
|
+
|
|
93
|
+
/** the words with each loose secret field moved into the step that names it, and the `**Answer**:` template line of an
|
|
94
|
+
* older scaffold gone */
|
|
95
|
+
export function withFields(body: string, numbered: boolean, loose: readonly { id: string; name: string; login: boolean }[]): { body: string; moved: string[] } {
|
|
96
|
+
const moved: string[] = []
|
|
97
|
+
const parts = parseInstructions(body, { numbered }).sections.map((s) => {
|
|
98
|
+
if (s.kind !== 'step') return s.md
|
|
99
|
+
const mine = loose.filter((q) => !moved.includes(q.id) && s.body.includes(q.name))
|
|
100
|
+
if (mine.length === 0) return `## ${s.heading}\n\n${s.body.trim()}`.trim()
|
|
101
|
+
moved.push(...mine.map((q) => q.id))
|
|
102
|
+
const fields = mine.map((q) => `\`\`\`secret ${q.name}${q.login ? ' login' : ''}\n\`\`\``).join('\n\n')
|
|
103
|
+
return `## ${s.heading}\n\n${moveStoreIntoFields(s.body, mine.map((q) => q.name), fields)}`
|
|
104
|
+
})
|
|
105
|
+
const out = parts.join('\n\n').split('\n').filter((l) => !ANSWER_TEMPLATE.test(l)).join('\n').replace(/\n{3,}/g, '\n\n').trim()
|
|
106
|
+
return { body: out, moved }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
type Plan = { t: Thread; id: string; body: string; title: string; facts: Omit<AskHead, 'created' | 'pinged'>; folds: string[]; old: string[]; steps: string[]; kept: string[]; at: number; numbered: boolean }
|
|
110
|
+
|
|
111
|
+
const sameSteps = (a: readonly string[], b: readonly string[]): boolean => a.length === b.length && a.every((s, i) => stepKey(s) === stepKey(b[i]!))
|
|
112
|
+
|
|
113
|
+
/** what an open ask needs: its steps in its instructions (an ask made before), or its loose secret fields in its steps
|
|
114
|
+
* and its Answer template gone (an ask whose instructions hold their steps); null when it needs nothing */
|
|
115
|
+
function planOf(t: Thread): Plan | null {
|
|
116
|
+
const a = askOfThread(t)
|
|
117
|
+
if (a === null || isClosed(a.status)) return null
|
|
118
|
+
const cur = currentInstructions(membersOf(t))
|
|
119
|
+
const ticked = tickedTitles(t)
|
|
120
|
+
const loose = looseSecrets(t)
|
|
121
|
+
const facts = cur?.instructions.ask ?? (({ created: _c, pinged: _p, ...rest }: AskHead) => rest)(t.head.item.ask!)
|
|
122
|
+
if (cur?.ask !== undefined) {
|
|
123
|
+
const was = cur.ask.options
|
|
124
|
+
const numbered = sameSteps(stepsAskOf(cur.text ?? '', { numbered: true })?.options ?? [], was)
|
|
125
|
+
const w = withFields(cur.text ?? '', numbered, loose)
|
|
126
|
+
if (w.moved.length === 0 && flat(w.body) === flat(cur.text ?? '')) return null
|
|
127
|
+
return { t, id: a.id, body: w.body, title: a.title, facts, folds: w.moved, old: was, steps: was, kept: was.filter((s) => ticked.has(stepKey(s))), at: Date.parse(cur.at) + 1, numbered }
|
|
128
|
+
}
|
|
129
|
+
const w = withFields(cleanWords(a.body, a.title, a.check), true, loose)
|
|
130
|
+
const steps = stepsAskOf(w.body, { numbered: true })?.options ?? []
|
|
131
|
+
const checklists = oldChecklists(t)
|
|
132
|
+
if (steps.length === 0 && checklists.length === 0) return null
|
|
133
|
+
const old = checklists.at(-1)?.ask?.options ?? []
|
|
134
|
+
const at = Math.max(Date.parse(cur?.at ?? t.head.item.created), ...checklists.map((m) => Date.parse(m.at))) + 1
|
|
135
|
+
return { t, id: a.id, body: w.body, title: a.title, facts, folds: [...checklists.map((m) => m.id), ...w.moved], old, steps, kept: steps.filter((s) => ticked.has(stepKey(s))), at, numbered: true }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** why a plan is not run: its steps read otherwise than its old checklist, a step that told the agent aside */
|
|
139
|
+
const differs = (p: Plan): string | null => {
|
|
140
|
+
const was = p.old.filter((s) => !tellsTheAgent(s)).map(stepKey)
|
|
141
|
+
const now = p.steps.map(stepKey)
|
|
142
|
+
return was.length === 0 || (was.length === now.length && was.every((s, i) => s === now[i])) ? null : `its words read ${p.steps.length} steps, its checklist had ${was.length}: left as it is, new instructions by hand (sk ask … --replaces)`
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export type StepsLine = { ask: string; old: string[]; steps: string[]; kept: string[]; left: string | null }
|
|
146
|
+
|
|
147
|
+
/** every open ask of the repo whose steps are not its instructions' own, counted, then (`go`) folded under the repo's
|
|
148
|
+
* asks lease. The new instructions are dated 1 ms after what they replace, so the fold neither makes its lane the
|
|
149
|
+
* thread's holder nor moves the thread in his « since you left ». `before`, `after`: the asks still to fold */
|
|
150
|
+
export async function foldSteps(root: string, o: { go: boolean; lane?: string }): Promise<{ before: number; lines: StepsLine[]; after: number }> {
|
|
151
|
+
const store = storeDir(root)
|
|
152
|
+
const plans = (): Plan[] => orderedThreads(readAll(store).items).flatMap((t) => planOf(t) ?? [])
|
|
153
|
+
const leased = await withMutateLease(mutateLease(root, 'asks'), { label: 'asks steps', print: () => {}, maxWaitMs: 45_000 }, async () => {
|
|
154
|
+
const todo = plans()
|
|
155
|
+
const lines = todo.map((p) => ({ ask: p.id, old: p.old, steps: p.steps, kept: p.kept, left: differs(p) }))
|
|
156
|
+
if (o.go)
|
|
157
|
+
for (const p of todo.filter((x) => differs(x) === null)) {
|
|
158
|
+
const who = o.lane ?? 'agent'
|
|
159
|
+
const ins = appendMessage(store, p.t.head.item.id, instructionsMessage({ who, title: p.title, body: p.body, facts: p.facts, folds: p.folds, ticked: new Set(p.kept.map(stepKey)), numbered: p.numbered }), { now: new Date(p.at) })
|
|
160
|
+
await postFields(store, p.t.head.item.id, ins, { who, now: new Date(p.at) })
|
|
161
|
+
}
|
|
162
|
+
return { before: todo.length, lines, after: o.go ? plans().length : todo.length }
|
|
163
|
+
})
|
|
164
|
+
if (!leased.ok) throw new Error(`asks of ${root} not folded: ${leased.warn}`)
|
|
165
|
+
return leased.value
|
|
166
|
+
}
|