teamsmith 0.0.0-stage → 0.1.2
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/LICENSE +21 -0
- package/README.md +158 -2
- package/bin/team.mjs +59 -0
- package/install.sh +94 -0
- package/package.json +37 -4
- package/skills/teamsmith/CHANGELOG.md +763 -0
- package/skills/teamsmith/SKILL.md +312 -0
- package/skills/teamsmith/extension/team-bg.ts +435 -0
- package/skills/teamsmith/extension/team-inbox-watch.ts +1412 -0
- package/skills/teamsmith/extension/team-notify.ts +663 -0
- package/skills/teamsmith/references/agent-adapters.md +643 -0
- package/skills/teamsmith/references/config.md +477 -0
- package/skills/teamsmith/references/meeting.md +124 -0
- package/skills/teamsmith/references/memory.md +133 -0
- package/skills/teamsmith/references/migration.md +227 -0
- package/skills/teamsmith/references/openspec.md +222 -0
- package/skills/teamsmith/references/philosophy.md +95 -0
- package/skills/teamsmith/references/protocol.md +712 -0
- package/skills/teamsmith/references/troubleshooting.md +1384 -0
- package/skills/teamsmith/references/workflows.md +448 -0
- package/skills/teamsmith/scripts/lib/cmd-agents.sh +1709 -0
- package/skills/teamsmith/scripts/lib/cmd-bg.sh +284 -0
- package/skills/teamsmith/scripts/lib/cmd-bootstrap.sh +311 -0
- package/skills/teamsmith/scripts/lib/cmd-config.sh +1156 -0
- package/skills/teamsmith/scripts/lib/cmd-death.sh +562 -0
- package/skills/teamsmith/scripts/lib/cmd-docs.sh +149 -0
- package/skills/teamsmith/scripts/lib/cmd-draft.sh +124 -0
- package/skills/teamsmith/scripts/lib/cmd-init.sh +212 -0
- package/skills/teamsmith/scripts/lib/cmd-meeting.sh +904 -0
- package/skills/teamsmith/scripts/lib/cmd-outbox.sh +196 -0
- package/skills/teamsmith/scripts/lib/cmd-project.sh +642 -0
- package/skills/teamsmith/scripts/lib/cmd-review.sh +1393 -0
- package/skills/teamsmith/scripts/lib/cmd-status.sh +1399 -0
- package/skills/teamsmith/scripts/lib/cmd-update.sh +191 -0
- package/skills/teamsmith/scripts/lib/cmd-watch.sh +1681 -0
- package/skills/teamsmith/scripts/lib/common.sh +4964 -0
- package/skills/teamsmith/scripts/lib/draft-entry.sh +51 -0
- package/skills/teamsmith/scripts/lib/outbox.sh +2042 -0
- package/skills/teamsmith/scripts/lib/tmux-argv.sh +165 -0
- package/skills/teamsmith/scripts/monitor.mjs +616 -0
- package/skills/teamsmith/scripts/panel/README.md +192 -0
- package/skills/teamsmith/scripts/panel/build.sh +47 -0
- package/skills/teamsmith/scripts/panel/bun.lock +109 -0
- package/skills/teamsmith/scripts/panel/draft-send.sh +68 -0
- package/skills/teamsmith/scripts/panel/package.json +24 -0
- package/skills/teamsmith/scripts/panel/panel.js +388 -0
- package/skills/teamsmith/scripts/panel/src/App.tsx +2150 -0
- package/skills/teamsmith/scripts/panel/src/clipboard.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/compose.ts +691 -0
- package/skills/teamsmith/scripts/panel/src/data.ts +555 -0
- package/skills/teamsmith/scripts/panel/src/format.ts +50 -0
- package/skills/teamsmith/scripts/panel/src/layout.ts +2562 -0
- package/skills/teamsmith/scripts/panel/src/main.tsx +894 -0
- package/skills/teamsmith/scripts/panel/src/markdown.ts +340 -0
- package/skills/teamsmith/scripts/panel/src/sanitize.ts +42 -0
- package/skills/teamsmith/scripts/panel/src/settings.ts +154 -0
- package/skills/teamsmith/scripts/panel/src/strings/en.ts +416 -0
- package/skills/teamsmith/scripts/panel/src/strings/index.ts +65 -0
- package/skills/teamsmith/scripts/panel/src/strings/types.ts +9 -0
- package/skills/teamsmith/scripts/panel/src/strings/zh.ts +414 -0
- package/skills/teamsmith/scripts/panel/src/theme.ts +116 -0
- package/skills/teamsmith/scripts/panel/src/types.ts +652 -0
- package/skills/teamsmith/scripts/panel/src/width.ts +105 -0
- package/skills/teamsmith/scripts/panel/tsconfig.json +16 -0
- package/skills/teamsmith/scripts/shim/signal-gate +156 -0
- package/skills/teamsmith/scripts/shim/tmux +403 -0
- package/skills/teamsmith/scripts/team +143 -0
- package/skills/teamsmith/templates/AGENTS.section.md.tmpl +147 -0
- package/skills/teamsmith/templates/BOARD.md.tmpl +18 -0
- package/skills/teamsmith/templates/DECISIONS.md.tmpl +22 -0
- package/skills/teamsmith/templates/OWNERSHIP.md.tmpl +25 -0
- package/skills/teamsmith/templates/PROTOCOL.md.tmpl +84 -0
- package/skills/teamsmith/templates/ROADMAP.md.tmpl +29 -0
- package/skills/teamsmith/templates/config.sh.tmpl +106 -0
- package/skills/teamsmith/templates/memory-seed.md.tmpl +46 -0
- package/skills/teamsmith/templates/pm-prompt.md.tmpl +110 -0
- package/skills/teamsmith/templates/report.md.tmpl +36 -0
- package/skills/teamsmith/templates/task.md.tmpl +65 -0
- package/skills/teamsmith/templates/threads-README.md +17 -0
- package/skills/teamsmith/tests/bg-ledger-harness.mjs +682 -0
- package/skills/teamsmith/tests/bg-ledger.sh +307 -0
- package/skills/teamsmith/tests/checkout-shape-probe.sh +800 -0
- package/skills/teamsmith/tests/config-cli.sh +1562 -0
- package/skills/teamsmith/tests/container-tmux.sh +493 -0
- package/skills/teamsmith/tests/coverage-inventory.sh +173 -0
- package/skills/teamsmith/tests/death-cause.sh +564 -0
- package/skills/teamsmith/tests/delivery-truth.sh +1231 -0
- package/skills/teamsmith/tests/fake-tui.py +450 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/README.md +60 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/judge-second.py +139 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/mock-server.py +29 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/observe.ts +20 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/run-case.sh +79 -0
- package/skills/teamsmith/tests/fixtures/delivery-truth-real/scenario.sh +175 -0
- package/skills/teamsmith/tests/fixtures/p55/flip-p49.sh +229 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/README.md +22 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.seen +8 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/dev2.wake +9 -0
- package/skills/teamsmith/tests/fixtures/p71-incident/pm-nudges.wake +3 -0
- package/skills/teamsmith/tests/fixtures/signal-lint-cases.txt +40 -0
- package/skills/teamsmith/tests/flip-glue.sh +162 -0
- package/skills/teamsmith/tests/flip-m12-26c.sh +129 -0
- package/skills/teamsmith/tests/flip-m12.sh +185 -0
- package/skills/teamsmith/tests/flip-m16.sh +166 -0
- package/skills/teamsmith/tests/flip-m17.sh +204 -0
- package/skills/teamsmith/tests/flip-m33.sh +284 -0
- package/skills/teamsmith/tests/flip-m34.sh +96 -0
- package/skills/teamsmith/tests/flip-m37.sh +185 -0
- package/skills/teamsmith/tests/flip-m4.3.sh +375 -0
- package/skills/teamsmith/tests/flip-m43.sh +128 -0
- package/skills/teamsmith/tests/flip-m44.sh +262 -0
- package/skills/teamsmith/tests/flip-m45.sh +244 -0
- package/skills/teamsmith/tests/flip-m46.sh +238 -0
- package/skills/teamsmith/tests/flip-m48.sh +304 -0
- package/skills/teamsmith/tests/flip-m6.2.sh +205 -0
- package/skills/teamsmith/tests/flip-m6.3.sh +283 -0
- package/skills/teamsmith/tests/flip-m6.4.sh +267 -0
- package/skills/teamsmith/tests/flip-m6.5.sh +113 -0
- package/skills/teamsmith/tests/flip-m7.1.sh +135 -0
- package/skills/teamsmith/tests/flip-m7.2.sh +321 -0
- package/skills/teamsmith/tests/flip-p144.sh +112 -0
- package/skills/teamsmith/tests/flip-p156.sh +133 -0
- package/skills/teamsmith/tests/flip-p158.sh +301 -0
- package/skills/teamsmith/tests/flip-p160.sh +182 -0
- package/skills/teamsmith/tests/flip-p171.sh +249 -0
- package/skills/teamsmith/tests/flip-p18.1.sh +95 -0
- package/skills/teamsmith/tests/flip-p20.sh +286 -0
- package/skills/teamsmith/tests/flip-p201.sh +249 -0
- package/skills/teamsmith/tests/flip-p210.sh +239 -0
- package/skills/teamsmith/tests/flip-p211.sh +152 -0
- package/skills/teamsmith/tests/flip-p217.sh +288 -0
- package/skills/teamsmith/tests/flip-p22.sh +123 -0
- package/skills/teamsmith/tests/flip-p23.sh +239 -0
- package/skills/teamsmith/tests/flip-p25.sh +165 -0
- package/skills/teamsmith/tests/flip-p71.sh +184 -0
- package/skills/teamsmith/tests/flip-p72.sh +202 -0
- package/skills/teamsmith/tests/frames/README.md +176 -0
- package/skills/teamsmith/tests/frames/p78-conversation-rule-below-box.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-cursor-mid-draft.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor-line.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-blank-region.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-draft-rule-only.txt +5 -0
- package/skills/teamsmith/tests/frames/p78-spinner-row-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p78-wider-rule-below-cursor.txt +6 -0
- package/skills/teamsmith/tests/frames/p86-f1-mixed-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-narrower-width-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/p86-f1-spinner-top-disjoint-box.txt +8 -0
- package/skills/teamsmith/tests/frames/pi-0.85.1-update-banner.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-draft-half-sentence.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-empty-box.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-one-line-draft.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.87.0-project-trust-prompt.txt +30 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-empty-editor.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-0.99.2-human-draft.txt +32 -0
- package/skills/teamsmith/tests/frames/pi-1.0.0-git-error-in-box.txt +32 -0
- package/skills/teamsmith/tests/gate-guard.sh +112 -0
- package/skills/teamsmith/tests/guard-matrix.sh +233 -0
- package/skills/teamsmith/tests/install-shape.sh +731 -0
- package/skills/teamsmith/tests/ledger-ban.sh +612 -0
- package/skills/teamsmith/tests/lib/box-judge.sh +68 -0
- package/skills/teamsmith/tests/lib/checkout-shape.sh +129 -0
- package/skills/teamsmith/tests/lib/loop-scan.awk +114 -0
- package/skills/teamsmith/tests/lib/pty-wait.sh +676 -0
- package/skills/teamsmith/tests/lib/section-guard.sh +855 -0
- package/skills/teamsmith/tests/lib/shell-lex.pl +261 -0
- package/skills/teamsmith/tests/lib/tmp-root.sh +528 -0
- package/skills/teamsmith/tests/lib/tmux-cap.sh +35 -0
- package/skills/teamsmith/tests/lib/tmux-iso-call-probe.sh +81 -0
- package/skills/teamsmith/tests/lib/tmux-iso-probe.sh +46 -0
- package/skills/teamsmith/tests/lib/tmux-iso.sh +381 -0
- package/skills/teamsmith/tests/load-experiment.sh +290 -0
- package/skills/teamsmith/tests/loop-inventory.tsv +84 -0
- package/skills/teamsmith/tests/panel-b2-slow-stub.sh +19 -0
- package/skills/teamsmith/tests/panel-b2.sh +1183 -0
- package/skills/teamsmith/tests/panel-b3-pty-mouse.py +240 -0
- package/skills/teamsmith/tests/panel-b3-pty-tmux-mouse.py +138 -0
- package/skills/teamsmith/tests/panel-b3-stub.sh +279 -0
- package/skills/teamsmith/tests/panel-b3.sh +1301 -0
- package/skills/teamsmith/tests/panel-choices.sh +572 -0
- package/skills/teamsmith/tests/panel-clipboard-model.ts +187 -0
- package/skills/teamsmith/tests/panel-compose-model.ts +290 -0
- package/skills/teamsmith/tests/panel-contrast.mjs +81 -0
- package/skills/teamsmith/tests/panel-cpu-premise.sh +173 -0
- package/skills/teamsmith/tests/panel-cpu.sh +391 -0
- package/skills/teamsmith/tests/panel-flip-m54.sh +207 -0
- package/skills/teamsmith/tests/panel-flip-p123.sh +278 -0
- package/skills/teamsmith/tests/panel-flip-p125.sh +318 -0
- package/skills/teamsmith/tests/panel-flip-p128.sh +259 -0
- package/skills/teamsmith/tests/panel-keyprobe-pty.py +99 -0
- package/skills/teamsmith/tests/panel-keyprobe-stub.sh +41 -0
- package/skills/teamsmith/tests/panel-keyprobe.sh +82 -0
- package/skills/teamsmith/tests/panel-keyprobe.tsx +116 -0
- package/skills/teamsmith/tests/panel-knobs.sh +83 -0
- package/skills/teamsmith/tests/panel-p21.sh +2181 -0
- package/skills/teamsmith/tests/panel-snapshots.sh +802 -0
- package/skills/teamsmith/tests/panel-strings.mjs +195 -0
- package/skills/teamsmith/tests/perf.sh +740 -0
- package/skills/teamsmith/tests/pm-box-real.sh +350 -0
- package/skills/teamsmith/tests/pulse-nudge-key.sh +563 -0
- package/skills/teamsmith/tests/routes.sh +1652 -0
- package/skills/teamsmith/tests/section-budgets.tsv +150 -0
- package/skills/teamsmith/tests/section-guard.sh +231 -0
- package/skills/teamsmith/tests/section-needs-audit.sh +94 -0
- package/skills/teamsmith/tests/section-paths.tsv +142 -0
- package/skills/teamsmith/tests/section-select.sh +655 -0
- package/skills/teamsmith/tests/signal-gate.sh +366 -0
- package/skills/teamsmith/tests/signal-lint-legacy.txt +14 -0
- package/skills/teamsmith/tests/signal-lint.pl +416 -0
- package/skills/teamsmith/tests/skill-load.mjs +65 -0
- package/skills/teamsmith/tests/smoke.sh +19711 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-dark-99.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-120.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-160.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-detail.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-59.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99-p4.txt +32 -0
- package/skills/teamsmith/tests/snapshots/zh-light-99.txt +32 -0
- package/skills/teamsmith/tests/spec-ledger-refs.tsv +78 -0
- package/skills/teamsmith/tests/spec-refs.sh +826 -0
- package/skills/teamsmith/tests/task-header-model.sh +267 -0
- package/skills/teamsmith/tests/team-bg-flip.sh +239 -0
- package/skills/teamsmith/tests/team-bg-harness.mjs +392 -0
- package/skills/teamsmith/tests/team-bg-stop.sh +434 -0
- package/skills/teamsmith/tests/team-inbox-watch-flip.sh +191 -0
- package/skills/teamsmith/tests/team-inbox-watch-harness.mjs +1559 -0
- package/skills/teamsmith/tests/tmp-hygiene.sh +1190 -0
- package/skills/teamsmith/tests/tmux-lint-legacy.txt +31 -0
- package/skills/teamsmith/tests/tmux-lint.pl +604 -0
- package/skills/teamsmith-init/SKILL.md +100 -0
- package/skills/teamsmith-init/references/bootstrap.md +74 -0
- package/skills/teamsmith-init/templates/bootstrap-prompt.md.tmpl +46 -0
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
// The clipboard probe's headless sibling (P20/B4, tasks.md 4.2): the pure probe order, the MIME
|
|
2
|
+
// rules and the temporary-file write, driven through an injected runner — plus the real bounded
|
|
3
|
+
// runner against a fake that never exits (the 1 s/3 s bound is part of the contract, not a hope).
|
|
4
|
+
//
|
|
5
|
+
// bun build panel-clipboard-model.ts --target=node --format=esm --outfile /tmp/panel-clipboard-model.js
|
|
6
|
+
// node /tmp/panel-clipboard-model.js
|
|
7
|
+
//
|
|
8
|
+
// Every case names itself; the first failing case prints its expectation and the exit code is 1.
|
|
9
|
+
// `panel-b2.sh clipboard` builds and runs this beside the pty scenarios.
|
|
10
|
+
|
|
11
|
+
import { chmodSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
|
12
|
+
import { tmpdir } from 'node:os'
|
|
13
|
+
import { join } from 'node:path'
|
|
14
|
+
import {
|
|
15
|
+
CLIPBOARD_LIST_TIMEOUT_MS,
|
|
16
|
+
CLIPBOARD_MAX_BYTES,
|
|
17
|
+
CLIPBOARD_READ_TIMEOUT_MS,
|
|
18
|
+
createClipboardRunner,
|
|
19
|
+
imageExt,
|
|
20
|
+
pasteFilePath,
|
|
21
|
+
pickImageMime,
|
|
22
|
+
readClipboard,
|
|
23
|
+
writePasteFile,
|
|
24
|
+
type ClipboardRunner,
|
|
25
|
+
} from '../scripts/panel/src/clipboard.js'
|
|
26
|
+
|
|
27
|
+
type Case = { name: string; run: () => Promise<string | null> | string | null }
|
|
28
|
+
|
|
29
|
+
const cases: Case[] = []
|
|
30
|
+
const check = (name: string, run: Case['run']): void => {
|
|
31
|
+
cases.push({ name, run })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const eq = (what: string, got: unknown, want: unknown): string | null =>
|
|
35
|
+
JSON.stringify(got) === JSON.stringify(want) ? null : `${what}: got ${JSON.stringify(got)}, want ${JSON.stringify(want)}`
|
|
36
|
+
|
|
37
|
+
const BYTES = 'PNGDATA8'
|
|
38
|
+
|
|
39
|
+
/** A runner over a per-command script: null = the executable does not exist. */
|
|
40
|
+
function fakeRunner(script: Record<string, (args: string[]) => { stdout: string; rc: number } | null>): {
|
|
41
|
+
run: ClipboardRunner
|
|
42
|
+
calls: string[]
|
|
43
|
+
} {
|
|
44
|
+
const calls: string[] = []
|
|
45
|
+
const run: ClipboardRunner = async (cmd, args) => {
|
|
46
|
+
calls.push(`${cmd} ${args.join(' ')}`)
|
|
47
|
+
const handler = script[cmd]
|
|
48
|
+
if (!handler) return null
|
|
49
|
+
const out = handler(args)
|
|
50
|
+
return out === null ? null : { stdout: Buffer.from(out.stdout), rc: out.rc }
|
|
51
|
+
}
|
|
52
|
+
return { run, calls }
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
check('wayland: the image read comes from wl-paste and xclip is never called', async () => {
|
|
56
|
+
const { run, calls } = fakeRunner({
|
|
57
|
+
'wl-paste': (args) => {
|
|
58
|
+
if (args[0] === '--list-types') return { stdout: 'text/plain;charset=utf-8\nimage/png\n', rc: 0 }
|
|
59
|
+
if (args[0] === '--type' && args[1] === 'image/png') return { stdout: BYTES, rc: 0 }
|
|
60
|
+
return { stdout: '', rc: 1 }
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
const read = await readClipboard(run)
|
|
64
|
+
if (!read || read.kind !== 'image') return `read: ${JSON.stringify(read)}`
|
|
65
|
+
return (
|
|
66
|
+
eq('mime', read.mime, 'image/png') ??
|
|
67
|
+
eq('bytes', read.bytes.toString(), BYTES) ??
|
|
68
|
+
eq('calls', calls, ['wl-paste --list-types', 'wl-paste --type image/png --no-newline'])
|
|
69
|
+
)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
check('mime: the offered list order picks the type, and only the four are accepted', () => {
|
|
73
|
+
return (
|
|
74
|
+
eq('first accepted in list order', pickImageMime('image/gif\nimage/png\n'), 'image/gif') ??
|
|
75
|
+
eq('png after text', pickImageMime('text/plain\nimage/png'), 'image/png') ??
|
|
76
|
+
eq('parameters are stripped', pickImageMime('image/jpeg;charset=binary'), 'image/jpeg') ??
|
|
77
|
+
eq('svg is outside the four', pickImageMime('image/svg+xml'), null) ??
|
|
78
|
+
eq('empty', pickImageMime(''), null)
|
|
79
|
+
)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
check('mime: the four extensions, and nothing for anything else', () => {
|
|
83
|
+
return (
|
|
84
|
+
eq('png', imageExt('image/png'), 'png') ??
|
|
85
|
+
eq('jpeg', imageExt('image/jpeg'), 'jpg') ??
|
|
86
|
+
eq('webp', imageExt('image/webp'), 'webp') ??
|
|
87
|
+
eq('gif', imageExt('image/gif'), 'gif') ??
|
|
88
|
+
eq('svg', imageExt('image/svg+xml'), null)
|
|
89
|
+
)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
check('temp file: ${TMPDIR}/teamsmith-paste-<uuid>.<ext> with the image bytes', () => {
|
|
93
|
+
const dir = mkdtempSync(join(tmpdir(), 'panel-clipboard-'))
|
|
94
|
+
try {
|
|
95
|
+
const path = writePasteFile(Buffer.from(BYTES), 'image/jpeg', dir, 'fixed-uuid')
|
|
96
|
+
if (!path) return 'writePasteFile returned null'
|
|
97
|
+
if (!path.endsWith('teamsmith-paste-fixed-uuid.jpg')) return `path: ${path}`
|
|
98
|
+
return (
|
|
99
|
+
eq('promised path', pasteFilePath('image/jpeg', dir, 'fixed-uuid'), path) ??
|
|
100
|
+
eq('bytes on disk', readFileSync(path, 'utf8'), BYTES) ??
|
|
101
|
+
eq('an unaccepted MIME writes nothing', writePasteFile(Buffer.from(BYTES), 'image/svg+xml', dir, 'x'), null)
|
|
102
|
+
)
|
|
103
|
+
} finally {
|
|
104
|
+
rmSync(dir, { recursive: true, force: true })
|
|
105
|
+
}
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
check('text fallback: no image offered means the clipboard text, still no xclip', async () => {
|
|
109
|
+
const { run, calls } = fakeRunner({
|
|
110
|
+
'wl-paste': (args) => {
|
|
111
|
+
if (args[0] === '--list-types') return { stdout: 'text/plain;charset=utf-8\n', rc: 0 }
|
|
112
|
+
if (args[0] === '--no-newline') return { stdout: 'from the clipboard', rc: 0 }
|
|
113
|
+
return { stdout: '', rc: 1 }
|
|
114
|
+
},
|
|
115
|
+
xclip: () => ({ stdout: 'should not be called', rc: 0 }),
|
|
116
|
+
})
|
|
117
|
+
const read = await readClipboard(run)
|
|
118
|
+
return (
|
|
119
|
+
eq('read', read, { kind: 'text', text: 'from the clipboard' }) ??
|
|
120
|
+
(calls.some((c) => c.startsWith('xclip')) ? `xclip was called: ${calls.join(' | ')}` : null)
|
|
121
|
+
)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
check('x11 fallback: a failing wl-paste falls through to xclip, in that order', async () => {
|
|
125
|
+
const { run, calls } = fakeRunner({
|
|
126
|
+
'wl-paste': () => ({ stdout: '', rc: 1 }),
|
|
127
|
+
xclip: (args) => {
|
|
128
|
+
if (args.includes('TARGETS')) return { stdout: 'image/png\n', rc: 0 }
|
|
129
|
+
if (args.includes('image/png')) return { stdout: 'XCLIPDATA', rc: 0 }
|
|
130
|
+
return { stdout: '', rc: 1 }
|
|
131
|
+
},
|
|
132
|
+
})
|
|
133
|
+
const read = await readClipboard(run)
|
|
134
|
+
const wlIndex = calls.findIndex((c) => c.startsWith('wl-paste'))
|
|
135
|
+
const xIndex = calls.findIndex((c) => c.startsWith('xclip'))
|
|
136
|
+
return (
|
|
137
|
+
eq('image bytes', read && read.kind === 'image' ? read.bytes.toString() : read, 'XCLIPDATA') ??
|
|
138
|
+
(wlIndex >= 0 && xIndex > wlIndex ? null : `order: ${calls.join(' | ')}`)
|
|
139
|
+
)
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
check('no tool: every probe missing means null and no write', async () => {
|
|
143
|
+
const { run } = fakeRunner({})
|
|
144
|
+
return eq('read', await readClipboard(run), null)
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
check('bound: a never-exiting wl-paste resolves null within the contract', async () => {
|
|
148
|
+
const dir = mkdtempSync(join(tmpdir(), 'panel-clipboard-hang-'))
|
|
149
|
+
const oldPath = process.env.PATH
|
|
150
|
+
try {
|
|
151
|
+
writeFileSync(join(dir, 'wl-paste'), '#!/usr/bin/env bash\nexec /bin/sleep 60\n')
|
|
152
|
+
chmodSync(join(dir, 'wl-paste'), 0o755)
|
|
153
|
+
writeFileSync(join(dir, 'xclip'), '#!/usr/bin/env bash\nexit 1\n')
|
|
154
|
+
chmodSync(join(dir, 'xclip'), 0o755)
|
|
155
|
+
process.env.PATH = `${dir}:${oldPath ?? ''}`
|
|
156
|
+
const started = Date.now()
|
|
157
|
+
const read = await readClipboard(createClipboardRunner())
|
|
158
|
+
const elapsed = Date.now() - started
|
|
159
|
+
const budget = CLIPBOARD_LIST_TIMEOUT_MS + CLIPBOARD_READ_TIMEOUT_MS + 1500
|
|
160
|
+
if (read !== null) return `read: ${JSON.stringify(read)}`
|
|
161
|
+
return elapsed <= budget ? null : `took ${elapsed}ms (> ${budget}ms)`
|
|
162
|
+
} finally {
|
|
163
|
+
process.env.PATH = oldPath
|
|
164
|
+
rmSync(dir, { recursive: true, force: true })
|
|
165
|
+
}
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
check('bound: the byte cap is 50 MiB and the timeouts are the contract s', () => {
|
|
169
|
+
return (
|
|
170
|
+
eq('max bytes', CLIPBOARD_MAX_BYTES, 50 * 1024 * 1024) ??
|
|
171
|
+
eq('list timeout', CLIPBOARD_LIST_TIMEOUT_MS, 1000) ??
|
|
172
|
+
eq('read timeout', CLIPBOARD_READ_TIMEOUT_MS, 3000)
|
|
173
|
+
)
|
|
174
|
+
})
|
|
175
|
+
|
|
176
|
+
let failed = 0
|
|
177
|
+
for (const c of cases) {
|
|
178
|
+
const detail = await c.run()
|
|
179
|
+
if (detail === null) {
|
|
180
|
+
console.log(`ok ${c.name}`)
|
|
181
|
+
} else {
|
|
182
|
+
console.log(`FAIL ${c.name}\n ${detail}`)
|
|
183
|
+
failed += 1
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
console.log(`panel-clipboard-model: ${cases.length - failed}/${cases.length} passed`)
|
|
187
|
+
process.exit(failed === 0 ? 0 : 1)
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
// The compose model's headless sibling (P20/B1, tasks.md 1.1): the pure insertion-point model,
|
|
2
|
+
// the row map and the window, driven without a terminal.
|
|
3
|
+
//
|
|
4
|
+
// bun build panel-compose-model.ts --target=node --format=esm --outfile /tmp/panel-compose-model.js
|
|
5
|
+
// node /tmp/panel-compose-model.js
|
|
6
|
+
//
|
|
7
|
+
// Every case names itself; the first failing case is printed with its expectation, and the exit
|
|
8
|
+
// code is 1. `panel-b2.sh` builds and runs this beside the pty scenarios, so a green bundle with a
|
|
9
|
+
// broken model is visible at both levels.
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
backspaceAt,
|
|
13
|
+
composeKey,
|
|
14
|
+
cpLength,
|
|
15
|
+
cursorView,
|
|
16
|
+
deleteAt,
|
|
17
|
+
findWordBackward,
|
|
18
|
+
findWordForward,
|
|
19
|
+
inputLines,
|
|
20
|
+
insertAt,
|
|
21
|
+
killSpan,
|
|
22
|
+
moveCursor,
|
|
23
|
+
popUndo,
|
|
24
|
+
pushKill,
|
|
25
|
+
pushUndo,
|
|
26
|
+
resetKillDirection,
|
|
27
|
+
ringEntry,
|
|
28
|
+
wordAfterEnd,
|
|
29
|
+
wordBackwardInLine,
|
|
30
|
+
wordBeforeStart,
|
|
31
|
+
wrapRows,
|
|
32
|
+
} from '../scripts/panel/src/compose.js'
|
|
33
|
+
|
|
34
|
+
type Case = { name: string; run: () => string | null }
|
|
35
|
+
|
|
36
|
+
const cases: Case[] = []
|
|
37
|
+
const check = (name: string, run: () => string | null): void => {
|
|
38
|
+
cases.push({ name, run })
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const eq = (what: string, got: unknown, want: unknown): string | null =>
|
|
42
|
+
JSON.stringify(got) === JSON.stringify(want) ? null : `${what}: got ${JSON.stringify(got)}, want ${JSON.stringify(want)}`
|
|
43
|
+
|
|
44
|
+
const draftOf = (rows: { text: string }[]): string => rows.map((r) => r.text).join('|')
|
|
45
|
+
|
|
46
|
+
check('cjk: insert and backspace move by codepoint, never half a glyph', () => {
|
|
47
|
+
const a = insertAt('ad', 1, '中文')
|
|
48
|
+
if (a.text !== 'a中文d' || a.cursor !== 3) return `insertAt: ${JSON.stringify(a)}`
|
|
49
|
+
const b = backspaceAt(a.text, 2)
|
|
50
|
+
return eq('backspaceAt over a wide glyph', b, { text: 'a文d', cursor: 1 })
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
check('emoji: an astral codepoint is one step and is never half-deleted', () => {
|
|
54
|
+
const a = insertAt('', 0, '🙂')
|
|
55
|
+
if (cpLength(a.text) !== 1 || a.cursor !== 1) return `insertAt astral: ${JSON.stringify(a)}`
|
|
56
|
+
const b = backspaceAt(a.text, 1)
|
|
57
|
+
return eq('backspaceAt astral', b, { text: '', cursor: 0 })
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
check('delete: removes the codepoint after the point', () => {
|
|
61
|
+
return eq('deleteAt', deleteAt('ab', 0), { text: 'b', cursor: 0 })
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
check('wrap: a 40-column room splits 40 x into 36 + 4', () => {
|
|
65
|
+
const rows = wrapRows('x'.repeat(40), 36)
|
|
66
|
+
if (rows.length !== 2) return `row count: ${rows.length}`
|
|
67
|
+
return (
|
|
68
|
+
eq('row 0 span', [rows[0].start, rows[0].end, rows[0].text.length], [0, 36, 36]) ??
|
|
69
|
+
eq('row 1 span', [rows[1].start, rows[1].end, rows[1].text.length], [36, 40, 4])
|
|
70
|
+
)
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
check('wrap: a wide glyph counts two columns in the wrap', () => {
|
|
74
|
+
const rows = wrapRows('中文中文', 4)
|
|
75
|
+
if (rows.length !== 2) return `row count: ${rows.length}`
|
|
76
|
+
return eq('spans', rows.map((r) => [r.start, r.end, r.text]), [[0, 2, '中文'], [2, 4, '中文']])
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
check('wrap: an explicit break starts a new row with its own span', () => {
|
|
80
|
+
const rows = wrapRows('ab\nXXXXXXXX', 36)
|
|
81
|
+
if (rows.length !== 2) return `row count: ${rows.length}`
|
|
82
|
+
return (
|
|
83
|
+
eq('line 0', [rows[0].start, rows[0].end, rows[0].line, rows[0].text], [0, 2, 0, 'ab']) ??
|
|
84
|
+
eq('line 1', [rows[1].start, rows[1].end, rows[1].line, rows[1].text], [3, 11, 1, 'XXXXXXXX'])
|
|
85
|
+
)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
check('inputLines: the cursor-at-the-end output is unchanged for a short draft', () => {
|
|
89
|
+
return eq('inputLines(10)', inputLines('message', '中文ab', 10), ['> 中文ab'])
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
check('inputLines: a logical break and a wrap keep the prompt/continuation prefixes', () => {
|
|
93
|
+
return eq('inputLines(8)', inputLines('message', 'abcdefgh\nij', 8), ['> abcdef', ' gh', ' ij'])
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
check('move: left/right step codepoints and clamp at the ends', () => {
|
|
97
|
+
return (
|
|
98
|
+
eq('left over a wide glyph', moveCursor('中文ab', 3, 'left', { width: 10 }), 2) ??
|
|
99
|
+
eq('left clamps', moveCursor('中文ab', 0, 'left', { width: 10 }), 0) ??
|
|
100
|
+
eq('right clamps', moveCursor('中文ab', 4, 'right', { width: 10 }), 4)
|
|
101
|
+
)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
check('move: up/down walk visual rows at the same column, clamped', () => {
|
|
105
|
+
return (
|
|
106
|
+
eq('up clamps to the shorter row', moveCursor('ab\nXXXXXXXX', 11, 'up', { width: 40 }), 2) ??
|
|
107
|
+
eq('down keeps the column', moveCursor('ab\nXXXXXXXX', 2, 'down', { width: 40 }), 5)
|
|
108
|
+
)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
check('move: up/down walk wrapped rows of one logical line', () => {
|
|
112
|
+
const draft = 'x'.repeat(40)
|
|
113
|
+
return (
|
|
114
|
+
eq('up from the wrapped row lands on the first', moveCursor(draft, 40, 'up', { width: 38 }), 4) ??
|
|
115
|
+
eq('down from the first lands on the wrapped row', moveCursor(draft, 4, 'down', { width: 38 }), 40)
|
|
116
|
+
)
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
check('move: lineStart/lineEnd are the logical line, not the drawn row', () => {
|
|
120
|
+
return (
|
|
121
|
+
eq('lineStart on the second line', moveCursor('alpha\nbeta', 10, 'lineStart', { width: 40 }), 6) ??
|
|
122
|
+
eq('lineEnd on the first line', moveCursor('alpha\nbeta', 2, 'lineEnd', { width: 40 }), 5) ??
|
|
123
|
+
eq('lineEnd clamps at the draft end', moveCursor('alpha\nbeta', 10, 'lineEnd', { width: 40 }), 10)
|
|
124
|
+
)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
check('view: the point on the first row is drawn there with the tray column', () => {
|
|
128
|
+
const view = cursorView('message', `Z${'x'.repeat(40)}`, 1, 38, 10, '↑{n} 行')
|
|
129
|
+
return (
|
|
130
|
+
eq('lines', view.lines, [`> Z${'x'.repeat(35)}`, ` ${'x'.repeat(5)}`]) ??
|
|
131
|
+
eq('cursorLine', view.cursorLine, 0) ??
|
|
132
|
+
eq('cursorColumn (2 prompt + 1 Z)', view.cursorColumn, 3) ??
|
|
133
|
+
eq('window start', [view.start, view.hiddenAbove], [0, 0])
|
|
134
|
+
)
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
check('view: a 30-row draft in a 10-row window shows the tail plus a counted marker', () => {
|
|
138
|
+
const draft = Array.from({ length: 30 }, (_, i) => `L${String(i + 1).padStart(2, '0')}`).join('\n')
|
|
139
|
+
const view = cursorView('message', draft, cpLength(draft), 120, 10, '↑{n} 行')
|
|
140
|
+
if (view.lines.length > 10) return `window shows ${view.lines.length} rows (> 10)`
|
|
141
|
+
if (!view.lines[view.lines.length - 1].includes('L30')) return `the point's row is not drawn: ${JSON.stringify(view.lines)}`
|
|
142
|
+
return (
|
|
143
|
+
eq('marker counts the hidden rows above', view.lines[0], '↑21 行') ??
|
|
144
|
+
eq('the point is on the last drawn row', view.cursorLine, view.lines.length - 1) ??
|
|
145
|
+
eq('hiddenAbove', view.hiddenAbove, 21)
|
|
146
|
+
)
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
check('view: the window follows the point and counts fewer hidden rows', () => {
|
|
150
|
+
const draft = Array.from({ length: 30 }, (_, i) => `L${String(i + 1).padStart(2, '0')}`).join('\n')
|
|
151
|
+
let point = cpLength(draft)
|
|
152
|
+
for (let i = 0; i < 12; i += 1) point = moveCursor(draft, point, 'up', { width: 120, pageRows: 9 })
|
|
153
|
+
const view = cursorView('message', draft, point, 120, 10, '↑{n} 行')
|
|
154
|
+
const shown = view.lines.join('\n')
|
|
155
|
+
return (
|
|
156
|
+
(shown.includes('L18') ? null : `L18's row is not drawn: ${JSON.stringify(view.lines)}`) ??
|
|
157
|
+
eq('fewer hidden rows above', view.hiddenAbove, 9)
|
|
158
|
+
)
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
// ------------------------------------------------------------------ B2: words, ring, undo, keys
|
|
162
|
+
|
|
163
|
+
check('word: pi\'s backward rule skips whitespace and stops at the word start', () => {
|
|
164
|
+
return (
|
|
165
|
+
eq('end of a word', findWordBackward('alpha beta gamma', 16), 11) ??
|
|
166
|
+
eq('after the space', findWordBackward('alpha beta ', 11), 6) ??
|
|
167
|
+
eq('mid-word', findWordBackward('alpha beta', 8), 6) ??
|
|
168
|
+
eq('at zero', findWordBackward('alpha beta', 0), 0)
|
|
169
|
+
)
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
check('word: pi\'s forward rule skips whitespace and stops at the first punctuation', () => {
|
|
173
|
+
return (
|
|
174
|
+
eq('from the line start', findWordForward('alpha beta', 0), 5) ??
|
|
175
|
+
eq('from the separator', findWordForward('alpha beta', 5), 10) ??
|
|
176
|
+
eq('from the end', findWordForward('alpha beta', 10), 10) ??
|
|
177
|
+
eq('punctuation stops the word', findWordForward('a-b c', 0), 1)
|
|
178
|
+
)
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
check('word: ctrl+w cuts the preceding whitespace with the word (the requirement\'s ` gamma`)', () => {
|
|
182
|
+
return (
|
|
183
|
+
eq('at the line end', wordBeforeStart('alpha beta gamma', 16), 10) ??
|
|
184
|
+
eq('right after the word', wordBeforeStart('alpha beta', 10), 5) ??
|
|
185
|
+
eq('the movement itself keeps pi\'s boundary (no separator)', wordBackwardInLine('alpha beta', 10), 6) ??
|
|
186
|
+
eq('CJK runs stay whole (plus the separator)', wordBeforeStart('你好 世界', 5), 2) ??
|
|
187
|
+
eq('forward cuts the cursor-side gap', wordAfterEnd('alpha beta', 5), 10)
|
|
188
|
+
)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
check('kill: every deletion reports the span it cuts and its side', () => {
|
|
192
|
+
return (
|
|
193
|
+
eq('char before', killSpan('ab', 2, 'charBefore'), { from: 1, to: 2, text: 'b', direction: 'backward' }) ??
|
|
194
|
+
eq('char after', killSpan('ab', 1, 'charAfter'), { from: 1, to: 2, text: 'b', direction: 'forward' }) ??
|
|
195
|
+
eq('word before', killSpan('alpha beta gamma', 16, 'wordBefore'), { from: 10, to: 16, text: ' gamma', direction: 'backward' }) ??
|
|
196
|
+
eq('word after', killSpan('alpha beta', 5, 'wordAfter'), { from: 5, to: 10, text: ' beta', direction: 'forward' }) ??
|
|
197
|
+
eq('line before', killSpan('alpha\nbeta', 8, 'lineBefore'), { from: 6, to: 8, text: 'be', direction: 'backward' }) ??
|
|
198
|
+
eq('line after', killSpan('alpha\nbeta', 2, 'lineAfter'), { from: 2, to: 5, text: 'pha', direction: 'forward' }) ??
|
|
199
|
+
eq('nothing to cut', killSpan('ab', 0, 'charBefore'), null)
|
|
200
|
+
)
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
check('ring: the same-side kills accumulate, the tenth entry is the bound', () => {
|
|
204
|
+
let ring = { entries: [] as string[], lastDirection: null as 'backward' | 'forward' | null }
|
|
205
|
+
ring = pushKill(ring, ' gamma', 'backward')
|
|
206
|
+
ring = pushKill(ring, ' beta', 'backward')
|
|
207
|
+
if (ring.entries.length !== 1 || ring.entries[0] !== ' beta gamma') return `accumulated head: ${JSON.stringify(ring.entries)}`
|
|
208
|
+
ring = pushKill(ring, 'alpha ', 'forward')
|
|
209
|
+
if (ring.entries.length !== 2 || ring.entries[0] !== 'alpha ') return `direction change starts an entry: ${JSON.stringify(ring.entries)}`
|
|
210
|
+
for (let i = 0; i < 20; i += 1) {
|
|
211
|
+
ring = resetKillDirection(ring)
|
|
212
|
+
ring = pushKill(ring, `x${i}`, 'forward')
|
|
213
|
+
}
|
|
214
|
+
if (ring.entries.length !== 10) return `ring bound: ${ring.entries.length}`
|
|
215
|
+
return eq('the newest entry is the head', ring.entries[0], 'x19')
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
check('ring: a non-kill action breaks accumulation, and pop walks older entries', () => {
|
|
219
|
+
let ring = pushKill({ entries: [], lastDirection: null }, 'one', 'backward')
|
|
220
|
+
ring = pushKill(ring, 'two', 'backward')
|
|
221
|
+
ring = resetKillDirection(ring)
|
|
222
|
+
ring = pushKill(ring, 'three', 'backward')
|
|
223
|
+
return (
|
|
224
|
+
eq('reset starts a new entry', ring.entries, ['three', 'twoone']) ??
|
|
225
|
+
eq('yank head', ringEntry(ring, 0), 'three') ??
|
|
226
|
+
eq('first pop', ringEntry(ring, 1), 'twoone') ??
|
|
227
|
+
eq('pop wraps', ringEntry(ring, 2), 'three')
|
|
228
|
+
)
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
check('undo: snapshots restore the text and the cursor, and the history is bounded', () => {
|
|
232
|
+
const stack: { text: string; cursor: number }[] = []
|
|
233
|
+
pushUndo(stack, 'ad', 2)
|
|
234
|
+
pushUndo(stack, 'aZd', 2)
|
|
235
|
+
const back = popUndo(stack)
|
|
236
|
+
if (!back || back.text !== 'aZd' || back.cursor !== 2) return `first pop: ${JSON.stringify(back)}`
|
|
237
|
+
const older = popUndo(stack)
|
|
238
|
+
if (!older || older.text !== 'ad' || older.cursor !== 2) return `second pop: ${JSON.stringify(older)}`
|
|
239
|
+
if (popUndo(stack) !== null) return 'an empty history must pop null'
|
|
240
|
+
for (let i = 0; i < 150; i += 1) pushUndo(stack, `t${i}`, i)
|
|
241
|
+
return eq('bound', stack.length, 100)
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
check('keys: the decoder maps both encodings to the same intents', () => {
|
|
245
|
+
const k = (input: string, flags: Record<string, boolean> = {}) => composeKey(input, flags)
|
|
246
|
+
return (
|
|
247
|
+
eq('the legacy lone LF is ctrl+j (newline), not submit', k('\n'), { kind: 'newline' }) ??
|
|
248
|
+
eq('the Kitty ctrl+j byte-pair is the newline key', k('j', { ctrl: true }), { kind: 'newline' }) ??
|
|
249
|
+
eq('kitty shift+enter is a newline', k('\r', { return: true, shift: true }), { kind: 'newline' }) ??
|
|
250
|
+
eq('enter still submits', k('\r', { return: true }), { kind: 'submit' }) ??
|
|
251
|
+
eq('esc', k('', { escape: true }), { kind: 'cancel' }) ??
|
|
252
|
+
eq('kitty ctrl+b', k('b', { ctrl: true }), { kind: 'move', motion: 'left' }) ??
|
|
253
|
+
eq('legacy ctrl+b', k('b', { ctrl: true }), { kind: 'move', motion: 'left' }) ??
|
|
254
|
+
eq('kitty alt+b', k('b', { meta: true }), { kind: 'move', motion: 'wordLeft' }) ??
|
|
255
|
+
eq('ctrl+left is a word move', k('', { ctrl: true, leftArrow: true }), { kind: 'move', motion: 'wordLeft' }) ??
|
|
256
|
+
eq('home', k('', { home: true }), { kind: 'move', motion: 'lineStart' }) ??
|
|
257
|
+
eq('ctrl+a', k('a', { ctrl: true }), { kind: 'move', motion: 'lineStart' }) ??
|
|
258
|
+
eq('ctrl+e is line end (the App still intercepts it until B3)', k('e', { ctrl: true }), { kind: 'move', motion: 'lineEnd' }) ??
|
|
259
|
+
eq('backspace', k('', { backspace: true }), { kind: 'kill', unit: 'charBefore' }) ??
|
|
260
|
+
eq('alt+backspace', k('', { backspace: true, meta: true }), { kind: 'kill', unit: 'wordBefore' }) ??
|
|
261
|
+
eq('delete', k('', { delete: true }), { kind: 'kill', unit: 'charAfter' }) ??
|
|
262
|
+
eq('ctrl+d', k('d', { ctrl: true }), { kind: 'kill', unit: 'charAfter' }) ??
|
|
263
|
+
eq('ctrl+w', k('w', { ctrl: true }), { kind: 'kill', unit: 'wordBefore' }) ??
|
|
264
|
+
eq('ctrl+u', k('u', { ctrl: true }), { kind: 'kill', unit: 'lineBefore' }) ??
|
|
265
|
+
eq('ctrl+k', k('k', { ctrl: true }), { kind: 'kill', unit: 'lineAfter' }) ??
|
|
266
|
+
eq('alt+d', k('d', { meta: true }), { kind: 'kill', unit: 'wordAfter' }) ??
|
|
267
|
+
eq('ctrl+y', k('y', { ctrl: true }), { kind: 'yank' }) ??
|
|
268
|
+
eq('alt+y', k('y', { meta: true }), { kind: 'yankPop' }) ??
|
|
269
|
+
eq('kitty ctrl+-', k('-', { ctrl: true }), { kind: 'undo' }) ??
|
|
270
|
+
eq('an unbound ctrl key is consumed', k('c', { ctrl: true }), { kind: 'none' }) ??
|
|
271
|
+
eq('an unbound alt key is consumed', k('z', { meta: true }), { kind: 'none' }) ??
|
|
272
|
+
eq('typing inserts', k('x'), { kind: 'insert', text: 'x' }) ??
|
|
273
|
+
eq('a paste is one insert', k('a\nb'), { kind: 'insert', text: 'a\nb' })
|
|
274
|
+
)
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
// ------------------------------------------------------------------ runner
|
|
278
|
+
|
|
279
|
+
let failed = 0
|
|
280
|
+
for (const c of cases) {
|
|
281
|
+
const detail = c.run()
|
|
282
|
+
if (detail === null) {
|
|
283
|
+
console.log(`ok ${c.name}`)
|
|
284
|
+
} else {
|
|
285
|
+
console.log(`FAIL ${c.name}\n ${detail}`)
|
|
286
|
+
failed += 1
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
console.log(`panel-compose-model: ${cases.length - failed}/${cases.length} passed`)
|
|
290
|
+
process.exit(failed === 0 ? 0 : 1)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Palette contrast gate for the two console themes (pulse-console B3, tasks.md 5.3).
|
|
3
|
+
//
|
|
4
|
+
// node skills/teamsmith/tests/panel-contrast.mjs [panel.js]
|
|
5
|
+
// node skills/teamsmith/tests/panel-contrast.mjs --palette-file bad.json # the flip
|
|
6
|
+
//
|
|
7
|
+
// Reads the declared palettes from the bundle (`--palette`) and computes the WCAG 2.x contrast
|
|
8
|
+
// ratio of every declared tone against its declared background **independently of the panel's own
|
|
9
|
+
// arithmetic**. Every pair must reach 4.5:1; a failure names the theme, the tone and the ratio.
|
|
10
|
+
//
|
|
11
|
+
// Exit: 0 every pair ≥ 4.5:1, 1 at least one below (or the palette could not be read), 2 usage/IO.
|
|
12
|
+
|
|
13
|
+
import { execFileSync } from 'node:child_process'
|
|
14
|
+
import { readFileSync } from 'node:fs'
|
|
15
|
+
import { dirname, join, resolve } from 'node:path'
|
|
16
|
+
import { fileURLToPath } from 'node:url'
|
|
17
|
+
|
|
18
|
+
const here = dirname(fileURLToPath(import.meta.url))
|
|
19
|
+
const BAR = 4.5
|
|
20
|
+
|
|
21
|
+
const args = process.argv.slice(2)
|
|
22
|
+
const fileIndex = args.indexOf('--palette-file')
|
|
23
|
+
let palettes
|
|
24
|
+
try {
|
|
25
|
+
if (fileIndex !== -1) {
|
|
26
|
+
palettes = JSON.parse(readFileSync(args[fileIndex + 1], 'utf8'))
|
|
27
|
+
if (palettes.palettes) palettes = palettes.palettes
|
|
28
|
+
} else {
|
|
29
|
+
const panel = resolve(args[0] || join(here, '..', 'scripts', 'panel', 'panel.js'))
|
|
30
|
+
const raw = execFileSync(process.execPath, [panel, '--palette'], { encoding: 'utf8' })
|
|
31
|
+
palettes = JSON.parse(raw).palettes
|
|
32
|
+
}
|
|
33
|
+
} catch (e) {
|
|
34
|
+
console.error(`✗ panel-contrast: cannot read the palettes: ${e.message}`)
|
|
35
|
+
process.exit(2)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const rgb = (hex) => {
|
|
39
|
+
const m = /^#?([0-9a-fA-F]{6})$/.exec(String(hex).trim())
|
|
40
|
+
if (!m) throw new Error(`not a hex color: ${hex}`)
|
|
41
|
+
const n = Number.parseInt(m[1], 16)
|
|
42
|
+
return [(n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff]
|
|
43
|
+
}
|
|
44
|
+
const luminance = (hex) => {
|
|
45
|
+
const [r, g, b] = rgb(hex).map((v) => {
|
|
46
|
+
const c = v / 255
|
|
47
|
+
return c <= 0.04045 ? c / 12.92 : ((c + 0.055) / 1.055) ** 2.4
|
|
48
|
+
})
|
|
49
|
+
return 0.2126 * r + 0.7152 * g + 0.0722 * b
|
|
50
|
+
}
|
|
51
|
+
const ratio = (a, b) => {
|
|
52
|
+
const la = luminance(a)
|
|
53
|
+
const lb = luminance(b)
|
|
54
|
+
return (Math.max(la, lb) + 0.05) / (Math.min(la, lb) + 0.05)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
let bad = 0
|
|
58
|
+
for (const [theme, palette] of Object.entries(palettes)) {
|
|
59
|
+
const bg = palette.bg
|
|
60
|
+
if (!bg) {
|
|
61
|
+
console.error(`✗ ${theme}: no declared background`)
|
|
62
|
+
bad++
|
|
63
|
+
continue
|
|
64
|
+
}
|
|
65
|
+
let themeBad = 0
|
|
66
|
+
for (const [tone, fg] of Object.entries(palette.tones ?? {})) {
|
|
67
|
+
const r = ratio(fg, bg)
|
|
68
|
+
if (r < BAR) {
|
|
69
|
+
console.error(`✗ ${theme}.${tone}: ${fg} on ${bg} = ${r.toFixed(2)}:1 (below ${BAR}:1)`)
|
|
70
|
+
bad++
|
|
71
|
+
themeBad++
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (themeBad === 0) console.log(`ok: ${theme} palette checked (${Object.keys(palette.tones ?? {}).length} pairs)`)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (bad > 0) {
|
|
78
|
+
console.error(`✗ panel-contrast: ${bad} pair(s) below ${BAR}:1`)
|
|
79
|
+
process.exit(1)
|
|
80
|
+
}
|
|
81
|
+
console.log(`panel-contrast: ok (every declared pair ≥ ${BAR}:1)`)
|