@tackup/cli 0.0.0 → 0.1.1-exp.pr144.g5661267

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 (83) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +16 -1
  3. package/dist/builtins/extensions/docs/guides/day-two.md +3 -0
  4. package/dist/builtins/extensions/docs/guides/onboarding-2.md +3 -0
  5. package/dist/builtins/extensions/docs/guides/onboarding-3.md +3 -0
  6. package/dist/builtins/extensions/docs/skills/use-tack-docs/SKILL.md +67 -0
  7. package/dist/builtins/extensions/docs/skills/use-tack-docs/references/declare-docs.md +71 -0
  8. package/dist/builtins/extensions/docs/skills/use-tack-docs/references/docs-in-profiles.md +25 -0
  9. package/dist/builtins/extensions/docs/skills/use-tack-docs/references/docs-maintenance.md +35 -0
  10. package/dist/builtins/extensions/docs/skills/use-tack-docs/references/review.md +34 -0
  11. package/dist/builtins/extensions/docs/skills/write-reader-figures/SKILL.md +66 -0
  12. package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figure-components.md +20 -0
  13. package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/architecture-map.md +86 -0
  14. package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/chart.md +52 -0
  15. package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/figure.md +79 -0
  16. package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/file-tree.md +74 -0
  17. package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/schema.md +116 -0
  18. package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/system.md +81 -0
  19. package/dist/builtins/extensions/docs/skills/write-reader-figures/references/figures/walkthrough.md +45 -0
  20. package/dist/builtins/extensions/docs/skills/write-reader-figures/references/page-components.md +82 -0
  21. package/dist/builtins/extensions/docs/skills/write-reader-figures/references/rules.md +27 -0
  22. package/dist/builtins/extensions/docs/tack.yaml +10 -0
  23. package/dist/builtins/extensions/scripts/guides/day-two.md +3 -0
  24. package/dist/builtins/extensions/scripts/guides/onboarding-2.md +3 -0
  25. package/dist/builtins/extensions/scripts/skills/author-tack-scripts/SKILL.md +48 -0
  26. package/dist/builtins/extensions/scripts/skills/author-tack-scripts/references/run-scripts.md +23 -0
  27. package/dist/builtins/extensions/scripts/skills/author-tack-scripts/references/script-api.md +76 -0
  28. package/dist/builtins/extensions/scripts/skills/author-tack-scripts/references/scripts-in-profiles.md +35 -0
  29. package/dist/builtins/extensions/scripts/skills/author-tack-scripts/references/scripts-in-sources.md +56 -0
  30. package/dist/builtins/extensions/scripts/tack.yaml +10 -0
  31. package/dist/builtins/skills/author-tack-profiles/SKILL.md +68 -0
  32. package/dist/builtins/skills/author-tack-profiles/references/apply.md +33 -0
  33. package/dist/builtins/skills/author-tack-profiles/references/bundles.md +59 -0
  34. package/dist/builtins/skills/author-tack-profiles/references/copy-workflows.md +46 -0
  35. package/dist/builtins/skills/manage-tack-sources/SKILL.md +75 -0
  36. package/dist/builtins/skills/manage-tack-sources/references/catalog-issues.md +38 -0
  37. package/dist/builtins/skills/manage-tack-sources/references/metadata.md +35 -0
  38. package/dist/builtins/skills/manage-tack-sources/references/tack-yaml.md +114 -0
  39. package/dist/builtins/skills/manage-tack-sources/references/worked-source.md +126 -0
  40. package/dist/builtins/skills/prepare-tack-checkout/SKILL.md +52 -0
  41. package/dist/builtins/skills/use-tack/SKILL.md +65 -0
  42. package/dist/builtins/skills/use-tack/references/agent-instructions.md +38 -0
  43. package/dist/builtins/skills/use-tack/references/day-two.md +35 -0
  44. package/dist/builtins/skills/use-tack/references/explore.md +13 -0
  45. package/dist/builtins/skills/use-tack/references/imports.md +30 -0
  46. package/dist/builtins/skills/use-tack/references/maintenance.md +51 -0
  47. package/dist/builtins/skills/use-tack/references/onboarding-2.md +41 -0
  48. package/dist/builtins/skills/use-tack/references/onboarding-3.md +29 -0
  49. package/dist/builtins/skills/use-tack/references/onboarding.md +54 -0
  50. package/dist/builtins/skills/use-tack/references/output.md +15 -0
  51. package/dist/builtins/skills/use-tack/references/selection.md +61 -0
  52. package/dist/builtins/skills/use-tack/references/setup.md +69 -0
  53. package/dist/builtins/tack.yaml +10 -0
  54. package/dist/bundle-support-C7OD5JEG.js +16 -0
  55. package/dist/chunk-2RUJGM5D.js +56 -0
  56. package/dist/chunk-3KGEOW4B.js +225 -0
  57. package/dist/chunk-BDOOV5W7.js +26 -0
  58. package/dist/chunk-C3K3AFJD.js +16 -0
  59. package/dist/chunk-E2SJQHKZ.js +281 -0
  60. package/dist/chunk-EOACX6VI.js +12401 -0
  61. package/dist/chunk-I25CGFRW.js +36671 -0
  62. package/dist/chunk-QW47O677.js +162 -0
  63. package/dist/chunk-QXSQ5MEX.js +28 -0
  64. package/dist/chunk-RZQCGAJF.js +5733 -0
  65. package/dist/chunk-SMY7ZPQQ.js +52 -0
  66. package/dist/chunk-VV2YFWGB.js +1791 -0
  67. package/dist/chunk-W76JFI2G.js +18013 -0
  68. package/dist/chunk-XTWP3LBL.js +1017 -0
  69. package/dist/chunk-ZTKVYMVR.js +92 -0
  70. package/dist/corpus-effects-IKUFX5HQ.js +12069 -0
  71. package/dist/elk.bundled-A4NY77AZ.js +94125 -0
  72. package/dist/main-K4VB62TY.js +65517 -0
  73. package/dist/main.js +17 -0
  74. package/dist/reader/visuals.tsx +368 -0
  75. package/dist/script.d.ts +133 -0
  76. package/dist/script.js +90 -0
  77. package/dist/server-R3ERJ4GJ.js +308 -0
  78. package/dist/src-RDHNYJMO.js +1871 -0
  79. package/dist/src-XIWV5BGG.js +1126 -0
  80. package/dist/tack-env.d.ts +137 -0
  81. package/dist/third-party-licenses.txt +2467 -0
  82. package/dist/worker-XBNGNPT7.js +24246 -0
  83. package/package.json +29 -3
package/dist/main.js ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as tackCreateRequire } from "node:module"; const require = tackCreateRequire(import.meta.url);
3
+ import {
4
+ workerCommand
5
+ } from "./chunk-3KGEOW4B.js";
6
+ import "./chunk-EOACX6VI.js";
7
+ import "./chunk-I25CGFRW.js";
8
+ import {
9
+ init_define_TACK_BUILD_INFO
10
+ } from "./chunk-2RUJGM5D.js";
11
+
12
+ // apps/cli/src/main.ts
13
+ init_define_TACK_BUILD_INFO();
14
+ if (process.argv[2] === workerCommand) void import("./worker-XBNGNPT7.js");
15
+ else void import("./main-K4VB62TY.js").then((cli) => cli.runMain());
16
+ /* v8 ignore start -- @preserve */
17
+ /* v8 ignore stop -- @preserve */
@@ -0,0 +1,368 @@
1
+ import { useState } from "react";
2
+ import type { ReactNode } from "react";
3
+ import { numericState, useVisualState } from "./state.ts";
4
+ import { visualStyles } from "./visual-styles.ts";
5
+ import { FigureFrame } from "./figures/frame.tsx";
6
+ import { chartIssues, walkthroughIssues } from "./figures/catalog.ts";
7
+
8
+ export type WalkthroughStep = {
9
+ readonly title: string;
10
+ readonly body: ReactNode;
11
+ readonly readable?: string;
12
+ };
13
+ export type WalkthroughProps = {
14
+ readonly id: string;
15
+ readonly title?: string;
16
+ readonly steps: readonly WalkthroughStep[];
17
+ };
18
+ export type ChartDatum = { readonly label: string; readonly value: number };
19
+ export type ChartScenario = {
20
+ readonly id: string;
21
+ readonly label: string;
22
+ readonly multiplier: number;
23
+ };
24
+ export type ChartProps = {
25
+ readonly id: string;
26
+ readonly title?: string;
27
+ readonly data: readonly ChartDatum[];
28
+ readonly unit?: string;
29
+ readonly scenarios?: readonly ChartScenario[];
30
+ };
31
+
32
+ const baselineScenario: ChartScenario = { id: "baseline", label: "Baseline", multiplier: 1 };
33
+ const defaultScenarios: readonly ChartScenario[] = [baselineScenario];
34
+
35
+ function stepReadable(step: WalkthroughStep): string {
36
+ return (
37
+ step.readable ??
38
+ (typeof step.body === "string" || typeof step.body === "number" ? String(step.body) : "")
39
+ );
40
+ }
41
+
42
+ /** Displays an authored sequence while keeping every step available to readable copy and search. */
43
+ export function Walkthrough({ id, title: authoredTitle, steps }: WalkthroughProps): ReactNode {
44
+ const title = authoredTitle ?? "Walkthrough";
45
+ const [state, update] = useVisualState(id);
46
+ const step =
47
+ steps.length === 0
48
+ ? 0
49
+ : numericState(state["step"], { fallback: 1, min: 1, max: steps.length, integer: true });
50
+ const readable = [
51
+ title,
52
+ ...steps.map((item, index) => `${index + 1}. ${item.title}\n${stepReadable(item)}`),
53
+ `Current step: ${step} of ${steps.length}`,
54
+ ].join("\n\n");
55
+ return (
56
+ <FigureFrame
57
+ id={id}
58
+ kind="steps"
59
+ title={title}
60
+ issues={walkthroughIssues({ id, title: authoredTitle, steps })}
61
+ readable={readable}
62
+ state={{ step }}
63
+ className="tack-walkthrough"
64
+ >
65
+ <div className="tack-figure-body">
66
+ <nav
67
+ aria-label={`${title} steps`}
68
+ className="flex overflow-x-auto border-b border-rule px-2.5"
69
+ >
70
+ {steps.map((item, index) => (
71
+ <button
72
+ key={index}
73
+ type="button"
74
+ aria-current={index + 1 === step ? "step" : undefined}
75
+ data-passed={index + 1 < step}
76
+ className={`group/step ${visualStyles.stepTab}`}
77
+ onClick={() => update({ step: String(index + 1) })}
78
+ >
79
+ <span
80
+ className={`${visualStyles.stepNumber} group-aria-[current=step]/step:text-pen group-data-[passed=true]/step:text-print`}
81
+ >
82
+ {index + 1}.
83
+ </span>{" "}
84
+ {item.title}
85
+ </button>
86
+ ))}
87
+ </nav>
88
+ {steps.length === 0 ? (
89
+ <p className={visualStyles.readout}>No steps have been authored.</p>
90
+ ) : (
91
+ steps.map((item, index) => (
92
+ <section
93
+ key={index}
94
+ hidden={index + 1 !== step}
95
+ aria-label={item.title}
96
+ className="px-4.5 pt-4.5 pb-5 font-serif text-base leading-relaxed"
97
+ >
98
+ <h3 className="mb-1.5">{item.title}</h3>
99
+ <div className="max-w-prose">{item.body}</div>
100
+ </section>
101
+ ))
102
+ )}
103
+ <div className={visualStyles.footer}>
104
+ <button
105
+ type="button"
106
+ aria-label="Previous step"
107
+ disabled={step <= 1}
108
+ onClick={() => update({ step: String(step - 1) })}
109
+ >
110
+ Previous
111
+ </button>
112
+ <output aria-live="polite" className={visualStyles.output}>
113
+ Step {step} of {steps.length}
114
+ </output>
115
+ <button
116
+ type="button"
117
+ aria-label="Next step"
118
+ disabled={step >= steps.length}
119
+ onClick={() => update({ step: String(step + 1) })}
120
+ >
121
+ Next
122
+ </button>
123
+ </div>
124
+ </div>
125
+ </FigureFrame>
126
+ );
127
+ }
128
+
129
+ /** Renders authored values with a reproducible scenario, multiplier, scale, and selection. */
130
+ export function Chart({
131
+ id,
132
+ title: authoredTitle,
133
+ data,
134
+ unit = "",
135
+ scenarios = defaultScenarios,
136
+ }: ChartProps): ReactNode {
137
+ const title = authoredTitle ?? "Chart";
138
+ const [state, update] = useVisualState(id);
139
+ const [hovered, setHovered] = useState<string | null>(null);
140
+ const availableScenarios = scenarios.length === 0 ? defaultScenarios : scenarios;
141
+ const scenario =
142
+ availableScenarios.find((item) => item.id === state["scenario"]) ??
143
+ availableScenarios[0] ??
144
+ baselineScenario;
145
+ const multiplier = numericState(state["multiplier"], { fallback: 1, min: 0.1, max: 5 });
146
+ const scale = state["scale"] === "sqrt" ? "sqrt" : "linear";
147
+ const values = data
148
+ .filter((item) => Number.isFinite(item.value) === true)
149
+ .map((item) => ({ ...item, value: item.value * multiplier * scenario.multiplier }));
150
+ const maximum = Math.max(1, ...values.map((item) => Math.abs(item.value)));
151
+ const selected = values.find((item) => item.label === state["selected"]);
152
+ const labelValue = (item: ChartDatum): string =>
153
+ `${item.label}: ${Number(item.value.toFixed(2))}${unit === "" ? "" : ` ${unit}`}`;
154
+ const readable = [
155
+ title,
156
+ ...values.map((item) => labelValue(item)),
157
+ `Scenario: ${scenario.label}; multiplier: ${multiplier}; scale: ${scale}; selected: ${selected?.label ?? "none"}`,
158
+ ].join("\n");
159
+ return (
160
+ <FigureFrame
161
+ id={id}
162
+ kind="quantities"
163
+ title={title}
164
+ issues={chartIssues({ id, title: authoredTitle, data })}
165
+ readable={readable}
166
+ state={{
167
+ scenario: scenario.id,
168
+ multiplier,
169
+ scale,
170
+ selected: selected?.label ?? null,
171
+ }}
172
+ className="tack-chart"
173
+ >
174
+ <div className="tack-figure-body">
175
+ <div className={visualStyles.toolbar}>
176
+ <label className={visualStyles.label}>
177
+ Scenario
178
+ <select
179
+ value={scenario.id}
180
+ onChange={(event) => update({ scenario: event.target.value })}
181
+ >
182
+ {availableScenarios.map((item) => (
183
+ <option key={item.id} value={item.id}>
184
+ {item.label}
185
+ </option>
186
+ ))}
187
+ </select>
188
+ </label>
189
+ <label className={visualStyles.label}>
190
+ Multiplier
191
+ <input
192
+ aria-label="Multiplier"
193
+ type="range"
194
+ min="0.1"
195
+ max="5"
196
+ step="0.1"
197
+ value={multiplier}
198
+ onChange={(event) => update({ multiplier: event.target.value })}
199
+ />
200
+ <output className={visualStyles.output}>{multiplier}×</output>
201
+ </label>
202
+ <label className={visualStyles.label}>
203
+ Scale
204
+ <select value={scale} onChange={(event) => update({ scale: event.target.value })}>
205
+ <option value="linear">Linear</option>
206
+ <option value="sqrt">Square root</option>
207
+ </select>
208
+ </label>
209
+ </div>
210
+ {values.length === 0 ? (
211
+ <p className={visualStyles.readout}>No values have been authored.</p>
212
+ ) : (
213
+ <svg
214
+ className="block h-auto w-full pt-2.5 pr-4.5 pb-1"
215
+ role="group"
216
+ aria-label={title}
217
+ viewBox={`0 0 640 ${values.length * 44 + 8}`}
218
+ >
219
+ <line
220
+ className="stroke-rule-strong"
221
+ x1="160"
222
+ x2="160"
223
+ y1="0"
224
+ y2={values.length * 44 + 8}
225
+ />
226
+ {values.map((item, index) => {
227
+ const magnitude = Math.abs(item.value) / maximum;
228
+ const width = (scale === "sqrt" ? Math.sqrt(magnitude) : magnitude) * 360;
229
+ const active = hovered === item.label || selected?.label === item.label;
230
+ return (
231
+ <g
232
+ key={item.label}
233
+ className="cursor-pointer focus-visible:outline-none"
234
+ data-active={active}
235
+ role="button"
236
+ tabIndex={0}
237
+ aria-label={labelValue(item)}
238
+ aria-pressed={selected?.label === item.label}
239
+ onClick={() =>
240
+ update({ selected: selected?.label === item.label ? null : item.label })
241
+ }
242
+ onKeyDown={(event) => {
243
+ if (event.key === "Enter" || event.key === " ") {
244
+ event.preventDefault();
245
+ update({ selected: selected?.label === item.label ? null : item.label });
246
+ }
247
+ }}
248
+ onMouseEnter={() => setHovered(item.label)}
249
+ onMouseLeave={() => setHovered(null)}
250
+ onFocus={() => setHovered(item.label)}
251
+ onBlur={() => setHovered(null)}
252
+ >
253
+ <title>{labelValue(item)}</title>
254
+ <rect x="0" y={index * 44} width="640" height="44" fill="transparent" />
255
+ <text
256
+ x="148"
257
+ y={index * 44 + 27}
258
+ textAnchor="end"
259
+ className="fill-body font-sans text-sm"
260
+ >
261
+ {item.label}
262
+ </text>
263
+ <rect
264
+ x="160"
265
+ y={index * 44 + 10}
266
+ width={Math.max(1, width)}
267
+ height="24"
268
+ rx="2"
269
+ className="transition-[width,fill] duration-300"
270
+ fill={
271
+ active === true
272
+ ? "var(--tack-visual-active)"
273
+ : item.value < 0
274
+ ? "var(--tack-visual-negative)"
275
+ : "var(--tack-visual-fill)"
276
+ }
277
+ />
278
+ <text
279
+ className={`font-mono text-xs ${active === true ? "fill-pen" : "fill-muted"}`}
280
+ x={170 + width}
281
+ y={index * 44 + 27}
282
+ >
283
+ {Number(item.value.toFixed(2))} {unit}
284
+ </text>
285
+ </g>
286
+ );
287
+ })}
288
+ </svg>
289
+ )}
290
+ <p aria-live="polite" className={visualStyles.readout}>
291
+ {selected === undefined
292
+ ? "Hover or select a bar to inspect its value."
293
+ : labelValue(selected)}
294
+ </p>
295
+ </div>
296
+ </FigureFrame>
297
+ );
298
+ }
299
+
300
+ import { ArchitectureMap } from "./figures/architecture-map.tsx";
301
+ import { FileTree } from "./figures/file-tree.tsx";
302
+ import { Badge, Band, Box, Drawing, Figure, Label, Link, Note } from "./figures/figure.tsx";
303
+ import { System } from "./figures/system.tsx";
304
+ import { Schema } from "./figures/schema.tsx";
305
+
306
+ export {
307
+ ArchitectureMap,
308
+ Badge,
309
+ Band,
310
+ Box,
311
+ Drawing,
312
+ Figure,
313
+ FileTree,
314
+ Label,
315
+ Link,
316
+ Note,
317
+ Schema,
318
+ System,
319
+ };
320
+ export type {
321
+ BadgeProps,
322
+ BandProps,
323
+ BoxProps,
324
+ DrawingProps,
325
+ FigureProps,
326
+ LabelProps,
327
+ LinkProps,
328
+ NoteProps,
329
+ } from "./figures/figure.tsx";
330
+ export type { FileTreeProps } from "./figures/file-tree-model.ts";
331
+ export type { SchemaColumnInput, SchemaProps, SchemaTableInput } from "./figures/schema-model.ts";
332
+ export type {
333
+ SystemGroupInput,
334
+ SystemLinkInput,
335
+ SystemNodeInput,
336
+ SystemProps,
337
+ } from "./figures/system-model.ts";
338
+
339
+ /**
340
+ * The components every document can use without importing them: the catalog figures and the kit
341
+ * elements of authored figures. A source's own components override them by name.
342
+ */
343
+ export const standardFigures = {
344
+ ArchitectureMap,
345
+ Badge,
346
+ Band,
347
+ Box,
348
+ Chart,
349
+ Drawing,
350
+ Figure,
351
+ FileTree,
352
+ Label,
353
+ Link,
354
+ Note,
355
+ Schema,
356
+ System,
357
+ Walkthrough,
358
+ };
359
+ export type {
360
+ ArchitectureLink,
361
+ ArchitectureMapProps,
362
+ ArchitectureNode,
363
+ ArchitectureTier,
364
+ } from "./figures/architecture-map-model.ts";
365
+
366
+ export { Icon } from "./icons/docs-icon.tsx";
367
+ export { Callout, Tab, Tabs, Term } from "./authoring/components.tsx";
368
+ export type { DocsIconName } from "./icons/catalog.ts";
@@ -0,0 +1,133 @@
1
+ /**
2
+ * The Tack script API: plain async functions, no Effect. The running Tack provides this module to a
3
+ * script under its published name, so a source installs nothing:
4
+ *
5
+ * ```ts
6
+ * import { defineScript } from "@tackup/cli";
7
+ *
8
+ * export default defineScript({
9
+ * args: { name: { type: "string", description: "Who to greet" } },
10
+ * run: async ({ args, log }) => {
11
+ * log(`Greeting ${args.name}`);
12
+ * return { greeting: `Hello, ${args.name}` };
13
+ * },
14
+ * });
15
+ * ```
16
+ *
17
+ * This module imports nothing, so it can be loaded on its own by any script under Node or Bun.
18
+ */
19
+ /** The value types an argument can take. */
20
+ export type ArgType = "string" | "number" | "boolean";
21
+ /** One named argument, in the shape of Node's `util.parseArgs` options plus `number` and `choices`. */
22
+ export type ArgSpec = {
23
+ readonly type: ArgType;
24
+ /** One line shown in argument errors. */
25
+ readonly description?: string;
26
+ /** Accept a list of values. */
27
+ readonly multiple?: boolean;
28
+ /** Allow the argument to be absent; it is then `undefined`. */
29
+ readonly optional?: boolean;
30
+ /** The value used when the argument is absent. */
31
+ readonly default?: string | number | boolean | ReadonlyArray<string | number | boolean>;
32
+ /** Restrict a string argument to these values. */
33
+ readonly choices?: ReadonlyArray<string>;
34
+ };
35
+ type Base<S> = S extends {
36
+ readonly type: "string";
37
+ readonly choices: ReadonlyArray<infer C>;
38
+ } ? C : S extends {
39
+ readonly type: "string";
40
+ } ? string : S extends {
41
+ readonly type: "number";
42
+ } ? number : boolean;
43
+ type ValueOf<S> = S extends {
44
+ readonly multiple: true;
45
+ } ? ReadonlyArray<Base<S>> : Base<S>;
46
+ type MayBeAbsent<S> = S extends {
47
+ readonly default: unknown;
48
+ } ? false : S extends {
49
+ readonly optional: true;
50
+ } ? true : false;
51
+ type Simplify<T> = {
52
+ [K in keyof T]: T[K];
53
+ } & {};
54
+ /** The parsed and validated arguments a script receives. */
55
+ export type Args<A extends Record<string, ArgSpec>> = Simplify<{
56
+ readonly [K in keyof A as MayBeAbsent<A[K]> extends true ? never : K]: ValueOf<A[K]>;
57
+ } & {
58
+ readonly [K in keyof A as MayBeAbsent<A[K]> extends true ? K : never]?: ValueOf<A[K]>;
59
+ }>;
60
+ /** Writes to the run's log. Calling it directly logs at info level. */
61
+ export type Log = ((...parts: ReadonlyArray<unknown>) => void) & {
62
+ readonly debug: (...parts: ReadonlyArray<unknown>) => void;
63
+ readonly info: (...parts: ReadonlyArray<unknown>) => void;
64
+ readonly warn: (...parts: ReadonlyArray<unknown>) => void;
65
+ readonly error: (...parts: ReadonlyArray<unknown>) => void;
66
+ };
67
+ /** Files, with relative paths resolved from `cwd`. Every call stops once the run is cancelled. */
68
+ export type Files = {
69
+ readonly read: (path: string) => Promise<string>;
70
+ readonly readJson: (path: string) => Promise<unknown>;
71
+ /** Creates parent directories as needed. */
72
+ readonly write: (path: string, content: string) => Promise<void>;
73
+ readonly writeJson: (path: string, value: unknown) => Promise<void>;
74
+ readonly exists: (path: string) => Promise<boolean>;
75
+ /** The files matching a glob, relative to `cwd`, sorted. */
76
+ readonly list: (pattern: string) => Promise<ReadonlyArray<string>>;
77
+ readonly remove: (path: string) => Promise<void>;
78
+ };
79
+ /** Options for one `exec` call. */
80
+ export type ExecOptions = {
81
+ readonly cwd?: string;
82
+ readonly env?: Readonly<Record<string, string>>;
83
+ /** Return the result instead of throwing when the command exits non-zero. */
84
+ readonly allowFailure?: boolean;
85
+ };
86
+ /** What one command printed and how it exited. */
87
+ export type ExecResult = {
88
+ readonly stdout: string;
89
+ readonly stderr: string;
90
+ readonly exitCode: number;
91
+ };
92
+ /** Runs one executable with an argument list, without a shell. Throws on a non-zero exit. */
93
+ export type Exec = (command: string, args?: ReadonlyArray<string>, options?: ExecOptions) => Promise<ExecResult>;
94
+ /** Everything Tack gives a running script. */
95
+ export type ScriptContext<A extends Record<string, ArgSpec>, S extends string> = {
96
+ readonly args: Args<A>;
97
+ /** The declared secrets. Tack replaces their values with `<redacted>` in logs and results. */
98
+ readonly secrets: {
99
+ readonly [K in S]: string;
100
+ };
101
+ readonly log: Log;
102
+ readonly fs: Files;
103
+ readonly exec: Exec;
104
+ /** The run's working directory: the selected project root or the user's home. */
105
+ readonly cwd: string;
106
+ /** Aborted when the operator cancels the run or it times out. */
107
+ readonly signal: AbortSignal;
108
+ /** Ends the run with an expected failure that the operator should read. */
109
+ readonly fail: (message: string, details?: unknown) => never;
110
+ };
111
+ /** What `defineScript` takes. */
112
+ export type ScriptOptions<A extends Record<string, ArgSpec>, S extends ReadonlyArray<string>> = {
113
+ readonly args?: A;
114
+ /** Names of operator secrets, read from `TACK_<NAME>` in the environment or the state `.env`. */
115
+ readonly secrets?: S;
116
+ /** The script. Return JSON data, or nothing. */
117
+ readonly run: (context: ScriptContext<A, S[number]>) => unknown;
118
+ };
119
+ declare const brand: unique symbol;
120
+ /** The value `defineScript` returns; export it as the module's default export. */
121
+ export type Script = {
122
+ readonly [brand]: 1;
123
+ };
124
+ /** Thrown by `defineScript` when a definition is malformed; the message says how to fix it. */
125
+ export declare class ScriptDefinitionError extends Error {
126
+ readonly name = "ScriptDefinitionError";
127
+ }
128
+ /**
129
+ * Declares a Tack script; export the result as the module's default export. A malformed definition
130
+ * throws {@link ScriptDefinitionError} when the module loads, listing every problem.
131
+ */
132
+ export declare function defineScript<const A extends Record<string, ArgSpec> = {}, const S extends ReadonlyArray<string> = []>(options: ScriptOptions<A, S>): Script;
133
+ export {};
package/dist/script.js ADDED
@@ -0,0 +1,90 @@
1
+ // packages/core/src/script-api.ts
2
+ var brand = Symbol.for("tack.script-api/1");
3
+ var ScriptDefinitionError = class extends Error {
4
+ name = "ScriptDefinitionError";
5
+ };
6
+ var optionKeys = ["args", "secrets", "run"];
7
+ var argKeys = ["type", "description", "multiple", "optional", "default", "choices"];
8
+ var argTypes = ["string", "number", "boolean"];
9
+ var isArgType = (value) => argTypes.some((type) => type === value);
10
+ var isRecord = (value) => typeof value === "object" && value !== null && Array.isArray(value) === false;
11
+ var closest = (word, known) => known.map((name) => ({
12
+ name,
13
+ shared: Array.from({ length: name.length }, (_, at) => at).findIndex(
14
+ (at) => word[at] !== name[at]
15
+ )
16
+ })).map(({ name, shared }) => ({ name, shared: shared === -1 ? name.length : shared })).reduce(
17
+ (best, candidate) => candidate.shared > best.shared ? candidate : best,
18
+ { shared: 0 }
19
+ ).name;
20
+ var expectedArgumentValue = (spec, value) => {
21
+ const typed = spec.type === "number" ? typeof value === "number" && Number.isFinite(value) : typeof value === spec.type;
22
+ if (typed === false) return `a ${spec.type}`;
23
+ if (spec.choices === void 0 || spec.choices.includes(String(value)) === true) return void 0;
24
+ return `one of ${spec.choices.join(", ")}`;
25
+ };
26
+ var shownDefault = (value) => typeof value === "number" ? String(value) : JSON.stringify(value);
27
+ var defaultProblems = (name, type, spec) => {
28
+ const fallback = spec["default"];
29
+ if (fallback === void 0) return [];
30
+ if (spec["multiple"] === true && Array.isArray(fallback) === false)
31
+ return [
32
+ `Argument "${name}" takes a list, so its default must be a list, got ${shownDefault(fallback)}.`
33
+ ];
34
+ const choices = Array.isArray(spec["choices"]) ? spec["choices"].map((choice) => String(choice)) : void 0;
35
+ const values = spec["multiple"] === true ? [fallback].flat() : [fallback];
36
+ return values.flatMap((value) => {
37
+ const expected = expectedArgumentValue({ type, choices }, value);
38
+ return expected === void 0 ? [] : [`Argument "${name}" has the default ${shownDefault(value)}, which is not ${expected}.`];
39
+ });
40
+ };
41
+ var argumentProblems = (name, spec) => {
42
+ if (/^[a-z][a-zA-Z0-9-]*$/.test(name) === false)
43
+ return [`Argument "${name}" needs a lower-camel or kebab name, such as "repo" or "dry-run".`];
44
+ if (isRecord(spec) === false || isArgType(spec["type"]) === false)
45
+ return [`Argument "${name}" needs a type: { type: "string" | "number" | "boolean" }.`];
46
+ const type = spec["type"];
47
+ const unknownFields = Object.keys(spec).flatMap(
48
+ (key) => argKeys.includes(key) === true ? [] : [`Argument "${name}" has no "${key}" field. Fields: ${argKeys.join(", ")}.`]
49
+ );
50
+ if (spec["choices"] !== void 0 && type !== "string")
51
+ return [
52
+ ...unknownFields,
53
+ `Argument "${name}" can only list choices when its type is "string".`
54
+ ];
55
+ return [...unknownFields, ...defaultProblems(name, type, spec)];
56
+ };
57
+ var definitionProblems = (options) => {
58
+ if (isRecord(options) === false)
59
+ return ["defineScript expects an object: defineScript({ run: async (context) => { ... } })."];
60
+ const unknownKeys = Object.keys(options).flatMap((key) => {
61
+ if (optionKeys.includes(key) === true) return [];
62
+ const suggestion = closest(key, optionKeys);
63
+ return [
64
+ `defineScript has no "${key}" option.${suggestion === void 0 ? "" : ` Did you mean "${suggestion}"?`} Options: ${optionKeys.join(", ")}.`
65
+ ];
66
+ });
67
+ const run = typeof options["run"] === "function" ? [] : ["defineScript needs a run function: run: async ({ args, log }) => { ... }."];
68
+ const args = isRecord(options["args"]) ? Object.entries(options["args"]).flatMap(([name, spec]) => argumentProblems(name, spec)) : options["args"] === void 0 ? [] : ['defineScript "args" must be an object of argument declarations.'];
69
+ const secrets = Array.isArray(options["secrets"]) ? options["secrets"].flatMap(
70
+ (name) => typeof name === "string" && /^[A-Z][A-Z0-9_]*$/.test(name) && name.startsWith("TACK_") === false ? [] : [
71
+ `Secret "${String(name)}" needs an uppercase name without the TACK_ prefix, such as "GITHUB_TOKEN".`
72
+ ]
73
+ ) : options["secrets"] === void 0 ? [] : ['defineScript "secrets" must be a list of names, such as ["GITHUB_TOKEN"].'];
74
+ return [...unknownKeys, ...run, ...args, ...secrets];
75
+ };
76
+ function defineScript(options) {
77
+ const problems = definitionProblems(options);
78
+ if (problems.length > 0) throw new ScriptDefinitionError(problems.join("\n"));
79
+ return Object.freeze({ [brand]: 1, options: Object.freeze({ ...options }) });
80
+ }
81
+ var recognizeScript = (value) => isRecord(value) && brand in value && "options" in value && isRecord(value["options"]) ? (
82
+ // oxlint-disable-next-line typescript/no-unsafe-type-assertion -- Only defineScript sets the brand, after validating these options.
83
+ value["options"]
84
+ ) : void 0;
85
+ export {
86
+ ScriptDefinitionError,
87
+ defineScript,
88
+ expectedArgumentValue,
89
+ recognizeScript
90
+ };