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,154 @@
|
|
|
1
|
+
// The clipboard probe (P20/B4): one small, injectable module.
|
|
2
|
+
//
|
|
3
|
+
// The console's `C-v` turns a clipboard image into a temporary file path. Everything the probe
|
|
4
|
+
// touches is a subprocess, so the one test seam is the executable name on `PATH` (design §8) — the
|
|
5
|
+
// fixtures put fakes first, and the headless sibling drives `readClipboard` through an injected
|
|
6
|
+
// runner. The probe is bounded by construction (1 s / 3 s / 50 MiB), runs only on a `C-v` press, and
|
|
7
|
+
// never deletes the file it writes.
|
|
8
|
+
|
|
9
|
+
import { randomUUID } from 'node:crypto'
|
|
10
|
+
import { spawn } from 'node:child_process'
|
|
11
|
+
import { writeFileSync } from 'node:fs'
|
|
12
|
+
import { tmpdir } from 'node:os'
|
|
13
|
+
import { join } from 'node:path'
|
|
14
|
+
|
|
15
|
+
/** One bounded subprocess: rc plus the stdout bytes; `null` = the executable does not exist. */
|
|
16
|
+
export interface ClipRun {
|
|
17
|
+
stdout: Buffer
|
|
18
|
+
rc: number
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type ClipboardRunner = (cmd: string, args: string[], timeoutMs: number) => Promise<ClipRun | null>
|
|
22
|
+
|
|
23
|
+
export type ClipboardRead =
|
|
24
|
+
| { kind: 'image'; bytes: Buffer; mime: string }
|
|
25
|
+
| { kind: 'text'; text: string }
|
|
26
|
+
| null
|
|
27
|
+
|
|
28
|
+
/** The offered-type list answers within 1 s, the byte read within 3 s and 50 MiB (design §8). */
|
|
29
|
+
export const CLIPBOARD_LIST_TIMEOUT_MS = 1000
|
|
30
|
+
export const CLIPBOARD_READ_TIMEOUT_MS = 3000
|
|
31
|
+
export const CLIPBOARD_MAX_BYTES = 50 * 1024 * 1024
|
|
32
|
+
|
|
33
|
+
/** The four MIME types the panel accepts, and the extension the temporary file gets. */
|
|
34
|
+
export const IMAGE_MIME_EXT: Readonly<Record<string, string>> = {
|
|
35
|
+
'image/png': 'png',
|
|
36
|
+
'image/jpeg': 'jpg',
|
|
37
|
+
'image/webp': 'webp',
|
|
38
|
+
'image/gif': 'gif',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The extension for an accepted image MIME, or null when it is outside the four. */
|
|
42
|
+
export function imageExt(mime: string): string | null {
|
|
43
|
+
return IMAGE_MIME_EXT[String(mime ?? '').trim().toLowerCase()] ?? null
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The first accepted image type in an offered-type list, in the list's own order. */
|
|
47
|
+
export function pickImageMime(list: string): string | null {
|
|
48
|
+
for (const raw of String(list ?? '').split('\n')) {
|
|
49
|
+
const mime = raw.split(';')[0].trim().toLowerCase()
|
|
50
|
+
if (mime && imageExt(mime)) return mime
|
|
51
|
+
}
|
|
52
|
+
return null
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The probe order (wayland first, X11 second): `wl-paste` is the primary tool — when it answers,
|
|
57
|
+
* `xclip` is never called — and `xclip` is the fallback when `wl-paste` is missing or fails. Inside
|
|
58
|
+
* one tool the image type wins; with no image the tool's text read is the fallback.
|
|
59
|
+
*/
|
|
60
|
+
export async function readClipboard(run: ClipboardRunner): Promise<ClipboardRead> {
|
|
61
|
+
const wlTypes = await run('wl-paste', ['--list-types'], CLIPBOARD_LIST_TIMEOUT_MS)
|
|
62
|
+
if (wlTypes && wlTypes.rc === 0) {
|
|
63
|
+
const mime = pickImageMime(wlTypes.stdout.toString('utf8'))
|
|
64
|
+
if (mime) {
|
|
65
|
+
const img = await run('wl-paste', ['--type', mime, '--no-newline'], CLIPBOARD_READ_TIMEOUT_MS)
|
|
66
|
+
if (img && img.rc === 0 && img.stdout.length > 0 && img.stdout.length <= CLIPBOARD_MAX_BYTES) {
|
|
67
|
+
return { kind: 'image', bytes: img.stdout, mime }
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const text = await run('wl-paste', ['--no-newline', '--type', 'text'], CLIPBOARD_READ_TIMEOUT_MS)
|
|
71
|
+
if (text && text.rc === 0 && text.stdout.length > 0) return { kind: 'text', text: text.stdout.toString('utf8') }
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
const xTypes = await run('xclip', ['-selection', 'clipboard', '-t', 'TARGETS', '-o'], CLIPBOARD_LIST_TIMEOUT_MS)
|
|
75
|
+
if (xTypes && xTypes.rc === 0) {
|
|
76
|
+
const mime = pickImageMime(xTypes.stdout.toString('utf8'))
|
|
77
|
+
if (mime) {
|
|
78
|
+
const img = await run('xclip', ['-selection', 'clipboard', '-t', mime, '-o'], CLIPBOARD_READ_TIMEOUT_MS)
|
|
79
|
+
if (img && img.rc === 0 && img.stdout.length > 0 && img.stdout.length <= CLIPBOARD_MAX_BYTES) {
|
|
80
|
+
return { kind: 'image', bytes: img.stdout, mime }
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const text = await run('xclip', ['-selection', 'clipboard', '-o'], CLIPBOARD_READ_TIMEOUT_MS)
|
|
84
|
+
if (text && text.rc === 0 && text.stdout.length > 0) return { kind: 'text', text: text.stdout.toString('utf8') }
|
|
85
|
+
}
|
|
86
|
+
return null
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The temporary path the paste writes: `${TMPDIR:-/tmp}/teamsmith-paste-<uuid>.<ext>`. */
|
|
90
|
+
export function pasteFilePath(mime: string, dir = process.env.TMPDIR || tmpdir(), uuid?: string): string | null {
|
|
91
|
+
const ext = imageExt(mime)
|
|
92
|
+
if (!ext) return null
|
|
93
|
+
return join(dir, `teamsmith-paste-${uuid ?? randomUUID()}.${ext}`)
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Write the clipboard image bytes to the temporary path and return it. The panel never deletes the
|
|
98
|
+
* file (the requirement) and the path is the whole edit the console makes.
|
|
99
|
+
*/
|
|
100
|
+
export function writePasteFile(bytes: Buffer, mime: string, dir?: string, uuid?: string): string | null {
|
|
101
|
+
const file = pasteFilePath(mime, dir, uuid)
|
|
102
|
+
if (!file) return null
|
|
103
|
+
writeFileSync(file, bytes)
|
|
104
|
+
return file
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The real runner: `spawn` with a hard timeout and a stdout cap. A missing executable resolves
|
|
109
|
+
* `null`; a timeout kills the child and resolves `rc = 124` (never a hang), so a clipboard tool that
|
|
110
|
+
* never answers cannot hold the console.
|
|
111
|
+
*/
|
|
112
|
+
export function createClipboardRunner(): ClipboardRunner {
|
|
113
|
+
return (cmd, args, timeoutMs) =>
|
|
114
|
+
new Promise((resolve) => {
|
|
115
|
+
let child: ReturnType<typeof spawn>
|
|
116
|
+
try {
|
|
117
|
+
child = spawn(cmd, args, { stdio: ['ignore', 'pipe', 'ignore'] })
|
|
118
|
+
} catch {
|
|
119
|
+
resolve(null)
|
|
120
|
+
return
|
|
121
|
+
}
|
|
122
|
+
const chunks: Buffer[] = []
|
|
123
|
+
let size = 0
|
|
124
|
+
let settled = false
|
|
125
|
+
const finish = (rc: number | null): void => {
|
|
126
|
+
if (settled) return
|
|
127
|
+
settled = true
|
|
128
|
+
clearTimeout(timer)
|
|
129
|
+
resolve(rc === null ? null : { stdout: Buffer.concat(chunks), rc })
|
|
130
|
+
}
|
|
131
|
+
const kill = (): void => {
|
|
132
|
+
try {
|
|
133
|
+
child.kill('SIGKILL')
|
|
134
|
+
} catch {
|
|
135
|
+
/* already gone */
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
const timer = setTimeout(() => {
|
|
139
|
+
kill()
|
|
140
|
+
finish(124)
|
|
141
|
+
}, Math.max(1, timeoutMs))
|
|
142
|
+
child.on('error', () => finish(null))
|
|
143
|
+
child.stdout?.on('data', (data: Buffer) => {
|
|
144
|
+
size += data.length
|
|
145
|
+
if (size > CLIPBOARD_MAX_BYTES) {
|
|
146
|
+
kill()
|
|
147
|
+
finish(125)
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
chunks.push(data)
|
|
151
|
+
})
|
|
152
|
+
child.on('close', (code) => finish(code ?? 1))
|
|
153
|
+
})
|
|
154
|
+
}
|