docks-kit 0.23.0 → 0.25.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.
Files changed (59) hide show
  1. package/AGENTS.md +22 -138
  2. package/README.md +38 -23
  3. package/cli/docs/command-guards.md +5 -3
  4. package/cli/docs/flags.md +11 -29
  5. package/cli/docs/install.md +5 -4
  6. package/cli/docs/omp-context.md +79 -7
  7. package/cli/docs/omp-models.md +22 -15
  8. package/cli/docs/overview.md +5 -8
  9. package/cli/docs/sync-layers.md +55 -83
  10. package/cli/docs/toolchain.md +7 -8
  11. package/cli/src/argv.ts +0 -4
  12. package/cli/src/argvValidate.ts +2 -9
  13. package/cli/src/commands/docs.ts +2 -2
  14. package/cli/src/commands/omp.ts +1 -1
  15. package/cli/src/commands/scratch.ts +1 -1
  16. package/cli/src/commands/sync.ts +3 -24
  17. package/cli/src/commands/tidy.ts +1 -1
  18. package/cli/src/commands/update.ts +3 -3
  19. package/cli/src/engine-native/DESIGN.md +24 -35
  20. package/cli/src/engine-native/deps.ts +2 -7
  21. package/cli/src/engine-native/engineCtx.ts +3 -31
  22. package/cli/src/engine-native/failures.ts +2 -2
  23. package/cli/src/engine-native/index.ts +2 -2
  24. package/cli/src/engine-native/kitDb.ts +21 -37
  25. package/cli/src/engine-native/ompChild.ts +1 -1
  26. package/cli/src/engine-native/ompFastMode.ts +1 -1
  27. package/cli/src/engine-native/ompKitPlugin.ts +7 -16
  28. package/cli/src/engine-native/ompOverlay.ts +1 -1
  29. package/cli/src/engine-native/ompPlugins.ts +205 -221
  30. package/cli/src/engine-native/ompRemovals.ts +24 -3
  31. package/cli/src/engine-native/ompSession.ts +67 -0
  32. package/cli/src/engine-native/ompSync.ts +6 -15
  33. package/cli/src/engine-native/os/posix.ts +0 -1
  34. package/cli/src/engine-native/os/types.ts +0 -4
  35. package/cli/src/engine-native/os/windows.ts +0 -1
  36. package/cli/src/engine-native/parseArgs.ts +1 -61
  37. package/cli/src/engine-native/parseHelp.ts +1 -6
  38. package/cli/src/engine-native/scratch.ts +1 -1
  39. package/cli/src/engine-native/sharedTypes.d.ts +1 -1
  40. package/cli/src/engine-native/syncConcurrency.ts +3 -3
  41. package/cli/src/engine-native/syncDispatch.ts +26 -92
  42. package/cli/src/engine-native/toolchain.ts +1 -5
  43. package/cli/src/generated/sotPayload.ts +339 -17
  44. package/cli/src/main.ts +3 -7
  45. package/cli/tsconfig.json +1 -0
  46. package/package.json +2 -2
  47. package/cli/src/checklistPrompt.ts +0 -464
  48. package/cli/src/commands/harnesses.ts +0 -77
  49. package/cli/src/commands/skills.ts +0 -40
  50. package/cli/src/engine-native/harnesses.ts +0 -138
  51. package/cli/src/engine-native/ompMarketplace.ts +0 -140
  52. package/cli/src/engine-native/skillsInstall.ts +0 -135
  53. package/cli/src/engine-native/skillsLinks.ts +0 -216
  54. package/cli/src/engine-native/skillsManifest.ts +0 -36
  55. package/cli/src/engine-native/skillsPrune.ts +0 -117
  56. package/cli/src/engine-native/skillsRecords.ts +0 -138
  57. package/cli/src/engine-native/skillsSync.ts +0 -57
  58. package/cli/src/manifests.ts +0 -53
  59. package/cli/src/terminalCells.ts +0 -191
@@ -1,117 +0,0 @@
1
- /**
2
- * EngineNative kit skill prune (`--prune` reconcile against the owned record
3
- * of `skillsRecords.ts`). Split from skillsSync.ts; the orchestration still
4
- * lives there.
5
- *
6
- * The prune deletes only what the kit created: the canonical skill directory
7
- * of a slug in `.kit-owned-skills` and the kit-managed Claude entry. It
8
- * removes a canonical directory only while it keeps the `<dev>:<ino>` that
9
- * the owned record names. It does not call `skills remove`, because that
10
- * command deletes the same-named directory of every known agent. A slug that
11
- * only the legacy `.kit-managed-skills` names is kept with a message, because
12
- * an older kit also recorded directories that the user made.
13
- */
14
- import { existsSync, rmSync } from "node:fs";
15
- import { p } from "./exec";
16
- import type { Ctx } from "./index";
17
- import { compareCodepoints } from "./jq";
18
- import { isKitOwnedCopy, lstat, removeKitOwnedCopy, removeLink } from "./skillsLinks";
19
- import { normalizeManifest, skillBase } from "./skillsManifest";
20
- import { directoryIdentity, type SkillRecords } from "./skillsRecords";
21
-
22
- function removeCanonical(path: string): boolean {
23
- try {
24
- rmSync(path, { recursive: true, force: true });
25
- return true;
26
- } catch {
27
- return lstat(path) === undefined;
28
- }
29
- }
30
-
31
- /**
32
- * Removes each owned skill that the SoT no longer declares, and drops it from
33
- * `records.owned` (in memory). A failed removal keeps the slug, so the next
34
- * prune tries again. An owned slug whose directory is not the one that the
35
- * kit installed is kept with a line. It leaves the record, so the line prints
36
- * once. A legacy slug that the SoT dropped gets a keep line while its
37
- * canonical path still has an entry. Only the legacy record names it, so the
38
- * kit keeps it.
39
- */
40
- export function reconcileRemovals(ctx: Ctx, manifest: string, records: SkillRecords): void {
41
- const { change, echo, warn } = ctx.services.logger;
42
- if (ctx.dryRun && !existsSync(records.ownedFile)) {
43
- echo(
44
- `[dry-run] (--prune) no kit-owned-skills record yet; a sync writes ${records.ownedFile} when it installs a skill, and --prune removes only the skills that it names`,
45
- );
46
- }
47
-
48
- const current = normalizeManifest(manifest);
49
- const currentBases = new Set(current.map(skillBase));
50
- const declared = (slug: string): boolean =>
51
- current.includes(slug) || currentBases.has(skillBase(slug));
52
-
53
- for (const slug of [...records.legacy].sort(compareCodepoints)) {
54
- if (declared(slug) || records.owned.has(slug)) continue;
55
- if (lstat(p(ctx.agentsDir, "skills", skillBase(slug))) === undefined) continue;
56
- warn(
57
- `keep ${slug}: an older kit recorded it, so the kit cannot prove it installed it; remove it by hand if the kit did`,
58
- );
59
- }
60
-
61
- let removed = 0;
62
- let failed = 0;
63
- for (const slug of [...records.owned.keys()].sort(compareCodepoints)) {
64
- if (declared(slug)) continue;
65
- const base = skillBase(slug);
66
- const canonical = p(ctx.agentsDir, "skills", base);
67
- // The skills CLI installs a canonical skill as a real directory that holds
68
- // SKILL.md. A gone directory needs only the Claude entry cleanup.
69
- const canonicalStat = lstat(canonical);
70
- const installedCanonical =
71
- canonicalStat?.isDirectory() === true &&
72
- existsSync(p(canonical, "SKILL.md")) &&
73
- directoryIdentity(canonical) === records.owned.get(slug);
74
- if (canonicalStat !== undefined && !installedCanonical) {
75
- warn(`keep ${slug}: the directory is not the one that the kit installed`);
76
- if (!ctx.dryRun) records.owned.delete(slug);
77
- continue;
78
- }
79
- const claudeEntry = p(ctx.home, ".claude", "skills", base);
80
- const managedClaudeEntry =
81
- lstat(claudeEntry)?.isSymbolicLink() === true || isKitOwnedCopy(claudeEntry);
82
- if (ctx.dryRun) {
83
- echo(`[dry-run] kit-managed skill no longer in SoT — would remove: ${base}`);
84
- if (managedClaudeEntry) {
85
- echo(`[dry-run] kit-managed Claude skill entry — would remove: ~/.claude/skills/${base}`);
86
- }
87
- continue;
88
- }
89
- if (installedCanonical && !removeCanonical(canonical)) {
90
- warn(`Failed to remove kit-managed skill: ${base}`);
91
- failed++;
92
- continue;
93
- }
94
- if (managedClaudeEntry) {
95
- const entryStat = lstat(claudeEntry);
96
- const removedClaudeEntry =
97
- entryStat === undefined ||
98
- (entryStat.isSymbolicLink() ? removeLink(claudeEntry) : removeKitOwnedCopy(claudeEntry));
99
- if (!removedClaudeEntry) {
100
- warn(`Failed to remove kit-managed Claude skill entry: ${base}`);
101
- failed++;
102
- continue;
103
- }
104
- }
105
- records.owned.delete(slug);
106
- removed++;
107
- }
108
-
109
- if (removed > 0) {
110
- change(`Kit-managed skills removed (-${removed})`);
111
- ctx.nextStepTriggers.skillsRestart = true;
112
- }
113
- if (failed > 0)
114
- warn(
115
- `${failed} skill remove(s) failed — re-run with --prune, or delete ~/.agents/skills/<name> and the ~/.claude/skills/<name> link manually`,
116
- );
117
- }
@@ -1,138 +0,0 @@
1
- /**
2
- * EngineNative skill ownership records under `~/.agents`:
3
- * - `.kit-pending-skills`, one slug per line: a slug whose install runs. Sync
4
- * adds it before `npx skills add` only when the canonical skill directory
5
- * does not exist. So it never names a directory that existed before the
6
- * install.
7
- * - `.kit-owned-skills`, one `<slug>\t<dev>:<ino>` line per skill: the skills
8
- * that the kit installed, with the identity of the directory that the
9
- * install created. It is the only record that lets `--prune` remove a
10
- * skill, and only while the directory keeps that identity.
11
- * - `.kit-managed-skills`: the legacy snapshot. An older kit also recorded
12
- * directories that the user made there, so sync reads it and never writes
13
- * it, and its entries never let `--prune` remove a skill.
14
- *
15
- * After each install, sync writes the owned record before the slug leaves the
16
- * pending record, and before the next install starts. So a sync that stops at
17
- * any point leaves each installed slug in one of the two records. The next
18
- * sync moves a leftover pending slug to the owned record when its directory
19
- * exists, and drops it otherwise.
20
- */
21
- import { existsSync, lstatSync, readFileSync, rmSync } from "node:fs";
22
- import { replaceTextIfChanged } from "./atomicWrite";
23
- import { p } from "./exec";
24
- import type { Ctx } from "./index";
25
- import { compareCodepoints } from "./jq";
26
- import { isDir, lstat } from "./skillsLinks";
27
- import { normalizeManifest, skillBase } from "./skillsManifest";
28
-
29
- export interface SkillRecords {
30
- readonly ownedFile: string;
31
- readonly pendingFile: string;
32
- readonly legacyFile: string;
33
- /** Each owned slug and the `<dev>:<ino>` identity of the directory that its install created. */
34
- readonly owned: Map<string, string>;
35
- readonly pending: Set<string>;
36
- readonly legacy: ReadonlySet<string>;
37
- }
38
-
39
- /** The `<dev>:<ino>` identity of the entry at `path`, or undefined when no entry exists. */
40
- export function directoryIdentity(path: string): string | undefined {
41
- // bigint keeps a Windows file index exact; a number loses digits above 2^53.
42
- const stats = lstatSync(path, { bigint: true, throwIfNoEntry: false });
43
- return stats === undefined ? undefined : `${stats.dev}:${stats.ino}`;
44
- }
45
-
46
- function readSlugs(file: string): Set<string> {
47
- return new Set(existsSync(file) ? normalizeManifest(readFileSync(file, "utf8")) : []);
48
- }
49
-
50
- /**
51
- * Read the owned record. A line with no identity keeps the slug with an empty
52
- * identity, which matches no directory, so it never lets `--prune` remove one.
53
- */
54
- function readOwned(file: string): Map<string, string> {
55
- const owned = new Map<string, string>();
56
- if (!existsSync(file)) return owned;
57
- for (const line of readFileSync(file, "utf8").split("\n")) {
58
- const [slug = "", identity = ""] = line.trim().split("\t");
59
- if (slug !== "") owned.set(slug, identity);
60
- }
61
- return owned;
62
- }
63
-
64
- function slugLines(slugs: ReadonlySet<string>): string {
65
- const sorted = [...slugs].sort(compareCodepoints);
66
- return sorted.length > 0 ? `${sorted.join("\n")}\n` : "";
67
- }
68
-
69
- function ownedLines(owned: ReadonlyMap<string, string>): string {
70
- const slugs = [...owned.keys()].sort(compareCodepoints);
71
- return slugs.map((slug) => `${slug}\t${owned.get(slug) ?? ""}\n`).join("");
72
- }
73
-
74
- export function readSkillRecords(agentsDir: string): SkillRecords {
75
- const ownedFile = p(agentsDir, ".kit-owned-skills");
76
- const pendingFile = p(agentsDir, ".kit-pending-skills");
77
- const legacyFile = p(agentsDir, ".kit-managed-skills");
78
- return {
79
- ownedFile,
80
- pendingFile,
81
- legacyFile,
82
- owned: readOwned(ownedFile),
83
- pending: readSlugs(pendingFile),
84
- legacy: readSlugs(legacyFile),
85
- };
86
- }
87
-
88
- /** True when the canonical skill directory of `slug` has no entry, so an install creates it. */
89
- export function canonicalAbsent(skillsDir: string, slug: string): boolean {
90
- return lstat(p(skillsDir, skillBase(slug))) === undefined;
91
- }
92
-
93
- /**
94
- * Ends the pending state of `slug`. When its canonical directory exists, the
95
- * slug moves to the owned record with the identity of that directory. Else it
96
- * leaves the pending record. A slug that the owned record already names keeps
97
- * its identity. A sync that stopped between the two record writes leaves the
98
- * slug in both records, and the directory can change before the next sync.
99
- * Changes the records in memory only; `writeSkillRecords` writes them.
100
- */
101
- export function settlePendingSlug(records: SkillRecords, skillsDir: string, slug: string): void {
102
- if (!records.pending.delete(slug) || records.owned.has(slug)) return;
103
- const canonical = p(skillsDir, skillBase(slug));
104
- const identity = isDir(canonical) ? directoryIdentity(canonical) : undefined;
105
- if (identity !== undefined) records.owned.set(slug, identity);
106
- }
107
-
108
- /**
109
- * Records `slug` as pending and writes the pending record before its install
110
- * starts. The canonical directory is gone, so an owned identity of the slug is
111
- * stale. It leaves the owned record first, so the install can record the new
112
- * directory.
113
- */
114
- export function recordPendingInstall(records: SkillRecords, slug: string): void {
115
- if (records.owned.delete(slug)) {
116
- replaceTextIfChanged(records.ownedFile, ownedLines(records.owned));
117
- }
118
- records.pending.add(slug);
119
- replaceTextIfChanged(records.pendingFile, slugLines(records.pending));
120
- }
121
-
122
- /**
123
- * Writes the owned record, then the pending record, so a sync that stops
124
- * between the two writes keeps the pending slugs for the next sync. An empty
125
- * pending record is removed. Writes nothing under dry run.
126
- */
127
- export function writeSkillRecords(ctx: Ctx, records: SkillRecords): void {
128
- if (ctx.dryRun) return;
129
- const owned = ownedLines(records.owned);
130
- if (owned !== "" || existsSync(records.ownedFile)) {
131
- replaceTextIfChanged(records.ownedFile, owned);
132
- }
133
- if (records.pending.size > 0) {
134
- replaceTextIfChanged(records.pendingFile, slugLines(records.pending));
135
- } else {
136
- rmSync(records.pendingFile, { force: true });
137
- }
138
- }
@@ -1,57 +0,0 @@
1
- /**
2
- * EngineNative `sync agents` pipeline: universal-skill bootstrap
3
- * (`npx skills@<pin> add`), Claude symlink healing, --prune reconcile against
4
- * the kit-owned record, and the record writes.
5
- *
6
- * Split: manifest parsing lives in `skillsManifest.ts`, link mechanics and
7
- * healing in `skillsLinks.ts`, the install pass in `skillsInstall.ts`, the
8
- * ownership records in `skillsRecords.ts`, and the prune in `skillsPrune.ts`.
9
- * This module keeps the orchestration and re-exports the public surface so
10
- * existing import paths keep working.
11
- */
12
- import { mkdirSync } from "node:fs";
13
- import { payloadText } from "../payload";
14
- import { p } from "./exec";
15
- import type { Ctx } from "./index";
16
- import { syncUniversal, type SkillsState } from "./skillsInstall";
17
- import { reconcileRemovals } from "./skillsPrune";
18
- import { readSkillRecords, settlePendingSlug, writeSkillRecords } from "./skillsRecords";
19
-
20
- export type { SkillsState } from "./skillsInstall";
21
- export { COPY_MARKER, linkOrCopy, type LinkOutcome } from "./skillsLinks";
22
- export { normalizeManifest } from "./skillsManifest";
23
-
24
- export async function skillsSync(ctx: Ctx): Promise<SkillsState> {
25
- const state: SkillsState = { present: 0 };
26
- const skillsDir = p(ctx.agentsDir, "skills");
27
- const manifest = payloadText("SoT/.agents/skills.txt");
28
- const records = readSkillRecords(ctx.agentsDir);
29
-
30
- if (!ctx.dryRun) mkdirSync(skillsDir, { recursive: true });
31
-
32
- // A pending slug that an earlier sync left: its install ran, but its record did not.
33
- for (const slug of [...records.pending]) settlePendingSlug(records, skillsDir, slug);
34
- writeSkillRecords(ctx, records);
35
-
36
- await syncUniversal(ctx, state, skillsDir, manifest, records);
37
- // An owned slug leaves the record only after a successful --prune removes it.
38
- if (ctx.prune) reconcileRemovals(ctx, manifest, records);
39
- writeSkillRecords(ctx, records);
40
- return state;
41
- }
42
-
43
- // -------------------------------------------------------------- summary ----
44
-
45
- export function skillsSummary(ctx: Ctx, state: SkillsState): void {
46
- const { echo } = ctx.services.logger;
47
- echo(`Skills: ${p(ctx.agentsDir, "skills")}`);
48
- if (!ctx.dryRun) {
49
- echo(` ${state.present} universal skill(s) installed`);
50
- }
51
- }
52
-
53
- export function skillsNextSteps(ctx: Ctx): Array<string> {
54
- return ctx.verbose || ctx.nextStepTriggers.skillsRestart
55
- ? ["Restart Claude Code to discover newly installed universal skills."]
56
- : [];
57
- }
@@ -1,53 +0,0 @@
1
- import { existsSync, lstatSync, readdirSync, readlinkSync } from "node:fs";
2
- import { dirname, join, resolve } from "node:path";
3
- import { engineHome } from "./engine-native/harnesses";
4
- import { skillBase } from "./engine-native/skillsManifest";
5
- import { COPY_MARKER } from "./engine-native/skillsSync";
6
- import { payloadText } from "./payload";
7
-
8
- /** Universal skills: SoT manifest slugs vs ~/.agents/skills contents. */
9
- export const skillsView = (): Array<{
10
- skill: string;
11
- declared: boolean;
12
- installed: boolean;
13
- /** Claude entry resolves to the canonical skill by symlink, junction, or kit-created copy. */
14
- claudeSymlink: boolean;
15
- }> => {
16
- const declared = payloadText("SoT/.agents/skills.txt")
17
- .split("\n")
18
- .map((l) => l.replace(/#.*$/, "").trim())
19
- .filter((l) => l.length > 0)
20
- .map(skillBase);
21
- const home = engineHome();
22
- const skillsDir = join(home, ".agents", "skills");
23
- const installed = existsSync(skillsDir)
24
- ? readdirSync(skillsDir, { withFileTypes: true })
25
- .filter((e) => e.isDirectory())
26
- .map((e) => e.name)
27
- : [];
28
- const names = new Set([...declared, ...installed]);
29
- return [...names].sort().map((skill) => {
30
- const link = join(home, ".claude", "skills", skill);
31
- const canonical = resolve(skillsDir, skill);
32
- let claudeSymlink = false;
33
- try {
34
- const target = resolve(dirname(link), readlinkSync(link));
35
- claudeSymlink = target === canonical && existsSync(target);
36
- } catch {
37
- /* not a symlink or missing */
38
- }
39
- if (!claudeSymlink && installed.includes(skill)) {
40
- try {
41
- claudeSymlink = lstatSync(link).isDirectory() && existsSync(join(link, COPY_MARKER));
42
- } catch {
43
- /* missing Claude entry */
44
- }
45
- }
46
- return {
47
- skill,
48
- declared: declared.includes(skill),
49
- installed: installed.includes(skill),
50
- claudeSymlink,
51
- };
52
- });
53
- };
@@ -1,191 +0,0 @@
1
- // Marks (variation selectors included), controls, and format characters such
2
- // as the zero-width joiner use no cell.
3
- const ZERO_WIDTH = /[\p{Mark}\p{Cc}\p{Cf}]/u;
4
-
5
- // The code points with East Asian Width W or F, after UAX #11
6
- // (https://www.unicode.org/reports/tr11/). The W data also holds the emoji
7
- // presentation characters, so emoji need no separate rule.
8
- // Source: https://www.unicode.org/Public/18.0.0/ucd/EastAsianWidth.txt
9
- // (Unicode 18.0.0, sha256
10
- // a0cf29eacd00cfcaec4381c6b7c281685f18dbb4e7ff82b4076ccb342ca839aa).
11
- // Derivation: take every code point with East_Asian_Width W or F, then merge
12
- // adjacent ranges. The ranges are sorted and do not overlap. To update the
13
- // table, derive it again the same way from a newer EastAsianWidth.txt.
14
- const WIDE_RANGES: ReadonlyArray<readonly [number, number]> = [
15
- [0x1100, 0x115f],
16
- [0x231a, 0x231b],
17
- [0x2329, 0x232a],
18
- [0x23e9, 0x23ec],
19
- [0x23f0, 0x23f0],
20
- [0x23f3, 0x23f3],
21
- [0x25fd, 0x25fe],
22
- [0x2614, 0x2615],
23
- [0x2630, 0x2637],
24
- [0x2648, 0x2653],
25
- [0x267f, 0x267f],
26
- [0x268a, 0x268f],
27
- [0x2693, 0x2693],
28
- [0x26a1, 0x26a1],
29
- [0x26aa, 0x26ab],
30
- [0x26bd, 0x26be],
31
- [0x26c4, 0x26c5],
32
- [0x26ce, 0x26ce],
33
- [0x26d4, 0x26d4],
34
- [0x26ea, 0x26ea],
35
- [0x26f2, 0x26f3],
36
- [0x26f5, 0x26f5],
37
- [0x26fa, 0x26fa],
38
- [0x26fd, 0x26fd],
39
- [0x2705, 0x2705],
40
- [0x270a, 0x270b],
41
- [0x2728, 0x2728],
42
- [0x274c, 0x274c],
43
- [0x274e, 0x274e],
44
- [0x2753, 0x2755],
45
- [0x2757, 0x2757],
46
- [0x2795, 0x2797],
47
- [0x27b0, 0x27b0],
48
- [0x27bf, 0x27bf],
49
- [0x2b1b, 0x2b1c],
50
- [0x2b50, 0x2b50],
51
- [0x2b55, 0x2b55],
52
- [0x2e80, 0x2e99],
53
- [0x2e9b, 0x2ef3],
54
- [0x2f00, 0x2fd5],
55
- [0x2ff0, 0x303e],
56
- [0x3041, 0x3096],
57
- [0x3099, 0x30ff],
58
- [0x3105, 0x312f],
59
- [0x3131, 0x318e],
60
- [0x3190, 0x31e5],
61
- [0x31ef, 0x321e],
62
- [0x3220, 0x3247],
63
- [0x3250, 0xa48c],
64
- [0xa490, 0xa4c6],
65
- [0xa960, 0xa97c],
66
- [0xac00, 0xd7a3],
67
- [0xf900, 0xfaff],
68
- [0xfe10, 0xfe19],
69
- [0xfe30, 0xfe52],
70
- [0xfe54, 0xfe66],
71
- [0xfe68, 0xfe6b],
72
- [0xff01, 0xff60],
73
- [0xffe0, 0xffe6],
74
- [0x16fe0, 0x16fe4],
75
- [0x16ff0, 0x16ff6],
76
- [0x17000, 0x18cda],
77
- [0x18cff, 0x18d20],
78
- [0x18d80, 0x18df2],
79
- [0x18e00, 0x19191],
80
- [0x191a0, 0x191d2],
81
- [0x1aff0, 0x1aff3],
82
- [0x1aff5, 0x1affb],
83
- [0x1affd, 0x1affe],
84
- [0x1b000, 0x1b128],
85
- [0x1b132, 0x1b132],
86
- [0x1b150, 0x1b152],
87
- [0x1b155, 0x1b155],
88
- [0x1b164, 0x1b168],
89
- [0x1b170, 0x1b2fb],
90
- [0x1d300, 0x1d356],
91
- [0x1d360, 0x1d376],
92
- [0x1f004, 0x1f004],
93
- [0x1f0cf, 0x1f0cf],
94
- [0x1f18e, 0x1f18e],
95
- [0x1f191, 0x1f19a],
96
- [0x1f1ae, 0x1f1ae],
97
- [0x1f200, 0x1f202],
98
- [0x1f210, 0x1f23b],
99
- [0x1f240, 0x1f248],
100
- [0x1f250, 0x1f251],
101
- [0x1f260, 0x1f265],
102
- [0x1f300, 0x1f320],
103
- [0x1f32d, 0x1f335],
104
- [0x1f337, 0x1f37c],
105
- [0x1f37e, 0x1f393],
106
- [0x1f3a0, 0x1f3ca],
107
- [0x1f3cf, 0x1f3d3],
108
- [0x1f3e0, 0x1f3f0],
109
- [0x1f3f4, 0x1f3f4],
110
- [0x1f3f8, 0x1f43e],
111
- [0x1f440, 0x1f440],
112
- [0x1f442, 0x1f4fc],
113
- [0x1f4ff, 0x1f53d],
114
- [0x1f54b, 0x1f54e],
115
- [0x1f550, 0x1f567],
116
- [0x1f57a, 0x1f57a],
117
- [0x1f595, 0x1f596],
118
- [0x1f5a4, 0x1f5a4],
119
- [0x1f5fb, 0x1f64f],
120
- [0x1f680, 0x1f6c5],
121
- [0x1f6cc, 0x1f6cc],
122
- [0x1f6d0, 0x1f6d2],
123
- [0x1f6d5, 0x1f6d9],
124
- [0x1f6dc, 0x1f6df],
125
- [0x1f6eb, 0x1f6ec],
126
- [0x1f6f4, 0x1f6fc],
127
- [0x1f7da, 0x1f7da],
128
- [0x1f7e0, 0x1f7eb],
129
- [0x1f7f0, 0x1f7f0],
130
- [0x1f90c, 0x1f93a],
131
- [0x1f93c, 0x1f945],
132
- [0x1f947, 0x1f9ff],
133
- [0x1fa70, 0x1fa7c],
134
- [0x1fa80, 0x1fac6],
135
- [0x1fac8, 0x1fac8],
136
- [0x1facc, 0x1fadd],
137
- [0x1fadf, 0x1faeb],
138
- [0x1faef, 0x1fafa],
139
- [0x20000, 0x2fffd],
140
- [0x30000, 0x3fffd],
141
- ];
142
-
143
- function isWide(point: number): boolean {
144
- let low = 0;
145
- let high = WIDE_RANGES.length - 1;
146
- while (low <= high) {
147
- const middle = (low + high) >> 1;
148
- const [first, last] = WIDE_RANGES[middle] ?? [0, -1];
149
- if (point < first) high = middle - 1;
150
- else if (point > last) low = middle + 1;
151
- else return true;
152
- }
153
- return false;
154
- }
155
-
156
- function charCells(char: string): number {
157
- if (ZERO_WIDTH.test(char)) return 0;
158
- return isWide(char.codePointAt(0) ?? 0) ? 2 : 1;
159
- }
160
-
161
- /**
162
- * The terminal cells of `text`: 0 for each mark, control, or format
163
- * character; 2 for each character with East Asian Width W or F; else 1.
164
- */
165
- export function terminalCells(text: string): number {
166
- let cells = 0;
167
- for (const char of text) cells += charCells(char);
168
- return cells;
169
- }
170
-
171
- /**
172
- * The rows that `text` uses on a terminal `columns` wide (a value below 1
173
- * counts as 1). A terminal never splits a character: a wide character that
174
- * does not fit in the rest of a row moves to the next row and leaves the last
175
- * cell of the row empty. An empty text uses 1 row.
176
- */
177
- export function terminalRows(text: string, columns: number): number {
178
- const width = Math.max(1, columns);
179
- let rows = 1;
180
- let column = 0;
181
- for (const char of text) {
182
- const cells = charCells(char);
183
- if (cells === 0) continue;
184
- if (column !== 0 && column + cells > width) {
185
- rows += 1;
186
- column = 0;
187
- }
188
- column += cells;
189
- }
190
- return rows;
191
- }