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,285 @@
|
|
|
1
|
+
// the messages store's one writer (wiki tools/shipkit/messages.md): the owner's suggestions from the page (a message in the
|
|
2
|
+
// owner's words, one more phrasing), refused when messages.md changed since the page read it; and an object he approved in a
|
|
3
|
+
// thread (`applyObject`, a kind's apply), refused only when that object's own section moved since it was proposed.
|
|
4
|
+
// The one constraint a reader breaks first: every line outside what changes stays byte for byte, comments included
|
|
5
|
+
import { existsSync, readFileSync, writeFileSync } from 'node:fs'
|
|
6
|
+
import { join } from 'node:path'
|
|
7
|
+
import { hashOf, MESSAGES_DIR, parseMessages } from './model.ts'
|
|
8
|
+
import { sameJson } from '../review/unit.ts'
|
|
9
|
+
import { FILE_OF, keyParts, mainRoot, objectJson, type MessageJson, type ObjectJson, type ObjectKind, type OneJson, type OneOptionJson, type OptionJson, type PersonaJson, type PhrasingJson, type SurfaceJson } from './objects.ts'
|
|
10
|
+
|
|
11
|
+
/** the source of a phrasing the owner wrote, as the store marks its sources */
|
|
12
|
+
export const OWNER = 'owner'
|
|
13
|
+
/** the fields a suggested message carries, each written empty when none was given: the lint and the page say « to fill » */
|
|
14
|
+
const FIELDS = ['meaning', 'value', 'truth', 'never'] as const
|
|
15
|
+
|
|
16
|
+
export type MessageSuggestion = { title: string; family?: string; meaning?: string; value?: string; phrasing?: string }
|
|
17
|
+
export type Suggestion = ({ kind: 'message' } & MessageSuggestion) | { kind: 'phrasing'; message: string; text: string }
|
|
18
|
+
|
|
19
|
+
/** one line: the store reads a field, a title or a phrasing up to its line's end */
|
|
20
|
+
export const oneLine = (s: string | undefined): string => (s ?? '').replace(/\s+/g, ' ').trim()
|
|
21
|
+
/** a phrasing sits between straight quotes, so its own quotes turn typographic */
|
|
22
|
+
export const quoted = (s: string): string => oneLine(s).replace(/"([^"]*)"/g, '“$1”').replace(/"/g, '”')
|
|
23
|
+
|
|
24
|
+
const STOP = new Set(['a', 'an', 'the', 'to', 'of', 'in', 'on', 'for', 'and', 'or', 'with', 'your', 'you', 'any', 'it', 'is', 'as', 'by', 'from', 'can', 'that', 'this', 'all', 'one'])
|
|
25
|
+
|
|
26
|
+
/** a message id from its title: two telling words, unique in the store */
|
|
27
|
+
function messageId(title: string, taken: Set<string>): string {
|
|
28
|
+
const words = title.toLowerCase().normalize('NFKD').replace(/[^a-z0-9\s]/g, ' ').split(/\s+/).filter((w) => w && !STOP.has(w))
|
|
29
|
+
const base = words.slice(0, 2).join('-') || 'message'
|
|
30
|
+
let id = base
|
|
31
|
+
for (let n = 2; taken.has(id); n++) id = `${base}-${n}`
|
|
32
|
+
return id
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** the next phrasing id under a prefix, past every id of the store that already uses it */
|
|
36
|
+
export function nextUnder(prefix: string, ids: string[]): string {
|
|
37
|
+
const re = new RegExp(`^${prefix.replace(/[^\w]/g, '\\$&')}(\\d+)$`)
|
|
38
|
+
const top = Math.max(0, ...ids.map((i) => Number(re.exec(i)?.[1] ?? 0)))
|
|
39
|
+
return `${prefix}${top + 1}`
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** the comments blanked line for line, so a line index of the parse is a line index of the file */
|
|
43
|
+
const lines = (md: string): string[] => md.replace(/<!--[\s\S]*?-->/g, (c) => c.replace(/[^\n]/g, ' ')).split('\n')
|
|
44
|
+
|
|
45
|
+
export function withMessage(md: string, s: MessageSuggestion): { md: string; id: string; phrasing?: string } {
|
|
46
|
+
const title = oneLine(s.title)
|
|
47
|
+
if (!title) throw new Error('a message needs its title')
|
|
48
|
+
const messages = parseMessages(md)
|
|
49
|
+
const ids = messages.flatMap((m) => m.candidates.map((c) => c.id))
|
|
50
|
+
const id = messageId(title, new Set(messages.map((m) => m.id)))
|
|
51
|
+
const text = quoted(s.phrasing ?? '')
|
|
52
|
+
const given: Record<string, string> = { meaning: oneLine(s.meaning), value: oneLine(s.value) }
|
|
53
|
+
const prefix = [...Array(id.length).keys()].map((n) => id.replace(/-/g, '').slice(0, n + 1)).find((p) => !ids.some((i) => new RegExp(`^${p}\\d+$`).test(i))) ?? id
|
|
54
|
+
const phrasing = text ? nextUnder(prefix, ids) : undefined
|
|
55
|
+
const family = oneLine(s.family)
|
|
56
|
+
const block = [
|
|
57
|
+
`## ${id}: ${title}`,
|
|
58
|
+
...(family ? [`- family: ${family}`] : []),
|
|
59
|
+
...FIELDS.map((k) => (given[k] ? `- ${k}: ${given[k]}` : `- ${k}:`)),
|
|
60
|
+
...(phrasing ? [`- \`${phrasing}\` "${text}" ${OWNER}`] : []),
|
|
61
|
+
]
|
|
62
|
+
const body = md.endsWith('\n') ? md : `${md}\n`
|
|
63
|
+
const gap = body.trim() === '' || body.endsWith('\n\n') ? '' : '\n'
|
|
64
|
+
return { md: `${body}${gap}${block.join('\n')}\n`, id, ...(phrasing ? { phrasing } : {}) }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function withPhrasing(md: string, message: string, raw: string): { md: string; id: string } {
|
|
68
|
+
const text = quoted(raw)
|
|
69
|
+
if (!text) throw new Error('a phrasing needs its words')
|
|
70
|
+
const m = parseMessages(md).find((x) => x.id === message)
|
|
71
|
+
if (!m) throw new Error(`messages.md has no message ${message}`)
|
|
72
|
+
const ids = parseMessages(md).flatMap((x) => x.candidates.map((c) => c.id))
|
|
73
|
+
const prefix = m.candidates[0]?.id.replace(/\d+$/, '') || m.id
|
|
74
|
+
const id = nextUnder(prefix, ids)
|
|
75
|
+
const ls = lines(md)
|
|
76
|
+
const head = ls.findIndex((l) => l.startsWith(`## ${message}: `))
|
|
77
|
+
const next = ls.findIndex((l, i) => i > head && l.startsWith('## '))
|
|
78
|
+
let at = (next === -1 ? ls.length : next) - 1
|
|
79
|
+
while (at > head && ls[at]!.trim() === '') at--
|
|
80
|
+
const raws = md.split('\n')
|
|
81
|
+
raws.splice(at + 1, 0, `- \`${id}\` "${text}" ${OWNER}`)
|
|
82
|
+
return { md: raws.join('\n'), id }
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** the suggestion written into the store at `root`, refused when messages.md is no longer the text hashed `expect` */
|
|
86
|
+
export function suggest(root: string, expect: string | undefined, s: Suggestion): { id: string; phrasing?: string } {
|
|
87
|
+
const file = join(root, MESSAGES_DIR, 'messages.md')
|
|
88
|
+
const md = readFileSync(file, 'utf8')
|
|
89
|
+
if (expect !== hashOf(md)) throw new Changed()
|
|
90
|
+
const { md: next, ...made } = s.kind === 'message' ? withMessage(md, s) : withPhrasing(md, s.message, s.text)
|
|
91
|
+
writeFileSync(file, next)
|
|
92
|
+
return made
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class Changed extends Error {
|
|
96
|
+
constructor() {
|
|
97
|
+
super('messages.md changed since this page read it (another session edited it). The page shows it again now: check your words are still wanted, then send again')
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// ---- an object he approved in a thread
|
|
102
|
+
|
|
103
|
+
const ID = /^[\w-]+$/
|
|
104
|
+
/** a section's id from its head line: `## <id> (<role>)` for a persona, `## <id>: <title>` for the rest */
|
|
105
|
+
const headId = (kind: ObjectKind, l: string): string | null => (kind === 'persona' ? /^## ([\w-]+) \(/.exec(l) : /^## ([\w-]+): /.exec(l))?.[1] ?? null
|
|
106
|
+
|
|
107
|
+
/** the lines of one section: its head and its last line that is not blank, in the comments blanked lines */
|
|
108
|
+
function sectionOf(kind: ObjectKind, ls: readonly string[], id: string): { head: number; last: number } | null {
|
|
109
|
+
const head = ls.findIndex((l) => headId(kind, l)?.toLowerCase() === id.toLowerCase())
|
|
110
|
+
if (head === -1) return null
|
|
111
|
+
const next = ls.findIndex((l, i) => i > head && l.startsWith('## '))
|
|
112
|
+
let last = (next === -1 ? ls.length : next) - 1
|
|
113
|
+
while (last > head && ls[last]!.trim() === '') last--
|
|
114
|
+
return { head, last }
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const phrasingLine = (p: PhrasingJson): string => `- \`${p.id}\` "${quoted(p.text)}"${oneLine(p.source) ? ` ${oneLine(p.source)}` : ''}`
|
|
118
|
+
const optionLine = (o: OptionJson): string => `- \`${o.id}\` "${quoted(o.headline)}"${oneLine(o.second) ? ` / "${quoted(o.second)}"` : ''}`
|
|
119
|
+
const fieldLine = (k: string, v: string | undefined): string => (oneLine(v) ? `- ${k}: ${oneLine(v)}` : `- ${k}:`)
|
|
120
|
+
/** a field's order in a written message: family first, as the store writes it */
|
|
121
|
+
const fieldKeys = (m: MessageJson): string[] => {
|
|
122
|
+
const keys = [...new Set([...Object.keys(m.fields), ...m.toFill])]
|
|
123
|
+
return [...keys.filter((k) => k === 'family'), ...keys.filter((k) => k !== 'family')]
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function blockOf(kind: ObjectKind, json: ObjectJson): string[] {
|
|
127
|
+
if (kind === 'persona') {
|
|
128
|
+
const p = json as PersonaJson
|
|
129
|
+
return [`## ${p.id} (${p.role})`, p.who.trim()]
|
|
130
|
+
}
|
|
131
|
+
if (kind === 'messages') {
|
|
132
|
+
const m = json as MessageJson
|
|
133
|
+
return [`## ${m.id}: ${oneLine(m.title)}`, ...fieldKeys(m).map((k) => fieldLine(k, m.fields[k])), ...m.phrasings.map(phrasingLine)]
|
|
134
|
+
}
|
|
135
|
+
const s = json as SurfaceJson
|
|
136
|
+
return [`## ${s.id}: ${oneLine(s.title)}`, ...(s.budget !== undefined ? [`- budget: ${s.budget} characters`] : []), ...(s.shot ? [`- shot: ${oneLine(s.shot)}`] : []), ...s.options.map(optionLine)]
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** a value that would break the store once written, else null: a comment opened or closed, a line that reads as a section,
|
|
140
|
+
* an id or a field key the parse does not take */
|
|
141
|
+
function storeProblem(j: unknown): string | null {
|
|
142
|
+
const o = (j ?? {}) as Record<string, unknown>
|
|
143
|
+
const ids = [...(Array.isArray(o.phrasings) ? o.phrasings : []), ...(Array.isArray(o.options) ? o.options : [])].map((x) => (x as { id?: unknown }).id)
|
|
144
|
+
for (const i of ids) if (typeof i !== 'string' || !ID.test(i)) return `id ${JSON.stringify(i)}: letters, digits, - and _`
|
|
145
|
+
if (typeof o.fields === 'object' && o.fields !== null) for (const k of Object.keys(o.fields)) if (!/^\w+$/.test(k)) return `field ${JSON.stringify(k)}: one word`
|
|
146
|
+
const texts: string[] = []
|
|
147
|
+
const walk = (v: unknown): void => void (typeof v === 'string' ? texts.push(v) : v && typeof v === 'object' ? Object.values(v).forEach(walk) : undefined)
|
|
148
|
+
walk(j)
|
|
149
|
+
for (const t of texts) {
|
|
150
|
+
if (t.includes('<!--') || t.includes('-->')) return `« ${t.slice(0, 40)} »: <!-- or --> would hide the store's lines behind it`
|
|
151
|
+
if (/^\s*## /m.test(t)) return `« ${t.slice(0, 40)} »: a line that starts with ## reads as a new section`
|
|
152
|
+
}
|
|
153
|
+
return null
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** what a proposal holds is the shape its kind and key name, else the reason it is not */
|
|
157
|
+
function shapeProblem(kind: ObjectKind, key: string, j: unknown): string | null {
|
|
158
|
+
const stored = storeProblem(j)
|
|
159
|
+
if (stored !== null) return stored
|
|
160
|
+
const { id, part } = keyParts(key)
|
|
161
|
+
const o = (j ?? {}) as Record<string, unknown>
|
|
162
|
+
const str = (k: string): boolean => typeof o[k] === 'string'
|
|
163
|
+
const idOk = (k: string, want: string): string | null => (str(k) && ID.test(o[k] as string) && (o[k] as string).toLowerCase() === want.toLowerCase() ? null : `${k}: ${want}, the address's own id`)
|
|
164
|
+
if (kind === 'persona') return part !== undefined ? 'a persona has no part' : (idOk('id', id) ?? (o.role === 'reader' || o.role === 'gatekeeper' ? null : 'role: reader or gatekeeper') ?? (str('who') && (o.who as string).trim() ? null : 'who: who it is, in words'))
|
|
165
|
+
if (kind === 'messages') {
|
|
166
|
+
if (part !== undefined) return idOk('message', id) ?? idOk('id', part) ?? (str('text') && oneLine(o.text as string) ? null : 'text: the phrasing')
|
|
167
|
+
return idOk('id', id) ?? (str('title') && oneLine(o.title as string) ? null : 'title: what the message says, in a few words') ?? (typeof o.fields === 'object' && o.fields !== null && Array.isArray(o.toFill) && Array.isArray(o.phrasings) ? null : 'fields, toFill and phrasings')
|
|
168
|
+
}
|
|
169
|
+
if (part !== undefined) return idOk('surface', id) ?? idOk('id', part) ?? (str('headline') && oneLine(o.headline as string) ? null : 'headline: the option')
|
|
170
|
+
return idOk('id', id) ?? (str('title') ? null : 'title: the place') ?? (Array.isArray(o.options) ? null : 'options')
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** an existing message or page top patched line by line: its head, each field, each phrasing or option by its id; every
|
|
174
|
+
* other line stays, comments included. A field or a line it no longer names is refused: removing one is a hand edit */
|
|
175
|
+
function patchSection(kind: 'messages' | 'surface', raws: string[], at: { head: number; last: number }, now: MessageJson | SurfaceJson, after: MessageJson | SurfaceJson): void {
|
|
176
|
+
const blank = lines(raws.join('\n'))
|
|
177
|
+
let tail = at.last
|
|
178
|
+
const inSection = (re: RegExp): number => {
|
|
179
|
+
for (let i = at.head + 1; i <= tail; i++) if (re.test(blank[i]!)) return i
|
|
180
|
+
return -1
|
|
181
|
+
}
|
|
182
|
+
/** the line at `i`, else a new line after `after` (the section's end by default) */
|
|
183
|
+
const put = (i: number, line: string, after = tail): void => {
|
|
184
|
+
if (i !== -1) raws[i] = line
|
|
185
|
+
else {
|
|
186
|
+
raws.splice(after + 1, 0, line)
|
|
187
|
+
blank.splice(after + 1, 0, line)
|
|
188
|
+
tail++
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/** a new field goes under the fields, above the lines */
|
|
192
|
+
const lastField = (): number => {
|
|
193
|
+
let last = at.head
|
|
194
|
+
for (let i = at.head + 1; i <= tail; i++) if (/^- \w+:/.test(blank[i]!)) last = i
|
|
195
|
+
return last
|
|
196
|
+
}
|
|
197
|
+
raws[at.head] = `## ${now.id}: ${oneLine(after.title)}`
|
|
198
|
+
const esc = (s: string): string => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
199
|
+
if (kind === 'messages') {
|
|
200
|
+
const a = after as MessageJson
|
|
201
|
+
const n = now as MessageJson
|
|
202
|
+
for (const k of fieldKeys(n)) if (a.fields[k] === undefined && !a.toFill.includes(k)) throw new Error(`${n.id}: its field ${k} leaves only by a hand edit`)
|
|
203
|
+
for (const p of n.phrasings) if (!a.phrasings.some((x) => x.id === p.id)) throw new Error(`${n.id}/${p.id}: a phrasing leaves only by a hand edit (or is held: its source « held: <why> »)`)
|
|
204
|
+
for (const k of fieldKeys(a)) if (a.fields[k] !== n.fields[k] || a.toFill.includes(k) !== n.toFill.includes(k)) put(inSection(new RegExp(`^- ${esc(k)}:`)), fieldLine(k, a.fields[k]), lastField())
|
|
205
|
+
for (const p of a.phrasings) {
|
|
206
|
+
const was = n.phrasings.find((x) => x.id === p.id)
|
|
207
|
+
if (was && was.text === p.text && was.source === p.source) continue
|
|
208
|
+
const i = inSection(new RegExp(`^- \`${esc(p.id)}\` `))
|
|
209
|
+
put(i, i === -1 ? phrasingLine(p) : keepTail('messages', raws[i]!, phrasingLine(p)))
|
|
210
|
+
}
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
const a = after as SurfaceJson
|
|
214
|
+
const n = now as SurfaceJson
|
|
215
|
+
for (const o of n.options) if (!a.options.some((x) => x.id === o.id)) throw new Error(`${n.id}/${o.id}: an option leaves only by a hand edit`)
|
|
216
|
+
if (a.budget !== n.budget) put(inSection(/^- budget: /), `- budget: ${a.budget} characters`, lastField())
|
|
217
|
+
if (a.shot !== n.shot) put(inSection(/^- shot: /), `- shot: ${oneLine(a.shot)}`, lastField())
|
|
218
|
+
for (const o of a.options) {
|
|
219
|
+
const was = n.options.find((x) => x.id === o.id)
|
|
220
|
+
if (was && was.headline === o.headline && was.second === o.second) continue
|
|
221
|
+
const i = inSection(new RegExp(`^- \`${esc(o.id)}\` `))
|
|
222
|
+
put(i, i === -1 ? optionLine(o) : keepTail('surface', raws[i]!, optionLine(o)))
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** a phrasing or an option line rewritten with what followed the old line's words kept: an option's note after its last
|
|
227
|
+
* quote, a phrasing's comment (its source is its json's) */
|
|
228
|
+
function keepTail(kind: ObjectKind, old: string, line: string): string {
|
|
229
|
+
if (kind === 'messages') return old.includes('<!--') ? `${line} ${old.slice(old.indexOf('<!--'))}` : line
|
|
230
|
+
const words = /^- `[^`]+` "[^"]*"(?: \/ "[^"]*")?/.exec(old)
|
|
231
|
+
return words == null ? line : `${line}${old.slice(words[0].length)}`
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/** an object he approved, written into the md of the repo's main checkout: appended when new, its section patched when
|
|
235
|
+
* not. `before`: the object as the proposal read it, null or absent for a new one. Refused, nothing written: a new
|
|
236
|
+
* object whose id is taken, an object whose section moved since it was proposed, a shape its kind does not take */
|
|
237
|
+
export function applyObject(root: string, kind: ObjectKind, key: string, after: unknown, before?: unknown): { file: string; id: string; made: boolean } {
|
|
238
|
+
const address = `${kind}:${key}`
|
|
239
|
+
const bad = shapeProblem(kind, key, after)
|
|
240
|
+
if (bad !== null) throw new Error(`${address}: ${bad}`)
|
|
241
|
+
const main = mainRoot(root)
|
|
242
|
+
const file = join(main, MESSAGES_DIR, FILE_OF[kind])
|
|
243
|
+
if (!existsSync(join(main, MESSAGES_DIR, 'messages.md'))) throw new Error(`no messages store in ${main} (${MESSAGES_DIR}/messages.md)`)
|
|
244
|
+
const md = existsSync(file) ? readFileSync(file, 'utf8') : ''
|
|
245
|
+
if (md.includes('\r')) throw new Error(`${FILE_OF[kind]} has CRLF line ends, which the store does not read: save it with LF first`)
|
|
246
|
+
const now = objectJson(root, kind, key)
|
|
247
|
+
// approved again (a verdict taken back, then given): what it holds is in the store already
|
|
248
|
+
if (before == null && now != null && sameJson(now, after)) return { file, id: (now as { id: string }).id, made: false }
|
|
249
|
+
if (before == null && now != null) throw new Error(`${address} exists already: a change of it is proposed with its before`)
|
|
250
|
+
if (before != null && now == null) throw new Error(`${address} is no longer in ${FILE_OF[kind]}: it was removed or renamed since it was proposed`)
|
|
251
|
+
if (before != null && !sameJson(before, now)) throw new Error(`${address} moved in ${FILE_OF[kind]} since it was proposed: propose it again from what it says now`)
|
|
252
|
+
const j = after as ObjectJson
|
|
253
|
+
if (kind === 'messages') {
|
|
254
|
+
// a phrasing's scores and its line in a run are by its id alone, so an id is the store's once
|
|
255
|
+
const mine = new Set(now != null && 'phrasings' in now ? now.phrasings.map((p) => p.id) : now != null ? [(now as OneJson).id] : [])
|
|
256
|
+
const fresh = 'phrasings' in j ? j.phrasings.map((p) => p.id) : [(j as OneJson).id]
|
|
257
|
+
const taken = new Set(parseMessages(md).flatMap((m) => m.candidates.map((c) => c.id)))
|
|
258
|
+
for (const p of fresh) if (!mine.has(p) && taken.has(p)) throw new Error(`${address}: the phrasing id ${p} is taken in messages.md`)
|
|
259
|
+
}
|
|
260
|
+
const raws = md.split('\n')
|
|
261
|
+
const { id, part } = keyParts(key)
|
|
262
|
+
if (part === undefined && now == null) {
|
|
263
|
+
const body = md === '' || md.endsWith('\n') ? md : `${md}\n`
|
|
264
|
+
const gap = body.trim() === '' || body.endsWith('\n\n') ? '' : '\n'
|
|
265
|
+
writeFileSync(file, `${body}${gap}${blockOf(kind, j).join('\n')}\n`)
|
|
266
|
+
return { file, id: (j as { id: string }).id, made: true }
|
|
267
|
+
}
|
|
268
|
+
const sec = sectionOf(kind, lines(md), id)
|
|
269
|
+
if (sec === null) throw new Error(`${address}: ${FILE_OF[kind]} has no section ${id} to write it under`)
|
|
270
|
+
if (kind === 'persona') {
|
|
271
|
+
raws.splice(sec.head, sec.last - sec.head + 1, ...blockOf(kind, j))
|
|
272
|
+
} else if (part === undefined) {
|
|
273
|
+
patchSection(kind, raws, sec, now as MessageJson | SurfaceJson, j as MessageJson | SurfaceJson)
|
|
274
|
+
} else {
|
|
275
|
+
const line = kind === 'messages' ? phrasingLine(j as OneJson) : optionLine(j as OneOptionJson)
|
|
276
|
+
const blank = lines(md)
|
|
277
|
+
const re = new RegExp(`^- \`${part.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\` `, 'i')
|
|
278
|
+
let i = -1
|
|
279
|
+
for (let k = sec.head + 1; k <= sec.last; k++) if (re.test(blank[k]!)) i = k
|
|
280
|
+
if (i !== -1) raws[i] = keepTail(kind, raws[i]!, line)
|
|
281
|
+
else raws.splice(sec.last + 1, 0, line)
|
|
282
|
+
}
|
|
283
|
+
writeFileSync(file, raws.join('\n'))
|
|
284
|
+
return { file, id: (j as { id: string }).id, made: now == null }
|
|
285
|
+
}
|
|
@@ -2,10 +2,13 @@
|
|
|
2
2
|
// repo's page bundles to live in the hub. No framework, no hub code beyond the keys table. Framed, it speaks the
|
|
3
3
|
// `{ shipkit: <verb> }` messages on its origin; alone at its own url, it keeps the keys in its own address, so the
|
|
4
4
|
// page works the same either way
|
|
5
|
+
import type { ObjectThread } from '../review/cells.ts'
|
|
5
6
|
import { pageKey, pageLetterKey, sectionKey } from '../serve/hub-app/keys.ts'
|
|
6
7
|
|
|
7
8
|
export type FrameTheme = 'dark' | 'light'
|
|
8
9
|
export type FrameBadge = { count: number; tone?: 'red' | 'warn' | null; title?: string }
|
|
10
|
+
/** the threads that name one object of the page, as the hub's `GET /api/review/of` answers */
|
|
11
|
+
export type FrameObjectThreads = { address: string; threads: ObjectThread[]; noteGoesTo: string | null }
|
|
9
12
|
|
|
10
13
|
export interface FrameOpts {
|
|
11
14
|
/** the page's state as url keys: from the hub's address, or the page's own; the page applies them */
|
|
@@ -35,9 +38,28 @@ export interface PageFrame {
|
|
|
35
38
|
threads(address: string): void
|
|
36
39
|
/** his note on one of the page's objects: it goes into the thread its address has, else starts one, then opens */
|
|
37
40
|
note(address: string, name: string, text: string): void
|
|
41
|
+
/** the threads of each address, in the order asked; alone, none */
|
|
42
|
+
threadsOf(addresses: readonly string[]): Promise<FrameObjectThreads[]>
|
|
43
|
+
/** the hub's 💬 control on one of the page's objects, a plain element: its count, its menu, the owner's words; hidden alone */
|
|
44
|
+
threadControl(address: string, name: string): HTMLElement
|
|
38
45
|
stop(): void
|
|
39
46
|
}
|
|
40
47
|
|
|
48
|
+
/** the wait after the last control is made before the one `threads-of` request: a page draws its rows in one moment */
|
|
49
|
+
const QUIET_MS = 60
|
|
50
|
+
|
|
51
|
+
const TURN_WORDS: Record<ObjectThread['turn'], string> = { yours: 'your turn', aside: 'set aside', agents: "an agent's move", done: 'done' }
|
|
52
|
+
|
|
53
|
+
/** the control's colours on the frame's theme; the accent is the hub's own for « your turn » */
|
|
54
|
+
const paint = (t: FrameTheme) => (t === 'dark' ? { bg: '#1d1f24', fg: '#e8e8ea', dim: '#9a9ca3', line: '#3a3d45', accent: '#ff5fa2' } : { bg: '#ffffff', fg: '#1d1f24', dim: '#6b6e76', line: '#d9dae0', accent: '#d6337f' })
|
|
55
|
+
|
|
56
|
+
interface ControlRec {
|
|
57
|
+
address: string
|
|
58
|
+
name: string
|
|
59
|
+
button: HTMLButtonElement
|
|
60
|
+
data: FrameObjectThreads | null
|
|
61
|
+
}
|
|
62
|
+
|
|
41
63
|
type KeyLike = Pick<KeyboardEvent, 'key' | 'code' | 'altKey' | 'shiftKey' | 'metaKey' | 'ctrlKey'>
|
|
42
64
|
|
|
43
65
|
/** a key the hub owns: its ⌥ sections, a page's ⌥⇧ letter, the home's ⌘ keys */
|
|
@@ -61,18 +83,170 @@ export function frameClient(o: FrameOpts): PageFrame {
|
|
|
61
83
|
live = null
|
|
62
84
|
}
|
|
63
85
|
|
|
86
|
+
let theme: FrameTheme = 'light'
|
|
87
|
+
let seq = 0
|
|
88
|
+
const asked = new Map<number, (objects: FrameObjectThreads[]) => void>()
|
|
89
|
+
const threadsOf = (addresses: readonly string[]): Promise<FrameObjectThreads[]> => {
|
|
90
|
+
if (!framed || addresses.length === 0) return Promise.resolve([])
|
|
91
|
+
const id = ++seq
|
|
92
|
+
return new Promise((res) => {
|
|
93
|
+
asked.set(id, res)
|
|
94
|
+
up({ shipkit: 'threads-of', id, addresses: [...addresses] })
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
const controls = new Set<ControlRec>()
|
|
98
|
+
let quiet: ReturnType<typeof setTimeout> | null = null
|
|
99
|
+
/** every control the page holds, asked in one request once the page holds still */
|
|
100
|
+
const refresh = (): void => {
|
|
101
|
+
if (quiet !== null) clearTimeout(quiet)
|
|
102
|
+
quiet = setTimeout(() => {
|
|
103
|
+
quiet = null
|
|
104
|
+
for (const c of controls) if (!c.button.isConnected && c.data !== null) controls.delete(c)
|
|
105
|
+
const all = [...controls]
|
|
106
|
+
void threadsOf(all.map((c) => c.address)).then((objects) => {
|
|
107
|
+
all.forEach((c, i) => {
|
|
108
|
+
c.data = objects[i] ?? null
|
|
109
|
+
drawButton(c)
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
}, QUIET_MS)
|
|
113
|
+
}
|
|
114
|
+
/** the page's own scheme, read from what it paints: a page may stay light under a dark hub */
|
|
115
|
+
const pageTheme = (): FrameTheme => {
|
|
116
|
+
for (const el of [document.body, document.documentElement]) {
|
|
117
|
+
const m = getComputedStyle(el).backgroundColor.match(/[\d.]+/g)?.map(Number)
|
|
118
|
+
if (m == null || m.length < 3 || m[3] === 0) continue
|
|
119
|
+
return 0.2126 * m[0]! + 0.7152 * m[1]! + 0.0722 * m[2]! < 128 ? 'dark' : 'light'
|
|
120
|
+
}
|
|
121
|
+
return theme
|
|
122
|
+
}
|
|
123
|
+
const drawButton = (c: ControlRec): void => {
|
|
124
|
+
const p = paint(pageTheme())
|
|
125
|
+
const n = c.data?.threads.length ?? 0
|
|
126
|
+
const yours = c.data?.threads.some((t) => t.turn === 'yours') ?? false
|
|
127
|
+
c.button.textContent = n > 0 ? `💬 ${n}` : '💬'
|
|
128
|
+
c.button.title = `threads on ${c.name} (${c.address})${yours ? ': one waits on you' : ''}`
|
|
129
|
+
Object.assign(c.button.style, { color: yours ? p.accent : p.fg, fontWeight: yours ? '600' : '400', opacity: n > 0 ? '1' : '0.55', borderColor: yours ? p.accent : 'transparent' })
|
|
130
|
+
}
|
|
131
|
+
let menu: { el: HTMLElement; off: () => void } | null = null
|
|
132
|
+
const closeMenu = (): void => {
|
|
133
|
+
menu?.off()
|
|
134
|
+
menu?.el.remove()
|
|
135
|
+
menu = null
|
|
136
|
+
}
|
|
137
|
+
const openMenu = (c: ControlRec): void => {
|
|
138
|
+
closeMenu()
|
|
139
|
+
const p = paint(pageTheme())
|
|
140
|
+
const el = document.createElement('div')
|
|
141
|
+
el.setAttribute('data-shipkit-threads', c.address)
|
|
142
|
+
const r = c.button.getBoundingClientRect()
|
|
143
|
+
const w = Math.min(340, innerWidth - 16)
|
|
144
|
+
Object.assign(el.style, { position: 'fixed', zIndex: '2147483647', top: `${Math.min(r.bottom + 4, innerHeight - 180)}px`, left: `${Math.max(8, Math.min(r.left, innerWidth - w - 8))}px`, width: `${w}px`, boxSizing: 'border-box', padding: '8px', display: 'flex', flexDirection: 'column', gap: '6px', background: p.bg, color: p.fg, border: `1px solid ${p.line}`, borderRadius: '8px', boxShadow: '0 6px 24px rgba(0,0,0,.25)', font: '13px system-ui, sans-serif' })
|
|
145
|
+
const head = document.createElement('div')
|
|
146
|
+
head.innerHTML = '<b></b> <span></span>'
|
|
147
|
+
head.children[0]!.textContent = c.name
|
|
148
|
+
head.children[1]!.textContent = c.address
|
|
149
|
+
Object.assign((head.children[1] as HTMLElement).style, { color: p.dim, overflowWrap: 'anywhere' })
|
|
150
|
+
el.append(head)
|
|
151
|
+
for (const t of c.data?.threads ?? []) {
|
|
152
|
+
const b = document.createElement('button')
|
|
153
|
+
b.type = 'button'
|
|
154
|
+
b.setAttribute('data-thread', t.head)
|
|
155
|
+
Object.assign(b.style, { display: 'block', width: '100%', textAlign: 'left', padding: '6px', borderRadius: '6px', border: `1px solid ${p.line}`, background: 'none', color: 'inherit', font: 'inherit', cursor: 'pointer' })
|
|
156
|
+
const turn = document.createElement('span')
|
|
157
|
+
turn.textContent = TURN_WORDS[t.turn]
|
|
158
|
+
Object.assign(turn.style, { fontSize: '11px', padding: '0 5px', borderRadius: '9px', marginRight: '6px', border: `1px solid ${t.turn === 'yours' ? p.accent : p.line}`, color: t.turn === 'yours' ? p.accent : p.dim })
|
|
159
|
+
b.append(turn, t.title)
|
|
160
|
+
b.onclick = () => {
|
|
161
|
+
closeMenu()
|
|
162
|
+
up({ shipkit: 'open', hash: `#page:review:${t.head}` })
|
|
163
|
+
}
|
|
164
|
+
el.append(b)
|
|
165
|
+
}
|
|
166
|
+
const box = document.createElement('textarea')
|
|
167
|
+
box.rows = 2
|
|
168
|
+
box.placeholder = c.data?.noteGoesTo ? 'a note: it goes into its thread (Enter sends)' : 'a note: it starts a thread on it (Enter sends)'
|
|
169
|
+
Object.assign(box.style, { width: '100%', boxSizing: 'border-box', resize: 'vertical', font: 'inherit', padding: '6px', borderRadius: '6px', border: `1px solid ${p.line}`, background: p.bg, color: p.fg })
|
|
170
|
+
const send = document.createElement('button')
|
|
171
|
+
send.type = 'button'
|
|
172
|
+
send.textContent = c.data?.noteGoesTo ? 'send to its thread' : 'start a thread'
|
|
173
|
+
Object.assign(send.style, { alignSelf: 'flex-start', padding: '4px 10px', borderRadius: '6px', border: `1px solid ${p.accent}`, background: p.accent, color: '#fff', font: 'inherit', cursor: 'pointer' })
|
|
174
|
+
const go = (): void => {
|
|
175
|
+
const text = box.value.trim()
|
|
176
|
+
if (text === '') return box.focus()
|
|
177
|
+
closeMenu()
|
|
178
|
+
up({ shipkit: 'note', address: c.address, name: c.name, text })
|
|
179
|
+
}
|
|
180
|
+
send.onclick = go
|
|
181
|
+
box.onkeydown = (e) => {
|
|
182
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
183
|
+
e.preventDefault()
|
|
184
|
+
go()
|
|
185
|
+
} else if (e.key === 'Escape') closeMenu()
|
|
186
|
+
}
|
|
187
|
+
el.append(box, send)
|
|
188
|
+
document.body.append(el)
|
|
189
|
+
box.focus()
|
|
190
|
+
const outside = (e: PointerEvent): void => {
|
|
191
|
+
if (!el.contains(e.target as Node) && e.target !== c.button) closeMenu()
|
|
192
|
+
}
|
|
193
|
+
const esc = (e: KeyboardEvent): void => {
|
|
194
|
+
if (e.key === 'Escape') closeMenu()
|
|
195
|
+
}
|
|
196
|
+
setTimeout(() => addEventListener('pointerdown', outside, true))
|
|
197
|
+
addEventListener('keydown', esc)
|
|
198
|
+
menu = { el, off: () => (removeEventListener('pointerdown', outside, true), removeEventListener('keydown', esc)) }
|
|
199
|
+
}
|
|
200
|
+
const threadControl = (address: string, name: string): HTMLElement => {
|
|
201
|
+
const button = document.createElement('button')
|
|
202
|
+
button.type = 'button'
|
|
203
|
+
button.className = 'shipkit-threads'
|
|
204
|
+
button.setAttribute('data-address', address)
|
|
205
|
+
Object.assign(button.style, { font: 'inherit', fontSize: '12px', lineHeight: '1.6', padding: '0 6px', border: '1px solid transparent', borderRadius: '6px', background: 'none', cursor: 'pointer', verticalAlign: 'middle', whiteSpace: 'nowrap' })
|
|
206
|
+
if (!framed) {
|
|
207
|
+
button.hidden = true
|
|
208
|
+
return button
|
|
209
|
+
}
|
|
210
|
+
const c: ControlRec = { address, name, button, data: null }
|
|
211
|
+
drawButton(c)
|
|
212
|
+
button.onclick = (e) => {
|
|
213
|
+
e.stopPropagation()
|
|
214
|
+
if (menu?.el.getAttribute('data-shipkit-threads') === address) closeMenu()
|
|
215
|
+
else openMenu(c)
|
|
216
|
+
}
|
|
217
|
+
controls.add(c)
|
|
218
|
+
refresh()
|
|
219
|
+
return button
|
|
220
|
+
}
|
|
221
|
+
|
|
64
222
|
const onMessage = (e: MessageEvent): void => {
|
|
65
223
|
if (e.source !== window.parent || e.origin !== origin) return
|
|
66
|
-
const m = (e.data ?? {}) as { shipkit?: unknown; keys?: unknown; theme?: unknown; identity?: unknown; on?: unknown }
|
|
224
|
+
const m = (e.data ?? {}) as { shipkit?: unknown; keys?: unknown; theme?: unknown; identity?: unknown; on?: unknown; id?: unknown; objects?: unknown }
|
|
225
|
+
if (m.shipkit === 'threads-of' && typeof m.id === 'number') {
|
|
226
|
+
asked.get(m.id)?.(Array.isArray(m.objects) ? (m.objects as FrameObjectThreads[]) : [])
|
|
227
|
+
asked.delete(m.id)
|
|
228
|
+
return
|
|
229
|
+
}
|
|
67
230
|
if ((m.shipkit === 'hello' || m.shipkit === 'keys') && typeof m.keys === 'string') {
|
|
68
231
|
last = m.keys
|
|
69
232
|
o.onKeys(m.keys)
|
|
70
233
|
}
|
|
71
|
-
if ((m.shipkit === 'hello' || m.shipkit === 'theme') && (m.theme === 'dark' || m.theme === 'light'))
|
|
234
|
+
if ((m.shipkit === 'hello' || m.shipkit === 'theme') && (m.theme === 'dark' || m.theme === 'light')) {
|
|
235
|
+
theme = m.theme
|
|
236
|
+
o.onTheme?.(m.theme)
|
|
237
|
+
// once the page painted its scheme
|
|
238
|
+
requestAnimationFrame(() => setTimeout(() => controls.forEach(drawButton), 50))
|
|
239
|
+
}
|
|
72
240
|
if ((m.shipkit === 'hello' || m.shipkit === 'identity') && (typeof m.identity === 'string' || m.identity === null)) o.onIdentity?.(m.identity)
|
|
73
241
|
if ((m.shipkit === 'hello' || m.shipkit === 'focus') && typeof m.on === 'boolean') {
|
|
74
|
-
if (m.on)
|
|
75
|
-
|
|
242
|
+
if (m.on) {
|
|
243
|
+
openLive()
|
|
244
|
+
// a note sent from here opened its thread: back on the page, the counts may have moved
|
|
245
|
+
if (controls.size > 0) refresh()
|
|
246
|
+
} else {
|
|
247
|
+
closeLive()
|
|
248
|
+
closeMenu()
|
|
249
|
+
}
|
|
76
250
|
o.onFocus?.(m.on)
|
|
77
251
|
}
|
|
78
252
|
}
|
|
@@ -118,7 +292,10 @@ export function frameClient(o: FrameOpts): PageFrame {
|
|
|
118
292
|
note(address, name, text) {
|
|
119
293
|
up({ shipkit: 'note', address, name, text })
|
|
120
294
|
},
|
|
295
|
+
threadsOf,
|
|
296
|
+
threadControl,
|
|
121
297
|
stop() {
|
|
298
|
+
closeMenu()
|
|
122
299
|
window.removeEventListener('message', onMessage)
|
|
123
300
|
window.removeEventListener('keydown', onKey)
|
|
124
301
|
mq?.removeEventListener('change', onScheme)
|
|
@@ -54,7 +54,7 @@ export function classifyReflection(text: string): ReflectionKind {
|
|
|
54
54
|
export type Reflection = ReflectionKind & { file: string; title: string; unreadable: boolean }
|
|
55
55
|
|
|
56
56
|
/** the first heading, which is the line whoever logged it wrote to name it */
|
|
57
|
-
const firstHeading = (text: string): string | null =>
|
|
57
|
+
export const firstHeading = (text: string): string | null =>
|
|
58
58
|
text.split('\n').find((l) => /^\s*#{1,6}\s+\S/.test(l))?.replace(/^\s*#{1,6}\s+/, '').trim() ?? null
|
|
59
59
|
|
|
60
60
|
/** every file still pending. README.md is the scaffold's own seed, written
|
|
@@ -39,7 +39,8 @@ export function linkModules(repo: string, dir: string, nms: string[] = moduleDir
|
|
|
39
39
|
continue
|
|
40
40
|
}
|
|
41
41
|
const inRepo = st.isSymbolicLink() ? relative(repo, resolve(from, readlinkSync(entry))) : ''
|
|
42
|
-
|
|
42
|
+
// a link into a folder git ignores (a package built into .shipkit/cache) has no copy in the checkout: the repo's
|
|
43
|
+
const workspace = inRepo !== '' && !inRepo.startsWith('..') && !isAbsolute(inRepo) && !inRepo.split(sep).includes('node_modules') && existsSync(join(dir, inRepo))
|
|
43
44
|
symlinkSync(workspace ? join(dir, inRepo) : entry, join(dir, nm, name))
|
|
44
45
|
}
|
|
45
46
|
}
|
package/src/release/git-facts.ts
CHANGED
|
@@ -4,11 +4,12 @@
|
|
|
4
4
|
// import it without dragging the gate in.
|
|
5
5
|
import type { RepoConfig } from '../repo-config.ts'
|
|
6
6
|
import { gitBin } from '../core/git-bin.ts'
|
|
7
|
+
import { realGit } from '../core/git.ts'
|
|
7
8
|
import { CI_LOG_DIR, LAYOUT } from '../core/layout.ts'
|
|
8
9
|
|
|
9
10
|
export function git(root: string, args: string[]): { code: number; out: string } {
|
|
10
|
-
const
|
|
11
|
-
return { code:
|
|
11
|
+
const r = realGit.runSync(root, args)
|
|
12
|
+
return { code: r.code, out: `${r.out}${r.err}`.trim() }
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
/** the push remote: the current branch's upstream when it has one, else the
|
|
@@ -9,7 +9,8 @@ import { dirname, join, relative } from 'path'
|
|
|
9
9
|
import { scanFleet } from '../fleet/scan-fleet.ts'
|
|
10
10
|
import { evaluateLeak, globalAllowFile, withBuiltinRows, globalKeywordFile, leakAllowProblem, loadAllowFile, maskPattern, occurrences, parsePatterns, patternFingerprint, type LoadedAllow } from '../hooks/leak-guard.ts'
|
|
11
11
|
import { readIdentities, type Identities } from '../identities/identities.ts'
|
|
12
|
-
import { KEYWORD_FILE
|
|
12
|
+
import { KEYWORD_FILE } from '../core/layout.ts'
|
|
13
|
+
import { HOUSE_LAYOUT } from '../core/house-layout.ts'
|
|
13
14
|
import { parseDirectives, reaches } from '../core/waivers.ts'
|
|
14
15
|
import { fileStamp } from '../core/file-stamp.ts'
|
|
15
16
|
import { gitRoot } from '../core/git-root.ts'
|
|
@@ -63,7 +64,7 @@ export function houseIdentitiesDir(root: string, home = homedir()): string | nul
|
|
|
63
64
|
if (env) return env
|
|
64
65
|
const index = houseIndex(houseRepos(root, home).home, home)
|
|
65
66
|
const top = index == null ? null : gitRoot(dirname(index))?.top
|
|
66
|
-
return top == null ? null : join(top,
|
|
67
|
+
return top == null ? null : join(top, HOUSE_LAYOUT.identities)
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
const host = (url: string): string => {
|