@wringer/gunshi 0.2.0 → 0.3.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 (62) hide show
  1. package/README.md +25 -24
  2. package/dist/build-cli-wringer.d.ts +2 -0
  3. package/dist/build-guide-command.d.ts +2 -0
  4. package/dist/build-guide-ports.d.ts +4 -0
  5. package/dist/build-guide-wringer.d.ts +2 -0
  6. package/dist/build-lint-command.d.ts +1 -1
  7. package/dist/check-feature-file.d.ts +5 -0
  8. package/dist/collect-dead-globs.d.ts +3 -3
  9. package/dist/collect-unclaimed-files.d.ts +2 -0
  10. package/dist/parse-feature-table-span.d.ts +11 -0
  11. package/dist/parse-guide-topic.d.ts +6 -0
  12. package/dist/parse-skill-metadata.d.ts +1 -1
  13. package/dist/pick-guide-data.d.ts +20 -0
  14. package/dist/read-guide.d.ts +3 -0
  15. package/dist/read-template-hash.d.ts +1 -0
  16. package/dist/resolve-lint-failures.d.ts +6 -1
  17. package/dist/run-cli.d.ts +3 -1
  18. package/dist/run-verify.d.ts +3 -0
  19. package/dist/scrub-parsed-invocation.d.ts +3 -0
  20. package/{skills/wringer/references → guide}/create.md +29 -25
  21. package/{skills/wringer/references → guide}/fresh-subagent-brief.md +2 -0
  22. package/{skills/wringer/references → guide}/maintain.md +29 -22
  23. package/guide/overview.md +135 -0
  24. package/{skills/wringer/references → guide}/prove.md +16 -13
  25. package/guide/template/verify/SKILL.md +172 -0
  26. package/guide/template/verify/references/feature-add-item.md +20 -0
  27. package/{skills/wringer → guide}/template/verify-registry.ts +2 -1
  28. package/package.json +10 -9
  29. package/src/build-cli-wringer.ts +32 -0
  30. package/src/build-guide-command.ts +37 -0
  31. package/src/build-guide-ports.ts +73 -0
  32. package/src/build-guide-wringer.ts +19 -0
  33. package/src/build-lint-command.ts +32 -6
  34. package/src/check-feature-file.ts +105 -0
  35. package/src/collect-dead-globs.ts +18 -11
  36. package/src/collect-unclaimed-files.ts +17 -0
  37. package/src/parse-feature-table-span.ts +56 -0
  38. package/src/parse-guide-topic.ts +14 -0
  39. package/src/parse-skill-metadata.ts +8 -6
  40. package/src/pick-guide-data.ts +47 -0
  41. package/src/read-guide.ts +49 -0
  42. package/src/read-template-hash.ts +42 -0
  43. package/src/render-human-envelope.ts +7 -0
  44. package/src/resolve-lint-failures.ts +182 -11
  45. package/src/run-cli.ts +17 -2
  46. package/src/run-verify.ts +38 -15
  47. package/src/scrub-parsed-invocation.ts +32 -0
  48. package/src/wringer-gunshi.ts +7 -24
  49. package/dist/build-linted-wringer.d.ts +0 -2
  50. package/dist/find-skill-copy-refusal.d.ts +0 -8
  51. package/dist/parse-skill-install-args.d.ts +0 -3
  52. package/dist/template-version.d.ts +0 -1
  53. package/dist/write-skill-copy.d.ts +0 -12
  54. package/skills/wringer/SKILL.md +0 -143
  55. package/skills/wringer/template/verify/SKILL.md +0 -176
  56. package/skills/wringer/template/verify/references/feature-map.md +0 -17
  57. package/src/build-linted-wringer.ts +0 -16
  58. package/src/find-skill-copy-refusal.ts +0 -34
  59. package/src/parse-skill-install-args.ts +0 -25
  60. package/src/template-version.ts +0 -3
  61. package/src/write-skill-copy.ts +0 -75
  62. /package/{skills/wringer → guide}/template/verify.ts +0 -0
@@ -0,0 +1,32 @@
1
+ import { collectEnvSecrets, createSecretSet, scrubFailure } from '@wringer/core';
2
+ import type { Wringer } from '@wringer/core';
3
+ import type { ParsedInvocation } from './pick-cli-outcome.ts';
4
+
5
+ // A parse failure can quote the arguments the person typed, such as an unknown command followed by
6
+ // a header, so its error passes through the secrets of the registry and the environment.
7
+ export function scrubParsedInvocation(
8
+ parsed: ParsedInvocation,
9
+ wringer: Wringer,
10
+ env: Readonly<Record<string, string | undefined>>,
11
+ ): ParsedInvocation {
12
+ if (parsed.kind !== 'failed') {
13
+ return parsed;
14
+ }
15
+
16
+ const secrets = createSecretSet();
17
+
18
+ for (const secret of collectEnvSecrets({ declared: wringer.secrets, env })) {
19
+ try {
20
+ secrets.add(secret);
21
+ } catch {
22
+ // A declared value that is too short is reported by the command that runs next. The other
23
+ // secrets still scrub this error.
24
+ }
25
+ }
26
+
27
+ return {
28
+ ...parsed,
29
+ command: secrets.scrubText(parsed.command),
30
+ error: scrubFailure(parsed.error, secrets) ?? parsed.error,
31
+ };
32
+ }
@@ -1,27 +1,10 @@
1
1
  #!/usr/bin/env bun
2
- import { join, resolve } from 'node:path';
3
- import { parseSkillInstallArgs } from './parse-skill-install-args.ts';
4
- import { writeSkillCopy } from './write-skill-copy.ts';
2
+ import { buildGuidePorts } from './build-guide-ports.ts';
3
+ import { buildGuideWringer } from './build-guide-wringer.ts';
4
+ import { runWringer } from './run-verify.ts';
5
5
 
6
- const usage = 'Usage: wringer-gunshi skill install [--dir <path>]';
7
- const args = parseSkillInstallArgs(process.argv.slice(2));
6
+ const [, script] = process.argv;
7
+ const selfCommand = script === undefined ? [process.execPath] : [process.execPath, script];
8
8
 
9
- if (args === null) {
10
- console.error(usage);
11
- process.exit(2);
12
- }
13
-
14
- const destination = resolve(args.destination);
15
-
16
- const result = await writeSkillCopy({
17
- source: join(import.meta.dir, '..', 'skills', 'wringer'),
18
- destination,
19
- cwd: process.cwd(),
20
- });
21
-
22
- if (!result.ok) {
23
- console.error(`Refused: ${result.reason} Pass --dir with the folder for the wringer skill.`);
24
- process.exit(2);
25
- }
26
-
27
- console.log(`Installed the wringer skill to ${destination}`);
9
+ // `guide` reads only the installed package, so it runs from any folder, in a repo or not.
10
+ await runWringer(buildGuideWringer(), buildGuidePorts(selfCommand));
@@ -1,2 +0,0 @@
1
- import type { Wringer } from '@wringer/core';
2
- export declare function buildLintedWringer(wringer: Wringer, skillFolder: string): Wringer;
@@ -1,8 +0,0 @@
1
- export type DestinationState = 'absent' | 'wringer-skill' | 'other';
2
- export interface SkillCopyPlan {
3
- readonly source: string;
4
- readonly destination: string;
5
- readonly cwd: string;
6
- readonly state: DestinationState;
7
- }
8
- export declare function findSkillCopyRefusal(plan: SkillCopyPlan): string | null;
@@ -1,3 +0,0 @@
1
- export declare function parseSkillInstallArgs(argv: readonly string[]): {
2
- destination: string;
3
- } | null;
@@ -1 +0,0 @@
1
- export declare const templateVersion = 1;
@@ -1,12 +0,0 @@
1
- export interface SkillCopyPaths {
2
- readonly source: string;
3
- readonly destination: string;
4
- readonly cwd: string;
5
- }
6
- export type SkillCopyResult = {
7
- readonly ok: true;
8
- } | {
9
- readonly ok: false;
10
- readonly reason: string;
11
- };
12
- export declare function writeSkillCopy(paths: SkillCopyPaths): Promise<SkillCopyResult>;
@@ -1,143 +0,0 @@
1
- ---
2
- name: wringer
3
- description:
4
- "Builds a repo's verify CLI, feature map and verify skill on wringer, proves them, and keeps them
5
- true. Load it to add wringer to a repo, to prove a verify CLI before its PR, when `verify lint`
6
- fails, or when a new @wringer/gunshi ships a new template version."
7
- ---
8
-
9
- # Build a verify CLI with wringer
10
-
11
- Give the repo's agents one way to use its real app and keep the evidence of what they checked. Build
12
- these in the repo:
13
-
14
- - a verify CLI on the `@wringer/*` packages, which an agent runs as `bun verify <command>`;
15
- - its registry: the code that declares the targets, the drivers, the actions, the doctor checks and
16
- the features, with each feature's `paths` globs, and the ignore list, set with `.ignore`: the
17
- globs of the files the running app never reads;
18
- - a `verify` skill, with a feature map in its `references/feature-map.md` that gives each feature's
19
- journey.
20
-
21
- These terms hold across this skill and its references:
22
-
23
- | Term | Meaning |
24
- | --------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
25
- | target | where the app runs: `local`, which the CLI starts, or an instance it attaches to |
26
- | read-only | a target's access that refuses each write with exit code 3 |
27
- | driver | a package that adds a group of commands, such as `@wringer/http` and `http request` |
28
- | action | a named step of the repo's own, run as `bun verify action <name>` |
29
- | doctor | `bun verify doctor`: the checks that must pass before any command that touches the app |
30
- | journey | the `bun verify` commands that use one feature, and the end state that shows it works |
31
- | verdict | what `bun verify done` records: the feature works on the current code |
32
- | gate | `bun verify gate` in CI: it fails a PR on a changed feature without a verdict, and on a changed file outside every `paths` glob and the ignore list |
33
- | report | the output of `bun verify report --human`, which the PR body holds for the gate |
34
-
35
- Then prove them, and wire the checks that keep them true. Hand back the PR that adds them, with the
36
- proof in its description. The mistakes that cost the most:
37
-
38
- - **Calling it done before a fresh agent uses it.** You know the app; the repo's next agent knows
39
- only the `verify` skill. Run a subagent with none of your context to show that the skill works.
40
- - **Copying commands into the `verify` skill.** The CLI lists its own commands in `--help`, and a
41
- copy goes stale. Point at `--help`, and write only what the help can't say.
42
- - **A `paths` glob that matches no file.** The files it should cover then fail the gate as unmapped,
43
- unless another feature's glob covers them. Run `bun verify lint` to find one.
44
- - **Writing a repo's own choices outside the `<!-- repo -->` blocks of the `verify` skill.** An
45
- upgrade of the template replaces every line outside them. Put each choice, such as where an agent
46
- reports a refused write, in a block or in the repo's code.
47
-
48
- ## Key rules
49
-
50
- - [Install the skill](#install-the-skill): copy it from `@wringer/gunshi`, at the version the repo
51
- installs.
52
- - [The template](#the-template): the files to copy, with fixed parts and repo parts.
53
- - [Create](#create): read the repo, then write the CLI, the actions, the checks, 3 to 5 features,
54
- the ignore list and the `verify` skill.
55
- - [Prove](#prove): doctor passes, a fresh subagent reaches `done` on every feature, and the CLI
56
- refuses what it should.
57
- - [Maintain](#maintain): the gate and `lint` in CI, and a template upgrade when `lint` asks.
58
-
59
- ## References
60
-
61
- - [Create](./references/create.md): writing the CLI, the registry and the `verify` skill in a repo.
62
- - [Prove](./references/prove.md): the proof steps and what each shows in the PR.
63
- - [Fresh subagent brief](./references/fresh-subagent-brief.md): the brief to give the subagent in
64
- the prove flow.
65
- - [Maintain](./references/maintain.md): wiring the gate and `lint` into CI, and upgrading the
66
- template.
67
-
68
- ## Install the skill
69
-
70
- This skill ships inside `@wringer/gunshi`, so its version matches the packages the repo installs.
71
- These commands put it in `.claude/skills/wringer/`, where an agent can load it, and replace any
72
- older copy there. Commit that folder with the rest of the work:
73
-
74
- ```bash
75
- bun add --dev --exact @wringer/core @wringer/gunshi zod
76
- bunx @wringer/gunshi skill install
77
- ```
78
-
79
- Run the second command again after each upgrade of `@wringer/gunshi`.
80
-
81
- The CLI runs on Bun. When the repo installs packages with another package manager, use it for
82
- `bun add` and `bunx`, such as `pnpm add` and `pnpm dlx`. Also use it in the `verify` skill's
83
- `metadata.wringer-command`, such as `pnpm verify`. The `verify` script in `package.json` still runs
84
- the CLI with `bun`.
85
-
86
- ## The template
87
-
88
- [`template/`](./template/) holds a working example for an invented app, Larder:
89
-
90
- | File | Copy to | Holds |
91
- | ----------------------------------------------------- | ----------------------------------- | --------------------------------------------------------------- |
92
- | [`verify.ts`](./template/verify.ts) | `scripts/verify/verify.ts` | the entry point that calls `runVerify` |
93
- | [`verify-registry.ts`](./template/verify-registry.ts) | `scripts/verify/verify-registry.ts` | targets, a driver, an action, a command, a check, a feature |
94
- | [`verify/`](./template/verify/) | `.claude/skills/verify/` | the repo's `verify` skill, and its feature map in `references/` |
95
-
96
- Skip `verify-registry.test.ts` in `template/`: it tests the template inside wringer.
97
-
98
- These locations are defaults. When you change one, change each place that refers to it:
99
-
100
- - the folder `scripts/verify/`: the `verify` script's path in `package.json`, and its glob in the
101
- registry's `.ignore` list;
102
- - the skill folder: `runVerify`'s `skill` option, a path from the repo root;
103
- - the script name `verify`: the `package.json` script and the skill's `metadata.wringer-command`,
104
- such as `bun verify`.
105
-
106
- In the `verify` skill's `SKILL.md`, each `<!-- repo: <part> -->` block ends at `<!-- /repo -->` and
107
- holds what only this repo knows. Rewrite those blocks, the frontmatter's `name` and `description`,
108
- and the `#` title. Keep every other line. The repo owns `references/feature-map.md` whole. Keep
109
- `metadata.wringer-template` as the template has it: `lint` compares it with the version that
110
- `@wringer/gunshi` ships.
111
-
112
- ## Create
113
-
114
- Read how the app starts, what it prints when it is ready, and which state it keeps. Then follow
115
- [Create](./references/create.md): it ends with 3 to 5 features in the registry, each with a journey
116
- in the `verify` skill, an ignore list for the files with no runtime effect, and `bun verify lint`
117
- passing.
118
-
119
- ## Prove
120
-
121
- The work is done only when each of these holds. [Prove](./references/prove.md) gives the commands.
122
-
123
- 1. `bun verify doctor` passes on `local`.
124
- 2. A fresh subagent that loads only the new `verify` skill reaches `done` on every feature. A new
125
- feature map needs one pass by an agent who did not write it, and this run is that pass.
126
- 3. After an edit to a file that a feature's `paths` match, a command that touches the app fails with
127
- `doctor-required`. A read-only target, if the repo has one, refuses one write with `read-only`.
128
- 4. The whole report is in the description of the PR that adds the CLI. The gate reads the report
129
- from the HTML comment at the report's end.
130
-
131
- ## Maintain
132
-
133
- Wire these into the repo, as [Maintain](./references/maintain.md) shows:
134
-
135
- - **The gate on each PR.** A PR that touches a feature's `paths` needs a verdict recorded on the
136
- PR's latest code. A PR that touches a file outside every feature's `paths` and the ignore list
137
- fails until you add the file to one of them.
138
- - **`lint` in CI.** It needs no running app.
139
- - **A journey fixed with its feature.** A PR that changes a feature fixes the feature's journey.
140
-
141
- Add no scheduled job. The gate checks a feature each time a PR changes it.
142
-
143
- **Reply:** the PR link, and for each prove step, the command and the output lines that show it held.
@@ -1,176 +0,0 @@
1
- ---
2
- name: verify
3
- description:
4
- 'Uses the Larder app the way a user would with `bun verify`, and records the verdict that a
5
- feature works. Load it before you check a change in the running app, run a journey from the
6
- feature map, or put the verdicts in a PR.'
7
- metadata:
8
- wringer-template: 1
9
- wringer-command: bun verify
10
- ---
11
-
12
- # Verify Larder
13
-
14
- Use `bun verify` to start the app, use each feature your change touches the way a user would, and
15
- record a verdict that it works. Hand back the output of `bun verify report --human` and each feature
16
- you could not verify. The CI gate, `bun verify gate`, fails a PR that changes a feature with no
17
- verdict.
18
-
19
- Each feature in the [feature map](./references/feature-map.md) has a journey: the `bun verify`
20
- commands that use the feature, and the end state that shows it works.
21
-
22
- The mistakes that cost the most time:
23
-
24
- - **Using the app before `doctor` passes.** `bun verify doctor` checks that the app answers and that
25
- each driver works. Until it passes on the current run, the one that `up` or `attach` started, any
26
- command that touches the app fails with exit code 3.
27
- - **Editing the app's code while `up` runs it.** The next command that touches the app fails with
28
- `doctor-required`. Run `bun verify up --restart`, then `bun verify doctor`. Then run the feature's
29
- journey again.
30
- - **Running `done` before you check the end state.** `done` checks only that one command of the
31
- feature's journey after `use --feature`, a read or a write, succeeded. It does not check the
32
- result. Check the end state yourself first.
33
- - **Branching on the error message.** Branch on the exit code and `error.code`. The message text can
34
- change in any release.
35
-
36
- ## Key rules
37
-
38
- - [Check a change](#check-a-change): report, start a run, doctor, then run the journey, check the
39
- end state and `done` for each feature, then report again and end the run.
40
- - [Read the envelope](#read-the-envelope): one JSON object per command, and an exit code to branch
41
- on.
42
- - [Targets](#targets): the targets this repo declares; check a change on one that `up` starts.
43
- - [Commands](#commands): `bun verify --help` lists every command, each marked read or write.
44
- - [Feature map](#feature-map): the file that holds each feature's journey and end state.
45
- - [Update the feature map](#update-the-feature-map): fix a broken journey in the same PR, and run
46
- `lint`.
47
-
48
- ## References
49
-
50
- - [Feature map](./references/feature-map.md): each feature's journey and end state, before you check
51
- the feature.
52
-
53
- ## Check a change
54
-
55
- 1. Run `bun verify report`. Each feature in `data.report.features` with `changed: true` has a file
56
- under its `paths` that differs from the default branch, committed or not. Each one needs a
57
- verdict.
58
- 2. Unless your task names another target, start a run on `local`, with the commands in the
59
- [Targets](#targets) table. Expect: `ok: true`, and the app's endpoints in `data.endpoints`.
60
- 3. Run `bun verify doctor`. Expect: `data.passed: true`. When a check fails, fix its cause, and run
61
- `doctor` again.
62
- 4. Run the feature's journey from the [feature map](./references/feature-map.md). Its first line,
63
- `use --feature`, records each later command under that feature. It does not change the target.
64
- Expect: each command exits 0.
65
- 5. Compare the app with the feature's end state:
66
- - When it matches, and no command failed with `read-only`, go on to step 6.
67
- - When your change broke the feature, fix the app's code. Then run `bun verify up --restart`,
68
- `bun verify doctor` and the journey again.
69
- - When your change means to change the end state, fix the feature's entry in the feature map, and
70
- run `bun verify lint`. Then run the journey again.
71
- - Otherwise, skip `done` for this feature. List it in your reply with the end state you expected
72
- and the `data` you got.
73
- 6. Run `bun verify done`. It records a verdict for the feature that `use --feature` set. Expect:
74
- `ok: true`. It fails with exit code 1 and `check-failed` until one command of the journey
75
- succeeds after `use --feature` and `doctor`.
76
- 7. Repeat steps 4 to 6 for each feature with `changed: true`, and for each feature your task names,
77
- in the order the feature map lists them. When the feature map's opening names a journey to run
78
- last, follow it. When a changed feature has no entry in the feature map, write one, and run
79
- `bun verify lint`.
80
- 8. Run `bun verify report --human`. A changed feature with your verdict shows `verified`; a feature
81
- the branch doesn't change shows `unchanged`, with your verdict's evidence. After `done`, an edit
82
- to any file on the branch makes every verdict `stale`, unless you commit the same code. Repeat
83
- steps 4 to 6 for each stale feature.
84
- 9. Put the whole output in the PR body, in place of the output of an older `report --human`. Keep
85
- the HTML comment at the end of the output: the gate reads the report from it.
86
- 10. End the run: `bun verify down` after `up`, or `bun verify detach` after `attach`.
87
-
88
- ## Read the envelope
89
-
90
- Each command prints one JSON envelope as its last line. With `--human`, it prints text for a person
91
- in its place. A streaming command, such as `doctor`, prints its events as JSON lines before the
92
- envelope. Read these fields:
93
-
94
- - `ok`, then `data` on success, or `error.code`, `error.message` and `error.hint` on failure;
95
- - `evidence`: the files the command kept, under `.wringer/`;
96
- - `truncated` and `truncatedPath`: `data` was too large, and the file at `truncatedPath` holds it.
97
-
98
- | Exit | `error.code` | Do |
99
- | ---- | -------------------- | -------------------------------------------------------------------------------------------- |
100
- | 0 | none | Go on. |
101
- | 1 | `check-failed` | Read the evidence, then go on as step 5 says. |
102
- | 2 | `usage` | Fix the command; `--help` shows its flags. |
103
- | 3 | `read-only` | Leave the write undone, skip `done` for the feature, and list the write in your reply. |
104
- | 3 | `doctor-required` | Run the commands in `error.hint`, then run the feature's journey again. |
105
- | 3 | `not-running` | Start the run, as step 2 says. |
106
- | 3 | `target-not-allowed` | Follow `error.hint`. |
107
- | 4 | `environment` | Read `error.message`, fix the problem on this machine, such as a missing browser, and retry. |
108
- | 4 | `internal` | Report the command and `error.message`: the CLI has a bug. |
109
- | 5 | `timeout` | Retry once with twice the timeout; the default is `--timeout-ms=120000`. Then report it. |
110
-
111
- ## Targets
112
-
113
- Start a launch target's app with `bun verify up`, and stop it with `bun verify down`. Connect to an
114
- attach target with `bun verify attach`: an attach target is an app that runs apart from
115
- `bun verify`, and `bun verify detach` leaves it running. Your edits never reach an attach target's
116
- app, so check a change on a launch target.
117
-
118
- Run `bun verify use --target <target>` to point every later command at a target. `--target` on one
119
- command points that command alone.
120
-
121
- <!-- repo: targets -->
122
-
123
- | Target | Start with | Access | Notes |
124
- | -------- | ---------------------------------------------------------- | ---------- | ------------------------------------------------------ |
125
- | `local` | `bun verify use --target local`, then `bun verify up` | read-write | Starts the app with `bun run dev`. |
126
- | `shared` | `bun verify use --target shared`, then `bun verify attach` | read-only | An app that `bun verify` did not start. Never stop it. |
127
-
128
- <!-- /repo -->
129
-
130
- ## Commands
131
-
132
- Run `bun verify --help` for the list, and `bun verify <command> --help` for a command's flags. The
133
- help marks each command `[read]` or `[write]`.
134
-
135
- - Run `bun verify <group> --help` to list the commands in a group, such as `action`. The top-level
136
- list shows the group alone.
137
- - Write a negative number with `=`, as in `--offset=-5`.
138
- - Pass an object as JSON text, as in `--filter '{"shelf":"top"}'`.
139
-
140
- <!-- repo: commands -->
141
-
142
- - `bun verify action add-item --name <name>` adds an item through the API.
143
- - `bun verify items count` counts the items through the API, in `data.count`.
144
-
145
- <!-- /repo -->
146
-
147
- ## Feature map
148
-
149
- Before you run a feature's journey, read its entry in the
150
- [feature map](./references/feature-map.md): what it does, how a user reaches it, its journey and its
151
- end state. `bun verify features` lists each feature's `paths`. The gate needs a verdict for each
152
- feature whose `paths` match a changed file. It fails on a changed file that matches neither a
153
- feature's `paths` nor the registry's `.ignore` globs: add it to one of them.
154
-
155
- ## Update the feature map
156
-
157
- <!-- repo: registry -->
158
-
159
- The registry, `scripts/verify/verify-registry.ts`, declares the targets, actions, commands, doctor
160
- checks and features, with each feature's `paths`.
161
-
162
- <!-- /repo -->
163
-
164
- - When a feature's journey stops working because the feature changed, fix it in the same PR.
165
- - In this file, edit only the frontmatter's `name` and `description`, the `#` title, and the lines
166
- inside the `<!-- repo -->` blocks. An upgrade of the template keeps those and replaces every other
167
- line. You may edit any line of the feature map.
168
- - After you change this skill, its feature map or the registry, run `bun verify lint`. It fails on:
169
- - a `paths` glob that matches no file;
170
- - a command in a code block that would fail before it ran, such as one with an unknown flag,
171
- feature or target;
172
- - a skill written from an older template. Load the `wringer` skill that `@wringer/gunshi` ships,
173
- and follow its upgrade steps.
174
-
175
- **Reply:** the output of `bun verify report --human`, and each feature you could not verify, with
176
- the command that failed and its `error.code`, or the end state you expected and the `data` you got.
@@ -1,17 +0,0 @@
1
- # Feature map
2
-
3
- ## add-item
4
-
5
- - **What:** a user adds an item to the pantry.
6
- - **How a user reaches it:** open `/pantry`, type a name, and press Add.
7
- - **Journey:**
8
-
9
- ```bash
10
- bun verify use --feature add-item
11
- bun verify items count
12
- bun verify action add-item --name Oats
13
- bun verify items count
14
- ```
15
-
16
- - **End state:** the second `items count` returns one more item than the first. Run
17
- `bun verify http request --path /api/items` too: its `data.json` lists `Oats`.
@@ -1,16 +0,0 @@
1
- import { WringerError } from '@wringer/core';
2
- import type { Wringer } from '@wringer/core';
3
- import { buildLintCommand } from './build-lint-command.ts';
4
-
5
- // The registry with the `lint` built-in added. `lint` parses journey lines with gunshi, so this
6
- // package adds it rather than core.
7
- export function buildLintedWringer(wringer: Wringer, skillFolder: string): Wringer {
8
- const lint = buildLintCommand(skillFolder);
9
- const key = lint.info.path.join(' ');
10
-
11
- if (wringer.commands.has(key)) {
12
- throw new WringerError('usage', { message: `Two commands share the name \`${key}\`.` });
13
- }
14
-
15
- return Object.freeze({ ...wringer, commands: new Map([...wringer.commands, [key, lint]]) });
16
- }
@@ -1,34 +0,0 @@
1
- import { isAbsolute, relative } from 'node:path';
2
-
3
- export type DestinationState = 'absent' | 'wringer-skill' | 'other';
4
-
5
- export interface SkillCopyPlan {
6
- readonly source: string;
7
- readonly destination: string;
8
- readonly cwd: string;
9
- readonly state: DestinationState;
10
- }
11
-
12
- // Why the installer must not remove the destination, or null when it may. The install removes the
13
- // destination before it copies, so a wrong `--dir` would delete another skill or the repo.
14
- export function findSkillCopyRefusal(plan: SkillCopyPlan): string | null {
15
- if (isInside(plan.destination, plan.cwd)) {
16
- return `${plan.destination} holds the current folder.`;
17
- }
18
-
19
- if (isInside(plan.destination, plan.source) || isInside(plan.source, plan.destination)) {
20
- return `${plan.destination} overlaps the packaged skill.`;
21
- }
22
-
23
- if (plan.state === 'other') {
24
- return `${plan.destination} exists and is not a copy of the wringer skill.`;
25
- }
26
-
27
- return null;
28
- }
29
-
30
- function isInside(parent: string, child: string): boolean {
31
- const path = relative(parent, child);
32
-
33
- return path === '' || (!path.startsWith('..') && !isAbsolute(path));
34
- }
@@ -1,25 +0,0 @@
1
- import { parseArgs } from 'node:util';
2
-
3
- // Users type `--dir`; the naming lint rejects `dir` as a literal key, so the name lives in a value.
4
- const directoryFlag = 'dir';
5
- const defaultDestination = '.claude/skills/wringer';
6
-
7
- // Answers the destination folder, or null when the arguments are not `skill install [--dir <path>]`.
8
- export function parseSkillInstallArgs(argv: readonly string[]): { destination: string } | null {
9
- try {
10
- const parsed = parseArgs({
11
- args: [...argv],
12
- options: { [directoryFlag]: { type: 'string' } },
13
- allowPositionals: true,
14
- strict: true,
15
- });
16
-
17
- if (parsed.positionals.join(' ') !== 'skill install') {
18
- return null;
19
- }
20
-
21
- return { destination: parsed.values[directoryFlag] ?? defaultDestination };
22
- } catch {
23
- return null;
24
- }
25
- }
@@ -1,3 +0,0 @@
1
- // The version of the verify skill template that this package ships. A repo's verify skill records
2
- // the version it was written from in its frontmatter, and `lint` fails until the two match.
3
- export const templateVersion = 1;
@@ -1,75 +0,0 @@
1
- import { cp, rm, stat } from 'node:fs/promises';
2
- import { join } from 'node:path';
3
- import { z } from 'zod';
4
- import { findSkillCopyRefusal } from './find-skill-copy-refusal.ts';
5
- import type { DestinationState } from './find-skill-copy-refusal.ts';
6
-
7
- export interface SkillCopyPaths {
8
- readonly source: string;
9
- readonly destination: string;
10
- readonly cwd: string;
11
- }
12
-
13
- export type SkillCopyResult =
14
- | { readonly ok: true }
15
- | { readonly ok: false; readonly reason: string };
16
-
17
- // Removes the destination first: `cp` into a folder that exists would nest the copy inside it.
18
- export async function writeSkillCopy(paths: SkillCopyPaths): Promise<SkillCopyResult> {
19
- const state = await readDestinationState(paths.destination);
20
-
21
- const reason = findSkillCopyRefusal({ ...paths, state });
22
-
23
- if (reason !== null) {
24
- return { ok: false, reason };
25
- }
26
-
27
- await rm(paths.destination, { recursive: true, force: true });
28
-
29
- await cp(paths.source, paths.destination, {
30
- recursive: true,
31
- filter: (path) => !path.endsWith('.test.ts'),
32
- });
33
-
34
- return { ok: true };
35
- }
36
-
37
- async function readDestinationState(destination: string): Promise<DestinationState> {
38
- const exists = await stat(destination).then(
39
- () => true,
40
- () => false,
41
- );
42
-
43
- if (!exists) {
44
- return 'absent';
45
- }
46
-
47
- const skill = Bun.file(join(destination, 'SKILL.md'));
48
-
49
- const hasSkill = await skill.exists();
50
-
51
- if (!hasSkill) {
52
- return 'other';
53
- }
54
-
55
- const text = await skill.text();
56
-
57
- return isWringerSkill(text) ? 'wringer-skill' : 'other';
58
- }
59
-
60
- const frontmatterPattern = /^---\r?\n(?<yaml>[\s\S]*?)\r?\n---\r?\n/u;
61
- const frontmatterSchema = z.looseObject({ name: z.literal('wringer') });
62
-
63
- function isWringerSkill(text: string): boolean {
64
- const yaml = frontmatterPattern.exec(text)?.groups?.['yaml'];
65
-
66
- if (yaml === undefined) {
67
- return false;
68
- }
69
-
70
- try {
71
- return frontmatterSchema.safeParse(Bun.YAML.parse(yaml)).success;
72
- } catch {
73
- return false;
74
- }
75
- }
File without changes