Compare commits
7
Commits
5d0f988ed8
...
641ebcac0e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
641ebcac0e | ||
|
|
4a4b598955 | ||
|
|
1e8f0571cf | ||
|
|
06b01f8afc | ||
|
|
fd86ee42f4 | ||
|
|
36723ae3fc | ||
|
|
9285b29e3c |
No files matched your search
+9
-7
@@ -67,9 +67,10 @@ consumers, but a deliberate choice, never a default. A rule for this repo alone
|
||||
_Avoid_: rule (the Claude-side deployed form under `.claude/rules/`), guideline, standard
|
||||
|
||||
**Hook**:
|
||||
A runtime callback a harness fires inside its own tool loop, authored as one JSON file per concern
|
||||
under `plugins/<plugin>/.apm/hooks/` in apm's canonical shape — nested entries, PascalCase events,
|
||||
`${PLUGIN_ROOT}` script paths — which apm renders per target. Reach is narrowed in the package's
|
||||
A runtime callback a harness fires inside its own tool loop, authored as JSON under
|
||||
`plugins/<plugin>/.apm/hooks/` — one file or several; kyberforge ships a single `hooks.json` — in
|
||||
apm's canonical shape — nested entries, PascalCase events, `${PLUGIN_ROOT}` script paths — which
|
||||
apm renders per target. Reach is narrowed in the package's
|
||||
`apm.yml` `targets:`, never by filename. The last resort among apm primitives: procedure belongs in
|
||||
a **Skill**, and a hook is only for "this must always happen at this event".
|
||||
_Avoid_: trigger, callback script (the script is the hook's payload, not the hook)
|
||||
@@ -225,7 +226,8 @@ _Avoid_: namespace, category
|
||||
recheck belongs to `factory-audit`, not to `forge`, which routes only to the author
|
||||
skills and never to an audit.
|
||||
- "prompt" meant both apm's `.prompt.md` primitive and, loosely, any slash command or a skill — resolved:
|
||||
a **Prompt** is the `.prompt.md` primitive under the house rule above. apm calls a prompt "a
|
||||
callable program for an LLM", but on Claude it deploys as a model-invocable command with fewer
|
||||
frontmatter keys than a skill, and Codex receives nothing. A fat prompt is a worse skill on every
|
||||
harness, so the procedure goes in the skill and the prompt only steers it.
|
||||
a **Prompt** is the `.prompt.md` primitive under the house rule above. apm frames a prompt as a
|
||||
program ("a prompt is a program for an LLM", its "What is APM?" page), but on Claude it deploys
|
||||
as a model-invocable command with fewer frontmatter keys than a skill, and Codex receives
|
||||
nothing. A fat prompt is a worse skill on every harness, so the procedure goes in the skill and
|
||||
the prompt only steers it.
|
||||
@@ -34,7 +34,9 @@ behind and refreshes it in place.
|
||||
*session* loads, and that is the moment the staleness does damage. It also enables two things a git
|
||||
hook structurally cannot do: `additionalContext` puts the notice into the agent's context rather
|
||||
than terminal scrollback nobody reads, and `reloadSkills: true` makes the host re-scan the skill
|
||||
directories after the hook returns, so a refresh lands in the running session without a restart.
|
||||
directories after the hook returns, so a refresh lands in the running session without a restart
|
||||
(`reloadSkills` is a documented `SessionStart` `hookSpecificOutput` field:
|
||||
code.claude.com/docs/en/hooks, checked 2026-09-29).
|
||||
|
||||
apm's own lifecycle events (`pre-/post-install`, `pre-/post-update`, `pre-/post-uninstall`) were
|
||||
rejected: they fire around apm operations already chosen, so they can announce a refresh but never
|
||||
@@ -51,8 +53,9 @@ Three sub-decisions:
|
||||
drift. A hook shipped in a package is written into that file by apm itself, so it is apm's output
|
||||
and does not drift. `.claude/settings.local.json` also works but is gitignored and machine-local,
|
||||
which fails the requirement that this travel with the repo.
|
||||
- **`startup` matcher only.** `resume`, `clear`, `compact` and `fork` would re-run the check on every
|
||||
compaction, and a compaction is not an event after which the remote can have moved.
|
||||
- **`startup` matcher only.** `resume`, `clear`, `compact` and `fork` — the other documented
|
||||
`SessionStart` matchers (code.claude.com/docs/en/hooks, checked 2026-09-29) — would re-run the check
|
||||
on every compaction, and a compaction is not an event after which the remote can have moved.
|
||||
|
||||
The executable-trust gate is switched on at the same time. Root `apm.yml` gains an `executables:`
|
||||
block allowing kyberforge's hooks and bin.
|
||||
@@ -142,6 +145,22 @@ value to be larger — so changing either side without the other fails the suite
|
||||
> Re-measured: ~24–26 s for the same six-behind refresh, warm, on a LAN remote — well inside the
|
||||
> 380 s above.
|
||||
|
||||
> **Amendment (2026-09-29) — the time limits are harder to escape, and portable.** Four changes to
|
||||
> `check-apm-current.sh` (PR #144):
|
||||
>
|
||||
> - Both limits are now `timeout -k 5`: a child that ignores SIGTERM is SIGKILLed 5 s later. The
|
||||
> worst case is 60 + 5 + 300 + 5 = 370 s, still below the host's 380, and the test now sums each
|
||||
> limit plus its grace.
|
||||
> - `timeout` falls back to `gtimeout` (Homebrew coreutils on macOS). With neither on `PATH` the
|
||||
> hook emits a notice and exits without calling `apm`. Before, the missing binary exited 127, the
|
||||
> `|| exit 0` swallowed it, and the hook silently never ran.
|
||||
> - `GIT_TERMINAL_PROMPT=0` is exported, so a remote that wants credentials fails at once instead of
|
||||
> blocking on an invisible prompt until the timeout fires.
|
||||
> - `apm update` runs under `flock -n` on `apm_modules/.kyberforge-apm-update.lock` when `flock` exists
|
||||
> and `apm_modules/` does. A second session starting at the same moment skips its refresh and says
|
||||
> so, instead of running a second `apm update` over the same tree. Without `flock` (stock macOS) the
|
||||
> refresh runs unserialised, as before.
|
||||
|
||||
**Reading a human-readable CLI for a control decision cost a silent failure, again.** `apm outdated`
|
||||
has no `--json` or other machine-readable flag (confirmed against 0.28.0), so the hook must match
|
||||
its prose. The first attempt matched `outdated dependencies found` — plural only. apm emits
|
||||
@@ -204,9 +223,20 @@ Until then the repo has the mechanism in source and not in effect.
|
||||
> and it does not last. At the next session start the hook finds the restored lock behind `main`
|
||||
> and refreshes again.
|
||||
|
||||
> **Amendment (2026-09-19) — the advice is neutral when the default branch is unknown.** The hook
|
||||
> picks its lock advice by comparing the current branch with `refs/remotes/origin/HEAD`. That ref is
|
||||
> often unset: git writes it on clone, and `git remote add` never does. The fallback used to be
|
||||
> `main`, which told a checkout whose default branch is `master` to discard a real lock update while
|
||||
> it stood on its default branch. Now, when `origin/HEAD` is unset, the notice gives neither the
|
||||
> default-branch nor the feature-branch advice. It says only "commit it or discard it
|
||||
> deliberately", the same text used outside a git checkout or on a detached HEAD. Learning the
|
||||
> remote's default would need the network, so the hook asserts nothing and the reader decides
|
||||
> (`ea119d8`).
|
||||
|
||||
**`.claude/settings.json` stops being `{"hooks": {}}`.** apm merges the hook into it and tracks
|
||||
ownership in a `.claude/apm-hooks.json` sidecar, with the script copied to
|
||||
`.claude/hooks/<pkg>/`. The sidecar and the script directory are gitignored install output; the
|
||||
`.claude/hooks/<pkg>/`. The sidecar and the script directory are gitignored install output
|
||||
(*superseded for the sidecar: it is committed, see correction 2026-09-16 below*); the
|
||||
settings file remains committed, now with apm-generated content in it. ADR-0018's statement that the
|
||||
committed content is exactly `{"hooks": {}}` is superseded on that point only — the rule it was
|
||||
protecting, that nothing repo-authored goes in that file, is unchanged.
|
||||
@@ -223,7 +253,9 @@ protecting, that nothing repo-authored goes in that file, is unchanged.
|
||||
|
||||
**Native consumers are protected by a guard, not by the gate.** A host installing holocron through
|
||||
`claude plugin install` auto-discovers `hooks/hooks.json` and does not consult apm's trust gate at
|
||||
all. The script therefore exits silently when there is no `apm.lock.yaml` in the working directory,
|
||||
all. The script therefore exits silently when there is no `apm.lock.yaml` in the working directory
|
||||
(*superseded: it now checks `${CLAUDE_PROJECT_DIR}/apm.lock.yaml` and has no cwd fallback, see
|
||||
correction 2026-09-28 below*),
|
||||
which is what makes it inert in a repo that does not consume packages through apm. Copilot CLI sees
|
||||
no hook at all, for the reasons already documented in `plugins/kyberforge/docs/hooks.md`.
|
||||
|
||||
|
||||
@@ -191,6 +191,17 @@ comments (`:9-93`) have described all three correctly since it shipped.
|
||||
was wrong for the tree-identical case: the `same_subtree` skip makes a push **pass** that this ADR as
|
||||
written requires to **fail**, which is documented behaviour changing, not an implementation detail.
|
||||
|
||||
## Amendment (2026-09-29): a new skill stays at `0.1.0` until its first improve
|
||||
|
||||
The Decision says `skill-author`'s create/improve bump convention is "unchanged". It has changed
|
||||
since. Before, `skill-author` bumped the **minor** version on create, so a skill left its first
|
||||
session above the `0.1.0` scaffold. Now create keeps the scaffold's `0.1.0` and does not bump it;
|
||||
the first improve is the first bump, a **patch** (`skill-author` `SKILL.md`, `references/create.md`
|
||||
and `references/improve.md`; `965208b`, PR #144). This makes `0.1.0` mean what this ADR says it
|
||||
means, "created and never yet revised", instead of a value no created skill ever kept. The rules
|
||||
above are otherwise unaffected: `metadata.version` is still required, and the push gate still
|
||||
compares whatever value is there.
|
||||
|
||||
## Consequences
|
||||
|
||||
27 SKILL.md files gain `metadata.version: "1.0.0"`, and a 28th — `bin/write-docs` — reaches the same
|
||||
|
||||
@@ -172,31 +172,6 @@ fallback row. It could not route a `SKILL.md` file path, a trigger its own descr
|
||||
Its agent row ("a path under `.apm/agents/`… or an agent markdown file") was both wider than the
|
||||
script and circular.
|
||||
|
||||
> **Amendment (2026-09-28) — three more modes: hook, instruction and prompt.** The "two accepted
|
||||
> shapes" above are now five. The `primitive-author` change (issue #94, PR #144) added three rows to
|
||||
> the Step 0 table, each with its own self-contained flow file and a shared
|
||||
> `scripts/lib-checks-primitive.sh` that `validate.sh` sources for all three:
|
||||
>
|
||||
> - A file named `*.instructions.md` takes the instruction flow (`references/instruction-flow.md`).
|
||||
> - A file named `*.prompt.md` takes the prompt flow (`references/prompt-flow.md`); the prompt rules
|
||||
> themselves are ADR-0029's.
|
||||
> - A `.json` file whose *immediate* parent directory is `hooks/` (`.apm/hooks/`, or a package's
|
||||
> root `hooks/`) takes the hook flow (`references/hook-flow.md`).
|
||||
>
|
||||
> The suffix rows are checked before the `agents/`-parent rule, so a `*.prompt.md` or
|
||||
> `*.instructions.md` under `agents/` is not audited as an agent. The fallback row is unchanged in
|
||||
> kind: anything else stops, runs no validator, exits 2, and names every accepted shape rather than
|
||||
> two. The exit-code table below applies to the new modes as written; its "matches neither shape"
|
||||
> row now means "matches none of the five".
|
||||
>
|
||||
> This is ADR-0020's merge-siblings rule applied forward rather than a new decision. Auditing a hook,
|
||||
> an instruction or a prompt is the same job as auditing a skill or agent — deterministic checks,
|
||||
> a read, a qualitative pass, one shared report — over a different input type, which is exactly the
|
||||
> case the rule says belongs in one skill behind a dispatch table, not in a new sibling audit skill.
|
||||
> The authoring side follows the rule's other half: the author skills stay split because they emit
|
||||
> genuinely different artifacts, so the three primitives got their own `primitive-author` rather
|
||||
> than rows in `skill-author` or `agent-author`.
|
||||
|
||||
**3. One entry point per script, auto-detecting, with the mode-specific half sourced.**
|
||||
|
||||
- `scripts/validate.sh` detects the target type itself, then sources `scripts/lib-boundary-resolver.sh`
|
||||
@@ -303,6 +278,31 @@ both entry points, and that is what most of the table is. Every change below is
|
||||
A single `validate.sh` copied or symlinked out of its `scripts/` directory still does not work,
|
||||
because its libraries are not beside it. It now fails at exit 2 and says so.
|
||||
|
||||
> **Amendment (2026-09-28) — three more modes: hook, instruction and prompt.** The "two accepted
|
||||
> shapes" in point 2 above are now five. The `primitive-author` change (issue #94, PR #144) added
|
||||
> three rows to the Step 0 table, each with its own self-contained flow file and a shared
|
||||
> `scripts/lib-checks-primitive.sh` that `validate.sh` sources for all three:
|
||||
>
|
||||
> - A file named `*.instructions.md` takes the instruction flow (`references/instruction-flow.md`).
|
||||
> - A file named `*.prompt.md` takes the prompt flow (`references/prompt-flow.md`); the prompt rules
|
||||
> themselves are ADR-0029's.
|
||||
> - A `.json` file whose *immediate* parent directory is `hooks/` (`.apm/hooks/`, or a package's
|
||||
> root `hooks/`) takes the hook flow (`references/hook-flow.md`).
|
||||
>
|
||||
> The suffix rows are checked before the `agents/`-parent rule, so a `*.prompt.md` or
|
||||
> `*.instructions.md` under `agents/` is not audited as an agent. The fallback row is unchanged in
|
||||
> kind: anything else stops, runs no validator, exits 2, and names every accepted shape rather than
|
||||
> two. The exit-code table above applies to the new modes as written; its "matches neither shape"
|
||||
> row now means "matches none of the five".
|
||||
>
|
||||
> This is ADR-0020's merge-siblings rule applied forward rather than a new decision. Auditing a hook,
|
||||
> an instruction or a prompt is the same job as auditing a skill or agent — deterministic checks,
|
||||
> a read, a qualitative pass, one shared report — over a different input type, which is exactly the
|
||||
> case the rule says belongs in one skill behind a dispatch table, not in a new sibling audit skill.
|
||||
> The authoring side follows the rule's other half: the author skills stay split because they emit
|
||||
> genuinely different artifacts, so hooks, instructions and prompts got their own
|
||||
> `primitive-author` rather than rows in `skill-author` or `agent-author`.
|
||||
|
||||
## Considered options
|
||||
|
||||
**Keep two skills and rely on the byte-identity contract test alone (rejected).** This is the status
|
||||
|
||||
@@ -8,17 +8,21 @@ parameters. It is the text a user would otherwise type again and again. It carri
|
||||
beyond steering existing skills or agents by name. Once it holds reusable know-how, bundled files,
|
||||
or anything the model should find on its own, it is a **Skill** in the wrong container.
|
||||
|
||||
This is stricter than apm. apm's docs call a prompt "a callable program for an LLM", and 0.28.0
|
||||
scaffolds one as a numbered-steps workflow (`apm_cli/workflow/discovery.py`). On every harness this
|
||||
repo targets, a prompt with a full workflow in it is a worse skill:
|
||||
This is stricter than apm. apm frames a prompt as a program: its docs state that "a prompt is a
|
||||
program for an LLM" (microsoft.github.io/apm/concepts/what-is-apm/, "Secure by default"; the same
|
||||
sentence is in the apm-cli 0.28.0 package README), and 0.28.0 scaffolds one as a numbered-steps
|
||||
workflow (`apm_cli/workflow/discovery.py`). On every harness this repo targets, a prompt with a full
|
||||
workflow in it is a worse skill:
|
||||
|
||||
- **Claude Code.** Custom commands have been merged into skills. "Both create `/deploy` and work
|
||||
the same way", and both are model-invocable by default (code.claude.com/docs/en/skills.md).
|
||||
apm 0.28.0 keeps only `description`, `allowed-tools`, `model`, `argument-hint` and `input` for
|
||||
Claude (`_PRESERVED_COMMAND_KEYS`) and drops `disable-model-invocation`. A deployed prompt is
|
||||
therefore a model-visible skill with fewer frontmatter keys, and it cannot be made user-only.
|
||||
- **Copilot / VS Code.** Prompt files are marked deprecated for Agent Host, and VS Code offers a
|
||||
migration to agent skills.
|
||||
- **Copilot / VS Code.** "Prompt files are deprecated for Agent Host sessions and aren't loaded by
|
||||
Agent Host", and VS Code offers a migration that converts existing prompt files to agent skills
|
||||
(code.visualstudio.com/docs/agent-customization/prompt-files). They still load in the Local agent,
|
||||
which that page says will be removed in a future release.
|
||||
- **Codex.** Codex receives no prompts at all.
|
||||
|
||||
The one job a prompt does better than a skill is a short, parameterised "do this now, using X and Y"
|
||||
@@ -45,10 +49,28 @@ happen, the cost is bounded: the prompt is a thin wrapper that calls the right s
|
||||
- `description` is present and non-empty (FAIL).
|
||||
- It is 250 characters or fewer (SUGGESTION).
|
||||
- It has no "Use when" trigger clause (SUGGESTION).
|
||||
- It has no `Not X -> Y` boundary clause (SUGGESTION).
|
||||
- **`factory-audit`, judgment step.** A body that clearly carries reusable procedure is a FAIL. A
|
||||
borderline body is a SUGGESTION. There is deliberately no line-count or heading heuristic: the
|
||||
call is made by reading the content, because any threshold misfires.
|
||||
|
||||
## Consequences
|
||||
|
||||
- **`factory-audit` gains a prompt mode.** `*.prompt.md` is a Step 0 dispatch row with its own
|
||||
`references/prompt-flow.md`, and `scripts/lib-checks-primitive.sh` carries the three description
|
||||
checks above plus the judgment step (ADR-0025, amendment 2026-09-28). A prompt that was fine under
|
||||
apm's framing — a trigger clause, a boundary clause, a numbered workflow — now draws findings.
|
||||
- **`primitive-author` refuses procedure-bearing prompts.** Its prompt reference opens with the
|
||||
boundary gate, so a "make me a command" request that carries reusable know-how is redirected to
|
||||
`skill-author` before any file is written. That makes skill-vs-prompt a checked boundary rather
|
||||
than an authoring preference.
|
||||
- **Codex gets no prompts from this repo.** apm deploys none to Codex, so anything a prompt steers
|
||||
must also be reachable there through the skill it names. Keeping procedure in the skill is what
|
||||
makes that true; a fat prompt would be content Codex users silently never see.
|
||||
- **Reversing this is cheap in files, not in routing.** No prompt exists in the repo yet, so the rule
|
||||
constrains new work only. Loosening it later means re-deciding the description contract, and every
|
||||
prompt written under it would need a trigger clause added.
|
||||
|
||||
## Considered options
|
||||
|
||||
- **Fat workflow prompts as peers of skills (rejected).** This follows apm's framing. But every
|
||||
|
||||
+26
-14
@@ -787,8 +787,10 @@ Wiring Vale as a deterministic prefilter for `factory-audit`'s Description dimen
|
||||
issue #84) is repo-specific, not part of the generic `lint` plugin, so it does not live in
|
||||
`plugins/lint/` — and per ADR-0014 it no longer lives at the repo root either. It lives **once**,
|
||||
under `plugins/kyberforge/.apm/skills/factory-audit/assets/vale/`, carrying both the `Kyberforge`
|
||||
and `KyberforgeCopilot` styles and a single `.vale.ini` with all three glob sections:
|
||||
`[**/SKILL.md]`, `[**/agents/*.md]`, `[**/*.agent.md]`.
|
||||
and `KyberforgeCopilot` styles and a single `.vale.ini` with five glob sections:
|
||||
`[**/SKILL.md]`, `[**/agents/*.md]`, `[**/*.instructions.md]`, `[**/*.prompt.md]` and
|
||||
`[**/*.agent.md]`. The instructions and prompt sections arrived with `factory-audit`'s primitive
|
||||
modes (ADR-0025, amendment 2026-09-28).
|
||||
|
||||
ADR-0014 split this into two skill-scoped copies because a plugin's cache-install copies only each
|
||||
skill's own files and `skill-audit` could not reach across the skill boundary into `agent-audit`'s
|
||||
@@ -816,7 +818,8 @@ Its `StylesPath` and `BasedOnStyles` checks were **not** diffs. They were per-fi
|
||||
invoked `vale --config` on one representative path per file shape. It was the only assertion
|
||||
anywhere that catches a `.vale.ini` glob typo (`[**/SKILL.md]` → `[**/SKILLS.md]`), the failure mode
|
||||
where every other check stays clean while Vale lints zero files. One config does not make that
|
||||
impossible: a typo in any one of the three sections still 0-file-skips that shape.
|
||||
impossible: a typo in any one section still 0-file-skips that shape. The table has since grown
|
||||
to eight rows: one each for the instructions and prompt sections added later.
|
||||
|
||||
**Case 0** runs before any Vale-dependent case and needs no Vale binary. It asserts that the shipped
|
||||
`.vale.ini` exists and is readable, sets a `StylesPath` that resolves to a directory, and names only
|
||||
@@ -826,8 +829,9 @@ cases back.
|
||||
|
||||
The probes now live in `tests/test-vale-wrap.sh` (cases 28–30), rehomed against the merged config:
|
||||
one representative path per file shape, each asserted to produce a Vale scan of more than zero files
|
||||
*and* a Kyberforge alert (case 28). Case 28 also checks that each probe path is in scope of a
|
||||
published vale hook, and that every `.vale.ini` section has a probe row. Its Part B drops
|
||||
*and* a Kyberforge alert (case 28). Case 28 also checks that every `.vale.ini` section has an
|
||||
isolating probe row. It no longer holds each probe path to a hook's `files:` scope: that half read
|
||||
the retired `.pre-commit-hooks.yaml`, and case 32 owns the local hooks' scope. Its Part B drops
|
||||
`Kyberforge` from each section's `BasedOnStyles` in a copy and requires that section's probes to
|
||||
fail as "style not loaded". Case 29 is a mutation case: it typos each section in a copy of the
|
||||
assets and requires that section's isolating probes to drop to zero. Case 30 asserts that
|
||||
@@ -931,17 +935,17 @@ authors. Without the binary the hooks fail with a bare "command not found" and n
|
||||
**Two hooks, not one combined hook — for a different reason than ADR-0014 gave.** The original
|
||||
reason was mechanical: with a config per skill, a single hook could point at only one copy and would
|
||||
silently 0-file-skip the other file shape (see
|
||||
[A 0-file Vale run is NOT RUN](#a-0-file-vale-run-is-not-run)). One `.vale.ini` carrying all three
|
||||
sections removes that constraint. The split stays anyway because the `files:` regexes still have to
|
||||
[A 0-file Vale run is NOT RUN](#a-0-file-vale-run-is-not-run)). One `.vale.ini` carrying every
|
||||
section removes that constraint. The split stays anyway because the `files:` regexes still have to
|
||||
differ — each hook hands Vale only the file shape it is scoped to. Both hooks name the same
|
||||
plugin-bundled `factory-audit/scripts/vale-wrap.sh` through `repo: local`; there is no second root
|
||||
copy.
|
||||
|
||||
### The `.vale.ini` globs do no scoping
|
||||
|
||||
The `.vale.ini`'s section globs are **path-agnostic** — `[**/SKILL.md]`, `[**/agents/*.md]` and
|
||||
`[**/*.agent.md]` — and constrain filename *shape*, not
|
||||
location: Vale's `*` crosses `/`. A `SKILL.md` outside `plugins/` (a project-scope
|
||||
The `.vale.ini`'s section globs are **path-agnostic** — `[**/SKILL.md]`, `[**/agents/*.md]`,
|
||||
`[**/*.instructions.md]`, `[**/*.prompt.md]` and `[**/*.agent.md]` — and constrain filename *shape*,
|
||||
not location: Vale's `*` crosses `/`. A `SKILL.md` outside `plugins/` (a project-scope
|
||||
`.claude/skills/foo/SKILL.md`, say) still matches `[**/SKILL.md]` and gets linted normally.
|
||||
|
||||
All scoping therefore comes from the pre-commit hooks' own `files:` regexes, which pin this repo's
|
||||
@@ -951,8 +955,16 @@ invocation — in this repo or in any repo that installs it, whatever that repo'
|
||||
Narrowing a `.vale.ini` glob to a `plugins/`-shaped path to "tighten" it breaks the consumer case:
|
||||
`factory-audit` run against a project-scope `.claude/skills/` tree would lint nothing.
|
||||
`check-vale-style-sync`'s probe set was built to catch exactly that; it moved to
|
||||
`tests/test-vale-wrap.sh` with the hook's deletion, and two of the six probes exist specifically to
|
||||
pin this location independence — see [One copy, one config](#one-copy-one-config).
|
||||
`tests/test-vale-wrap.sh` with the hook's deletion. Its table (`PROBE_TABLE28`) now has eight rows,
|
||||
one or more per section, and the two `.claude/`-prefixed rows exist specifically to pin this
|
||||
location independence — see [One copy, one config](#one-copy-one-config).
|
||||
|
||||
**No pre-commit Vale hook covers `*.instructions.md` or `*.prompt.md` yet.** The `.vale.ini`
|
||||
sections exist so that `factory-audit`'s own Vale call lints those files when it is handed one, in
|
||||
any repo. This repo's two prefilter hooks select only `SKILL.md` and `.agent.md` files, and the repo
|
||||
has no instruction or prompt file for a third hook to select. Case 32 requires every Vale hook's
|
||||
`files:` regex to match at least one tracked file, so a hook added now would fail it. Add the hook
|
||||
in the change that lands the first `.apm/instructions/` or `.apm/prompts/` file.
|
||||
|
||||
### The blind spot: `references/` is unlinted, for two independent reasons
|
||||
|
||||
@@ -1051,9 +1063,9 @@ clean.
|
||||
### Pre-push
|
||||
|
||||
`vale` is still a **pre-push** dependency, but no longer through a hook of its own.
|
||||
`check-vale-style-sync` — the hook that ran the six glob probes, and whose
|
||||
`check-vale-style-sync` — the hook that ran the original six glob probes, and whose
|
||||
`CHECK_VALE_STYLE_SYNC_ALLOW_MISSING_VALE=1` opt-out downgraded them audibly rather than skipping the
|
||||
hook — is deleted with the second Vale copy (ADR-0025). The six glob probes survive it inside
|
||||
hook — is deleted with the second Vale copy (ADR-0025). The glob probes survive it inside
|
||||
`test-vale-wrap.sh`, so `run-tests --strict` is now the gate that runs them. That is also what keeps
|
||||
`vale` a pre-push requirement: `test-vale-wrap.sh` exits 77 without the binary once its static cases
|
||||
pass, and a skip fails the push.
|
||||
|
||||
@@ -38,27 +38,47 @@ command -v apm > /dev/null 2>&1 || exit 0
|
||||
# `apm outdated` and `apm update` both resolve the lockfile from the cwd.
|
||||
cd "$project_dir" || exit 0
|
||||
|
||||
# Only ever emit fixed text plus a digit-checked count — never interpolate
|
||||
# command output into the JSON, which would need escaping this cannot do safely.
|
||||
emit() {
|
||||
printf '{"hookSpecificOutput":{"hookEventName":"SessionStart","reloadSkills":%s,"additionalContext":"%s"}}\n' "$1" "$2"
|
||||
}
|
||||
|
||||
# Every apm call is time-boxed, so timeout(1) is a hard requirement. It is GNU
|
||||
# coreutils: stock macOS has none, and Homebrew's coreutils installs it as
|
||||
# `gtimeout`. Calling a missing binary would exit 127, which the `|| exit 0`
|
||||
# below swallows — the hook would silently never work. Say so once instead, and
|
||||
# do not run apm unbounded.
|
||||
if command -v timeout > /dev/null 2>&1; then
|
||||
timeout_bin="timeout"
|
||||
elif command -v gtimeout > /dev/null 2>&1; then
|
||||
timeout_bin="gtimeout"
|
||||
else
|
||||
emit false "The apm install currency check did not run: neither timeout nor gtimeout (GNU coreutils) is on PATH, and this hook will not run apm without a time limit. Install coreutils (macOS: brew install coreutils) or run apm outdated by hand."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# apm drives git for every remote ref. A remote that wants credentials must fail
|
||||
# fast, not block on a terminal prompt nobody can see until the timeout fires.
|
||||
export GIT_TERMINAL_PROMPT=0
|
||||
|
||||
# `apm outdated` exits 0 whether or not anything is stale, so the answer has to
|
||||
# come from its output. ~0.7s against six remote refs; a hung remote must not
|
||||
# hold the session open.
|
||||
# hold the session open. -k sends SIGKILL a grace period after the SIGTERM, so a
|
||||
# child that ignores TERM cannot outlive its budget; tests/test-apm-current-hook.sh
|
||||
# sums every limit plus its grace against the hooks.json timeout.
|
||||
#
|
||||
# There is no --json/machine-readable flag on `apm outdated` (verified against
|
||||
# apm 0.28.0), so the phrase match is forced rather than chosen. Note the
|
||||
# singular: apm prints "1 outdated dependency found" when exactly one package is
|
||||
# behind, so matching only "dependencies" would silently miss a one-package
|
||||
# drift. tests/test-apm-current-hook.sh pins both spellings against the real apm.
|
||||
outdated_output="$(timeout 60 apm outdated 2>&1)" || exit 0
|
||||
outdated_output="$("$timeout_bin" -k 5 60 apm outdated 2>&1)" || exit 0
|
||||
grep -qE 'outdated dependenc(y|ies) found' <<< "$outdated_output" || exit 0
|
||||
|
||||
stale_count="$(grep -oE '[0-9]+ outdated dependenc(y|ies) found' <<< "$outdated_output" | grep -oE '^[0-9]+' || true)"
|
||||
[[ "$stale_count" =~ ^[0-9]+$ ]] || stale_count="some"
|
||||
|
||||
# Only ever emit fixed text plus a digit-checked count — never interpolate
|
||||
# command output into the JSON, which would need escaping this cannot do safely.
|
||||
emit() {
|
||||
printf '{"hookSpecificOutput":{"hookEventName":"SessionStart","reloadSkills":%s,"additionalContext":"%s"}}\n' "$1" "$2"
|
||||
}
|
||||
|
||||
# What to do with the rewritten lock depends on the branch (ADR-0019): on the
|
||||
# default branch it is a real update to commit or discard; on a feature branch it
|
||||
# is churn unrelated to the branch and should be discarded. The branch name only
|
||||
@@ -85,7 +105,23 @@ if [[ -n "$current_branch" && -n "$default_branch" ]]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
if timeout 300 apm update --yes > /dev/null 2>&1; then
|
||||
# Two sessions started together would both run `apm update --yes` over the same
|
||||
# tree. Serialise on a lock under apm_modules/: `apm install` itself adds that
|
||||
# directory to .gitignore, so the lock never shows up as a working-tree change,
|
||||
# and apm only ever removes package directories inside it, never the directory
|
||||
# (or this file) itself. The loser does not wait — the winner's refresh is the
|
||||
# one it wanted — and says so. flock(1) is util-linux, absent on stock macOS,
|
||||
# and there the refresh runs unserialised, as it did before the lock existed; so
|
||||
# does a checkout with no apm_modules/ yet, rather than creating it.
|
||||
if command -v flock > /dev/null 2>&1 && [[ -d apm_modules ]] \
|
||||
&& { exec 9> apm_modules/.kyberforge-apm-update.lock; } 2> /dev/null; then
|
||||
if ! flock -n 9; then
|
||||
emit false "apm install is ${stale_count} package(s) behind the remote default branch, and another session is refreshing it right now, so this session skipped its own refresh. Skills and agents loaded in this session may be stale; if they are, restart the session once that refresh has finished."
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
if "$timeout_bin" -k 5 300 apm update --yes > /dev/null 2>&1; then
|
||||
emit true "apm install was ${stale_count} package(s) behind the remote default branch and has been refreshed automatically; skills and agents were redeployed and re-scanned. apm.lock.yaml has been rewritten and is now a modified file in the working tree - ${lock_advice}"
|
||||
else
|
||||
emit false "apm install is ${stale_count} package(s) behind the remote default branch and the automatic refresh failed. Deployed skills and agents may be stale. Run: apm update --yes"
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
---
|
||||
name: agent-author
|
||||
description: >
|
||||
Use when the user wants to create a new agent definition file from scratch, or
|
||||
apply grill findings, audit findings, or inline feedback to an existing one.
|
||||
Use when the user wants a new agent definition created, or grill, audit
|
||||
or inline feedback applied to an existing one.
|
||||
Not read-only review -> `factory-audit`. Not skills -> `skill-author`.
|
||||
Not hooks, instructions or prompts -> `primitive-author`.
|
||||
allowed-tools: Bash Read Write Edit
|
||||
metadata:
|
||||
version: "1.0.3"
|
||||
version: "1.0.4"
|
||||
category: factory
|
||||
source_keys:
|
||||
- context7-websites-code-claude
|
||||
@@ -60,6 +61,6 @@ At every scope, five tools reach no subagent whatever `tools` says — `AskUserQ
|
||||
|
||||
Invoke `factory-audit` on each file written and resolve every FAIL before reporting done. It checks the field allowlist, name-to-stem match, leftover placeholders and template comments, the description budget and the Copilot body limit — do not hand-check those.
|
||||
|
||||
At plugin/APM scope bump the resolved package's `apm.yml` `version` — **minor** on create, **patch** on improve — because consumers compare it to detect updates. Project and user scope have no manifest.
|
||||
At plugin/APM scope bump the resolved package's `apm.yml` `version` — **minor** on create, **patch** on improve — because consumers compare it to detect updates. Skip, and say so, if this branch already bumped it: `git diff $(git merge-base HEAD <remote-default-branch>) -- <package>/apm.yml` shows a changed `version:` line, and one bump covers a branch. Project and user scope have no manifest.
|
||||
|
||||
**Commit verification.** Once the audit is clean, run `rtk git add` and `rtk git commit` — do not stop at staging. Re-run `rtk git log --oneline -1` and confirm the hash changed from Step 1's. A non-empty `git diff --stat` is not proof: staged-but-uncommitted work is part of no commit and is lost if the tree is cleaned up. Report done only once the hash has changed.
|
||||
@@ -15,13 +15,13 @@ metadata:
|
||||
## Gotchas
|
||||
|
||||
- `apm experimental enable registries` must run before a `registries:` block or `registry.*` config takes effect in any flow; without it they silently do nothing.
|
||||
- `apm.yml`'s `type:` is never checked against what `.apm/` holds, so `apm install` and `apm compile` can exit 0 shipping none of the primitives you expected. Confirm the deployed output, not the exit code (`references/configure.md`).
|
||||
- `apm.yml`'s `type:` is never checked against `.apm/`, so `apm install` and `apm compile` can exit 0 shipping none of the expected primitives. Set `type:` to cover every primitive shipped; confirm the deployed output, not the exit code (`references/configure.md`).
|
||||
|
||||
## Step 1 — Dispatch
|
||||
|
||||
| Condition | Flow | Reference |
|
||||
|---|---|---|
|
||||
| Author or edit `apm.yml`, or scaffold a new package (`apm plugin init`) | configure | `references/configure.md` |
|
||||
| Author or edit `apm.yml`, or scaffold a new package (`apm plugin init`); skill, agent, hook, instruction or prompt content goes to the matching author skill | configure | `references/configure.md` |
|
||||
| Resolve or fetch the dependencies `apm.yml` declares (`apm install`, `apm install [PACKAGE_REF]`) | install | `references/install.md` |
|
||||
| Build a marketplace, register a package into it (local: hand-edit `apm.yml`; remote: `apm marketplace package add`), or register someone else's as a consumer (`apm marketplace init/check/package add/add`) | marketplace | `references/marketplace.md` |
|
||||
| Generate per-target output, bundle, or publish (`apm compile`, `apm pack`, `apm publish`) | compile | `references/compile.md` |
|
||||
|
||||
@@ -34,6 +34,8 @@ Bundles a producer package into a distributable artifact. Default to `--dry-run
|
||||
- A populated one gets its `mcpServers` content merged directly into the compiled `plugin.json`, but only for the `claude` target.
|
||||
- The `copilot` target's compiled `plugin.json` OMITS `mcpServers` entirely — it isn't part of Copilot's plugin manifest schema.
|
||||
|
||||
`mcpServers` headers and env must use `${VAR}` indirection — the content is merged verbatim into the published `plugin.json`, so a literal secret ships with the package.
|
||||
|
||||
`dependencies.mcp` in `apm.yml` is for a different purpose — declaring a remote MCP-server package as an APM dependency — not local `.mcp.json` passthrough.
|
||||
|
||||
### `includes: auto` and the packed bundle
|
||||
|
||||
@@ -10,7 +10,7 @@ source_keys:
|
||||
apm plugin init --yes --target claude,copilot
|
||||
```
|
||||
|
||||
Run from inside the target package directory, with no positional name argument (see Gotchas). Creates `apm.yml` + `plugin.json` in the current directory — it does NOT scaffold a `.apm/` skeleton. Primitive subdirectories (`.apm/skills/`, `.apm/agents/`, `.apm/hooks/`) must be created manually as content is migrated into them. Run this once per package (e.g. once per `plugins/<name>/` directory in a monorepo-hybrid layout), not once for the whole repo.
|
||||
Run from inside the target package directory, with no positional name argument (see this file's Gotchas). Creates `apm.yml` + `plugin.json` in the current directory — it does NOT scaffold a `.apm/` skeleton. Create each primitive subdirectory (`.apm/skills/`, `.apm/agents/`, `.apm/hooks/`, `.apm/instructions/`, `.apm/prompts/`) through its author skill as content lands in it: skills via `skill-author`, agents via `agent-author`, hooks, instructions and prompts via `primitive-author`. Run this once per package (e.g. once per `plugins/<name>/` directory in a monorepo-hybrid layout), not once for the whole repo.
|
||||
|
||||
## `apm.yml` — required fields
|
||||
|
||||
@@ -25,7 +25,7 @@ version: 1.0.0
|
||||
|
||||
- `name`, `version` — required (see above)
|
||||
- `description`, `author`, `license`, `homepage`, `repository`, `keywords` — standard package metadata
|
||||
- `type` — `instructions | skill | hybrid | prompts`; selects how the package is processed at install/compile time. It is a routing selector, not a constraint on what `.apm/` may contain (see Gotchas)
|
||||
- `type` — `instructions | skill | hybrid | prompts`; selects how the package is processed at install/compile time. It is a routing selector, not a constraint on what `.apm/` may contain (see this file's Gotchas)
|
||||
- `targets` — which harnesses this package compiles to (plural list form preferred; legacy singular `target: copilot,claude` CSV form still accepted)
|
||||
- `includes` — `auto` publishes the authoritative local layout as-is; it is not scoped down to what's relevant, so anything narrower needs an explicit repo-path list. Note: `auto` also does not sweep generic root-level passthrough files (README.md, docs/, sources.md, config files) into the `apm pack` distribution bundle — see `references/compile.md`
|
||||
- `dependencies`/`devDependencies` — `apm`/`mcp`/`lsp` entries; `devDependencies` share the same shape but are excluded from the shipped artifact
|
||||
@@ -80,7 +80,7 @@ MCP server secrets (headers, env vars) in `apm.yml` must use `${VAR}` indirectio
|
||||
Any git repo is a valid package source by default — no registry required. To declare named registries for shorthand dependency resolution:
|
||||
|
||||
```bash
|
||||
apm experimental enable registries # required first — see Gotchas
|
||||
apm experimental enable registries # required first — see this file's Gotchas
|
||||
apm config set registry.corp-main.url https://artifactory.corp.example.com/apm
|
||||
apm config set registry.corp-main.token "$CORP_APM_TOKEN"
|
||||
apm config set registry.corp-main.default true
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
---
|
||||
name: factory-audit
|
||||
description: >
|
||||
Use when a skill, agent, or apm hook, instruction or prompt needs auditing,
|
||||
or "is this ready to ship". Not fixing a skill -> skill-author.
|
||||
Use when a skill, agent, apm hook, instruction or prompt needs auditing
|
||||
("ready to ship?"), even after a hand edit. Not fixing a skill -> skill-author.
|
||||
Not fixing an agent -> agent-author.
|
||||
Not fixing a hook, instruction or prompt -> primitive-author.
|
||||
allowed-tools: Bash Read
|
||||
@@ -42,7 +42,7 @@ Resolve the flow from the target path **before running anything**. The flows run
|
||||
| A file named `*.instructions.md` | instruction | `references/instruction-flow.md` |
|
||||
| A file named `*.prompt.md` | prompt | `references/prompt-flow.md` |
|
||||
| A `.md` file whose immediate parent directory is `agents/` (`.apm/agents`, `.claude/agents`, `.github/agents`, `.copilot/agents`) | agent | `references/agent-flow.md` |
|
||||
| A `.json` file whose immediate parent directory is `hooks/` (`.apm/hooks`, or a package-root `hooks/`; any other `hooks/` is deployed output the hook flow FAILs) | hook | `references/hook-flow.md` |
|
||||
| A `.json` file whose immediate parent directory is `hooks/` (`.apm/hooks`, or a package-root `hooks/`; the hook flow FAILs any other `hooks/`) | hook | `references/hook-flow.md` |
|
||||
| Anything else — a missing path, a directory without `SKILL.md`, any other file | none | — |
|
||||
|
||||
Read only the file its row matched. Each carries Steps 1 to 3 — the deterministic checks, the read, and the qualitative audit — and is self-contained. Return here for Step 4.
|
||||
|
||||
@@ -12,7 +12,7 @@ BasedOnStyles = Kyberforge
|
||||
[**/*.prompt.md]
|
||||
BasedOnStyles = Kyberforge
|
||||
|
||||
# Stays the last section: tests/test-vale-wrap.sh case 31 appends a rule
|
||||
# Stays the last section: the repo's `tests/test-vale-wrap.sh` case 31 appends a rule
|
||||
# override to the end of this file and relies on it landing here.
|
||||
[**/*.agent.md]
|
||||
BasedOnStyles = Kyberforge, KyberforgeCopilot
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
extends: existence
|
||||
message: "Generic reference pointer: '%s' — use the specific 'If X, read `references/file.md`' form instead"
|
||||
message: "Generic reference pointer: '%s' — name the exact file and when to read it ('If X, read `<path>`') instead"
|
||||
level: error
|
||||
scope: text
|
||||
ignorecase: true
|
||||
|
||||
@@ -25,17 +25,41 @@ Resolve the path against this skill's own directory. Run exactly:
|
||||
bash scripts/validate.sh <hook-file>
|
||||
```
|
||||
|
||||
Its findings become the `### Structure` dimension, FAILs and SUGGESTIONs both, at the tier the script assigned: JSON validity, the wrapped-or-naked shape, event lists and nested handler lists (the checks whose failure makes the Copilot install fail), a file contributing no entries (no events, only empty event lists, or an entry with no handler), event names that never fire, unfilled `FILL IN` or `FILL_IN_` template placeholders, a symlinked file or one under apm's deployed output rather than package source, referenced scripts that are missing, outside the package, not executable when run directly, or referenced by an absolute, bare relative, `../`, split-quoted, space-containing, or `$`/backtick-containing path apm will not bundle correctly, deprecated filename routing, and `${CLAUDE_PLUGIN_ROOT}` where `${PLUGIN_ROOT}` would do. Script references are read with apm 0.28.0's own patterns: `${PLUGIN_ROOT}/…` only when the path follows the token directly, up to the first whitespace or quote, and `./…` anywhere in the command. A `./` or `../` match is held to the script rules — a FAIL when missing — only in command position (the first token, or the first operand after `bash`, `sh`, `zsh`, `python`, `python3`, `node`, `pwsh`, `ruby` or `perl`, past its options such as `-e` or `-u`; after a `sh`-family `-c`, the first token of the command string; inline code such as `python3 -c` has none), when it ends in a script extension, or when it names a package entry that is not a file; any other match (`npx prettier --check ./src`, `printf '.\n'`) is at most a SUGGESTION, because apm only warns and it runs against the consumer's working directory as meant. Absolute and bare relative script paths are checked in the same command positions. Each event is judged per target the package root's `apm.yml` deploys to — no `target:`/`targets:`, `all`, or no `apm.yml` means every hook target — after apm's rename map for that target: it FAILs when a target with a published event list (Claude, Copilot) does not fire the renamed name, whatever its casing. It exits **0** with no FAIL, **1** on real findings, **2** when it never ran — report that as `### Structure` unverified, quoting the stderr reason. An INFO line is observational: report it under `### Structure` and count it in `· P info`.
|
||||
Its findings become the `### Structure` dimension, FAILs and SUGGESTIONs both, at the tier the script assigned.
|
||||
|
||||
Checks:
|
||||
|
||||
- JSON validity and UTF-8 encoding; a top level that is not a JSON object; the wrapped-or-naked shape; event lists and nested handler lists (the checks whose failure makes the Copilot install fail).
|
||||
- A file contributing no entries (no events, only empty event lists, or an entry with no handler), an empty event name, and event names that never fire.
|
||||
- Unfilled `FILL IN` or `FILL_IN_` template placeholders.
|
||||
- A symlinked file, or one under apm's deployed output or outside any package rather than package source (exit 1, a finding, not exit 2).
|
||||
- Referenced scripts that are missing, outside the package, not executable when run directly, or referenced by an absolute, bare relative, `../`, split-quoted, space-containing, or `$`/backtick-containing path apm will not bundle correctly.
|
||||
- A plugin-root token apm never rewrites: unbraced (`$PLUGIN_ROOT/x.sh`, `$CLAUDE_PLUGIN_ROOT`), or braced but not directly followed by `/` or `\` (`cd ${PLUGIN_ROOT} && …`).
|
||||
- Deprecated filename routing, and `${CLAUDE_PLUGIN_ROOT}` where `${PLUGIN_ROOT}` would do.
|
||||
- INFO: no `apm.yml` at an inferred `.apm/` package root, or a `targets:` naming no hook target apm recognises (`claude-code`), which leaves event names checked against no harness.
|
||||
|
||||
Script reference rules:
|
||||
|
||||
- Script references are read with apm 0.28.0's own patterns: `${PLUGIN_ROOT}/…` only when the path follows the token directly, up to the first whitespace or quote, and `./…` anywhere in the command.
|
||||
- A `./` or `../` match is held to the script rules — a FAIL when missing — only in command position, when it ends in a script extension, or when it names a package entry that is not a file; any other match (`npx prettier --check ./src`, `printf '.\n'`) is at most a SUGGESTION, because apm only warns and it runs against the consumer's working directory as meant.
|
||||
- Command position is the first token past any `NAME=value` assignments and `env` with its options, or the first operand after `bash`, `sh`, `zsh`, `python`, `python3`, `node`, `pwsh`, `ruby` or `perl`, past its options such as `-e` or `-u`; after a `sh`-family `-c`, the first token of the command string; inline code such as `python3 -c` has none. Absolute and bare relative script paths are checked in the same positions.
|
||||
- The exec bit is required of a script that runs directly: the first token, or the first token of a `-c` command string (`bash -c "${PLUGIN_ROOT}/x.sh"`). Through an interpreter it is not.
|
||||
- Each event is judged per target the package root's `apm.yml` deploys to — no `target:`/`targets:`, `all`, or no `apm.yml` means every hook target — after apm's rename map for that target: it FAILs when a target with a published event list (Claude, Copilot) does not fire the renamed name, whatever its casing.
|
||||
|
||||
Exit codes: **0** with no FAIL, **1** on real findings, **2** when it never ran, including a crash inside the checks — report that as `### Structure` unverified, quoting the stderr reason. An INFO line is observational: report it under `### Structure` and count it in `· P info`.
|
||||
|
||||
The command parser is a heuristic, not a shell. Known blind spots: a script after `&&`, `;` or a pipe inside one command, `env -S`, command substitution, and a quoted `-c` string that ends before the script are not in command position, so a bad reference there is at most a SUGGESTION or unseen. Read every command in Step 2 rather than taking a clean script run as proof.
|
||||
|
||||
There is no provenance and no Vale step: a hook carries no `source_keys` and no prose.
|
||||
|
||||
Five tiers deliberately differ from `primitive-author`'s checklist or the research's. Do not re-tier them by judgment:
|
||||
Six tiers deliberately differ from `primitive-author`'s checklist or the research's. Do not re-tier them by judgment:
|
||||
|
||||
- A hook file directly under a package-root `hooks/` — beside the package's `apm.yml`, or beside a `plugin.json` at any location apm's `find_plugin_json` reads (root, `.github/plugin/`, `.claude-plugin/`, `.cursor-plugin/`) — passes. apm discovers both `.apm/hooks/` and `hooks/`, installs a Claude plugin with no `apm.yml`, and this audit may target a third-party package; `primitive-author` authors only in `.apm/hooks/`. Any other `hooks/` directory (`.github/hooks/`, `.cursor/hooks/`, …) is apm's deployed output and FAILs.
|
||||
- A hook file directly under a package-root `hooks/` — beside the package's `apm.yml`, or beside a `plugin.json` at any location apm's `find_plugin_json` reads (root, `.github/plugin/`, `.claude-plugin/`, `.cursor-plugin/`) — passes. apm discovers both `.apm/hooks/` and `hooks/`, installs a Claude plugin with no `apm.yml`, and this audit may target a third-party package; `primitive-author` authors only in `.apm/hooks/`. Any other `hooks/` directory (`.github/hooks/`, `.cursor/hooks/`, …) is apm's deployed output, or no package source at all, and FAILs at exit 1.
|
||||
- An event that every listed target fires, but that reaches a target with no published event list (Cursor, Kiro, Gemini, Codex, Antigravity, Windsurf) in a non-PascalCase form after apm's rename, is a SUGGESTION, not the FAIL Must 4 implies: the script cannot tell a harness's native spelling (Cursor's `stop`, Windsurf's `pre_run_command`) from a typo. A Cursor-only `stop` therefore exits 0.
|
||||
- Copilot counts every name apm's own Copilot map emits as fired (`userPromptSubmit`, although Copilot documents `userPromptSubmitted`): the author cannot route around apm's rename, so that is not a finding in the file.
|
||||
- Deprecated filename routing is a SUGGESTION, matching the author's Should: the research allows it when deprecated routing is intended.
|
||||
- A non-executable script run as the command's first token is a FAIL, stricter than the research's Should, because it fails every time it fires.
|
||||
- A non-executable script run directly (the first token, or first in a `-c` string) is a FAIL, stricter than the research's Should, because it fails every time it fires.
|
||||
- `primitive-author` hook Must 5 bans an absolute or bare relative path "in any position"; this audit checks command positions only, because a later argument is data the script cannot tell from a path. Judge the rest by reading in Step 3.
|
||||
|
||||
## Step 2 — Read the hook and its scripts
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ bash scripts/validate.sh <instruction-file>
|
||||
bash scripts/vale-wrap.sh <instruction-file>
|
||||
```
|
||||
|
||||
`validate.sh` findings become the `### Structure` dimension, FAILs and SUGGESTIONs both, at the tier the script assigned: path, unfilled `FILL IN` or `FILL_IN_` template placeholders, frontmatter, `description`, body, an `applyTo` that is present but empty or has unbalanced braces or brackets, a missing or list-form `applyTo`, extra keys, and a stem duplicated at the package root. It exits **0** with no FAIL, **1** on real findings, **2** when it never ran — report that as `### Structure` unverified, quoting the stderr reason.
|
||||
`validate.sh` findings become the `### Structure` dimension, FAILs and SUGGESTIONs both, at the tier the script assigned: path, a file that is not valid UTF-8, unfilled `FILL IN` or `FILL_IN_` template placeholders, frontmatter, `description`, body, an `applyTo` that is neither a string nor a list, present but empty, or has unbalanced braces or brackets (a closer before its opener counts), a missing or list-form `applyTo`, extra keys, and a stem duplicated at the package root. It exits **0** with no FAIL, **1** on real findings, **2** when it never ran, including a crash inside the checks — report that as `### Structure` unverified, quoting the stderr reason.
|
||||
|
||||
A missing `applyTo` is a SUGGESTION, not the FAIL `primitive-author`'s instruction Must 4 implies: absence is legal after the author Gate's explicit yes, which the audit cannot see. The **scope** dimension's always-on FAILs below cover the misuse. Do not re-tier it by judgment.
|
||||
|
||||
@@ -33,7 +33,7 @@ There is no provenance step: an instruction carries no `source_keys`.
|
||||
|
||||
## Step 2 — Read the instruction and its context
|
||||
|
||||
Read the file, the package's `apm.yml`, and the repo's root `AGENTS.md`. For a scoped file, list the tracked files its `applyTo` matches (`rtk git ls-files` filtered by the glob). List the instruction stems the installed dependencies ship (`apm_modules/**/.apm/instructions/*.instructions.md`) — the script checks only the package root for a duplicate.
|
||||
Read the file, the package's `apm.yml`, and the repo's root `AGENTS.md`. For a scoped file, list the tracked files its `applyTo` matches (`git ls-files` filtered by the glob). List the instruction stems the installed dependencies ship (`apm_modules/**/.apm/instructions/*.instructions.md`) — the script checks only the package root for a duplicate.
|
||||
|
||||
## Step 3 — Qualitative audit
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ order, then return to `SKILL.md` Step 4 to report.
|
||||
|
||||
## Gotchas
|
||||
|
||||
- A prompt is judged against ADR-0029, not against apm's framing. apm calls a prompt "a callable program"; this repo holds it to a single-intent, user-triggered message that steers existing skills or agents by name and carries no procedure of its own.
|
||||
- A prompt is judged against ADR-0029, not against apm's framing. apm's docs call a prompt "a program for an LLM" (`apm-docs-llms-full`, "What is APM?" › "Secure by default"); this repo holds it to a single-intent, user-triggered message that steers existing skills or agents by name and carries no procedure of its own.
|
||||
- A prompt's description is not a skill description. It is one plain user-facing sentence with no "Use when" trigger clause and no boundary clause — so never raise a missing trigger or boundary as a finding. A Vale `Kyberforge.DescriptionOpener` alert here means rewrite it as an imperative action ("Review the current PR with …"), not add a trigger.
|
||||
|
||||
## Step 1 — Deterministic checks
|
||||
@@ -24,7 +24,7 @@ bash scripts/validate.sh <prompt-file>
|
||||
bash scripts/vale-wrap.sh <prompt-file>
|
||||
```
|
||||
|
||||
`validate.sh` findings become the `### Structure` dimension, FAILs and SUGGESTIONs both, at the tier the script assigned: path and name, unfilled `FILL IN` or `FILL_IN_` template placeholders, frontmatter, `description` presence, length, and trigger or `Not X -> Y` boundary clause, keys Claude drops, the camelCase spelling of `allowed-tools` or `argument-hint` and an `argument-hint` alongside `input:` (both SUGGESTION), `input:` names and the object form `- <name>: "<desc>"` (`primitive-author` prompt Must 3 — a bare name, a string list or a plain map is a FAIL even though apm reads them), and `${input:x}` references against `input:`. Keys Claude drops are a SUGGESTION, per `primitive-author` prompt Should 5: a Copilot-only key is legitimate when its Claude drop is intended, and only the author can say which. It exits **0** with no FAIL, **1** on real findings, **2** when it never ran — report that as `### Structure` unverified, quoting the stderr reason.
|
||||
`validate.sh` findings become the `### Structure` dimension, FAILs and SUGGESTIONs both, at the tier the script assigned: path and name, a file that is not valid UTF-8, unfilled `FILL IN` or `FILL_IN_` template placeholders, frontmatter, `description` presence, length, and trigger or `Not X -> Y` boundary clause, keys Claude drops, the camelCase spelling of `allowed-tools` or `argument-hint` and an `argument-hint` alongside `input:` (both SUGGESTION), `input:` names and the object form `- <name>: "<desc>"` (`primitive-author` prompt Must 3 — a bare name, a string list or a plain map is a FAIL even though apm reads them), and `${input:x}` references against `input:`. Keys Claude drops are a SUGGESTION, per `primitive-author` prompt Should 5: a Copilot-only key is legitimate when its Claude drop is intended, and only the author can say which. It exits **0** with no FAIL, **1** on real findings, **2** when it never ran, including a crash inside the checks — report that as `### Structure` unverified, quoting the stderr reason.
|
||||
|
||||
`vale-wrap.sh` applies the bundled `Kyberforge` style. Every alert is a FAIL under `### Prose`, cited by rule ID; do not re-derive it by judgment. That includes the rules scoped to the `description` (`Kyberforge.DescriptionOpener`, `VagueWording`, `CompositionNote`), a deliberate deviation from `primitive-author`, which holds description wording to at most a Should: the house prose rules apply to every model- or user-visible description, and a deterministic rule does not change tier by file kind. Do not re-tier them. `0 files` scanned means NOT RUN, not clean — say so and judge prose by reading.
|
||||
|
||||
|
||||
@@ -159,7 +159,8 @@ source_keys:
|
||||
|
||||
## apm-cli-installed-source
|
||||
|
||||
- **URL:** file:///root/.local/pipx/venvs/apm-cli/lib/python3.11/site-packages/apm_cli/
|
||||
- **URL:** https://github.com/microsoft/apm/tree/v0.28.0/src/apm_cli/
|
||||
- **Note:** read locally from the pipx install at `~/.local/pipx/venvs/apm-cli/lib/python3.11/site-packages/apm_cli/` (apm-cli 0.28.0, tag `v0.28.0`)
|
||||
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md
|
||||
- **Description:** Installed apm-cli 0.28.0 source — ground truth for what apm deploys from a hook, instruction or prompt file and what it silently skips, warns on, or fails the install for; every deterministic check in `scripts/lib-checks-primitive.sh` traces to it via the research docs' Authoring checklists
|
||||
- **Contributing files:** SKILL.md, references/hook-flow.md, references/instruction-flow.md, references/prompt-flow.md
|
||||
|
||||
@@ -129,7 +129,9 @@ def package_root_for(subdir):
|
||||
return os.path.dirname(apm_dir)
|
||||
|
||||
|
||||
FRONTMATTER_RE = re.compile(r'\A---[ \t]*\r?\n(.*?)\r?\n---[ \t]*(?:\r?\n|\Z)', re.DOTALL)
|
||||
# The inner group is lazy-optional so an empty block (`---` directly followed
|
||||
# by `---`) matches as empty rather than as no block at all.
|
||||
FRONTMATTER_RE = re.compile(r'\A---[ \t]*\r?\n(?:(.*?)\r?\n)??---[ \t]*(?:\r?\n|\Z)', re.DOTALL)
|
||||
|
||||
|
||||
def split_frontmatter(content):
|
||||
@@ -141,7 +143,7 @@ def split_frontmatter(content):
|
||||
fail(f"has no YAML frontmatter block (--- ... ---) — description and every other key live there — {fname}")
|
||||
return None, content, False
|
||||
try:
|
||||
fm = yaml.safe_load(m.group(1))
|
||||
fm = yaml.safe_load(m.group(1) or '')
|
||||
except yaml.YAMLError as exc:
|
||||
mark = getattr(exc, 'problem_mark', None)
|
||||
where = f" at line {mark.line + 2}" if mark is not None else ''
|
||||
@@ -252,6 +254,12 @@ ROOT_TOKEN_RE = re.compile(r'\$\{(' + '|'.join(ROOT_TOKENS) + r')\}')
|
||||
# matches after an interpreter (`bash ./x.sh`) too.
|
||||
APM_ROOT_REF_RE = re.compile(r'\$\{(?:' + '|'.join(ROOT_TOKENS) + r')\}([\\/][^\s"\']+)')
|
||||
APM_REL_REF_RE = re.compile(r'(\.[\\/][^\s"\']+)')
|
||||
# A plugin-root token apm never rewrites: unbraced, so its pattern cannot see it.
|
||||
UNBRACED_ROOT_RE = re.compile(r'\$(?:CLAUDE_|CURSOR_|KIRO_)?PLUGIN_ROOT\b')
|
||||
# A NAME=value shell assignment before the command, bare or after `env`.
|
||||
ASSIGN_RE = re.compile(r'^[A-Za-z_][A-Za-z0-9_]*=')
|
||||
# env options that consume the next token as their value.
|
||||
ENV_VALUE_OPTS = {'-u', '--unset', '-C', '--chdir'}
|
||||
|
||||
|
||||
# An interpreter whose first operand is the script it runs. A reference in
|
||||
@@ -276,16 +284,33 @@ def _prefix_tokens(prefix):
|
||||
return [t.strip('"\'') for t in prefix.split()]
|
||||
|
||||
|
||||
def _command_start(tokens):
|
||||
"""Index of the token that actually runs: past leading NAME=value
|
||||
assignments and an `env` with its options and assignments."""
|
||||
i = 0
|
||||
while i < len(tokens) and ASSIGN_RE.match(tokens[i]):
|
||||
i += 1
|
||||
if i < len(tokens) and os.path.basename(tokens[i]) == 'env':
|
||||
i += 1
|
||||
while i < len(tokens):
|
||||
tok = tokens[i]
|
||||
if tok in ENV_VALUE_OPTS:
|
||||
i += 2
|
||||
elif tok.startswith('-') or ASSIGN_RE.match(tok):
|
||||
i += 1
|
||||
else:
|
||||
break
|
||||
return i
|
||||
|
||||
|
||||
def _interp_arg_index(tokens):
|
||||
"""(index, is_command_string) of the script operand after a known
|
||||
interpreter (optionally behind `env`), or None when the command does not
|
||||
interpreter (optionally behind assignments or `env`), or None when the command does not
|
||||
open with one. Option flags are skipped (`bash -e x.sh`, `python3 -u x.py`);
|
||||
for a sh-family `-c` the operand is the command string, whose own first
|
||||
token is the script (`sh -c 'scripts/x.sh'`). Inline code (`python3 -c`,
|
||||
`node -e`) has no script operand."""
|
||||
i = 0
|
||||
if tokens and os.path.basename(tokens[0]) == 'env':
|
||||
i = 1
|
||||
i = _command_start(tokens)
|
||||
if not (len(tokens) > i and os.path.basename(tokens[i]) in INTERPRETERS):
|
||||
return None
|
||||
interp = os.path.basename(tokens[i])
|
||||
@@ -308,12 +333,21 @@ def _interp_arg_index(tokens):
|
||||
|
||||
|
||||
def _position(prefix):
|
||||
"""(is_first_token, is_interpreter_arg) for a reference preceded by prefix."""
|
||||
"""(is_direct, is_interpreter_arg) for a reference preceded by prefix.
|
||||
Direct means the reference is what runs: the command's first token, or the
|
||||
first token of a sh-family `-c` command string (`bash -c "./x.sh"`)."""
|
||||
toks = [t for t in _prefix_tokens(prefix) if t]
|
||||
if not toks:
|
||||
return True, False
|
||||
slot = _interp_arg_index(toks)
|
||||
return False, slot is not None and slot[0] == len(toks)
|
||||
while True:
|
||||
if _command_start(toks) == len(toks):
|
||||
return True, False
|
||||
slot = _interp_arg_index(toks)
|
||||
if slot is None:
|
||||
return False, False
|
||||
idx, is_command_string = slot
|
||||
if is_command_string and idx <= len(toks):
|
||||
toks = toks[idx:]
|
||||
continue
|
||||
return False, idx == len(toks)
|
||||
|
||||
|
||||
def is_handler(h):
|
||||
@@ -327,7 +361,7 @@ def is_handler(h):
|
||||
|
||||
|
||||
def extract_script_refs(cmd, pkg_root, where):
|
||||
"""Return (kind, relpath, is_first_token, is_interpreter_arg) for each
|
||||
"""Return (kind, relpath, is_direct, is_interpreter_arg) for each
|
||||
package-relative reference apm would rewrite, reading the command exactly
|
||||
as apm does. kind is 'root' for a ${*_PLUGIN_ROOT} token, 'rel' for a
|
||||
./path, 'up' for a ../path. A token apm reads wrongly — split-quoted, or a
|
||||
@@ -339,6 +373,10 @@ def extract_script_refs(cmd, pkg_root, where):
|
||||
start, end = m.start(), m.end()
|
||||
if end < len(cmd) and cmd[end] in '"\'' and cmd[end + 1:end + 2] in ('/', '\\'):
|
||||
fail(f"script path '{cmd[start:]}' splits the quote after ${{{m.group(1)}}} — apm rewrites only a path that follows the token directly, so this one deploys unrewritten and unbundled; quote the whole token: \"${{PLUGIN_ROOT}}/<path>\" — {where}")
|
||||
elif cmd[end:end + 1] not in ('/', '\\'):
|
||||
fail(f"${{{m.group(1)}}} is not followed directly by / or \\ — apm rewrites the token only as the head of a path (${{PLUGIN_ROOT}}/<path>), so here it deploys unrewritten and expands to nothing on most targets — {where}")
|
||||
for m in UNBRACED_ROOT_RE.finditer(cmd):
|
||||
fail(f"unbraced {m.group(0)} — apm rewrites only the braced ${{PLUGIN_ROOT}}/<path> form, so this deploys unrewritten and the script is not bundled; write ${{{m.group(0)[1:]}}}/<path> — {where}")
|
||||
for m in APM_ROOT_REF_RE.finditer(cmd):
|
||||
start, end = m.start(), m.end()
|
||||
opener = cmd[start - 1] if start > 0 and cmd[start - 1] in '"\'' else None
|
||||
@@ -397,7 +435,10 @@ def check_unanchored_script(cmd, pkg_root, where):
|
||||
toks = command_tokens(cmd)
|
||||
if not toks:
|
||||
return
|
||||
slots = [0]
|
||||
start = _command_start(toks)
|
||||
if start >= len(toks):
|
||||
return
|
||||
slots = [start]
|
||||
arg = _interp_arg_index(toks)
|
||||
if arg is not None and arg[0] < len(toks):
|
||||
if arg[1]:
|
||||
@@ -414,7 +455,7 @@ def check_unanchored_script(cmd, pkg_root, where):
|
||||
# In the first slot an extension-less absolute path outside the
|
||||
# package (`/usr/bin/env`, `/bin/bash`) is the host's interpreter;
|
||||
# in the interpreter-argument slot it is the script being run.
|
||||
if inside or SCRIPT_EXT_RE.search(tok) or idx > 0:
|
||||
if inside or SCRIPT_EXT_RE.search(tok) or idx > start:
|
||||
fail(f"script '{tok}' is an absolute path — apm neither bundles nor rewrites it, so it breaks on every other machine; reference it as ${{PLUGIN_ROOT}}/<path> — {where}")
|
||||
continue
|
||||
if '/' in tok:
|
||||
@@ -424,7 +465,7 @@ def check_unanchored_script(cmd, pkg_root, where):
|
||||
break
|
||||
|
||||
|
||||
def check_script(kind_, rel, first, interp_arg, pkg_root, where):
|
||||
def check_script(kind_, rel, direct, interp_arg, pkg_root, where):
|
||||
if not rel:
|
||||
return
|
||||
# apm's ./ pattern also matches plain arguments — a cwd directory
|
||||
@@ -433,7 +474,7 @@ def check_script(kind_, rel, first, interp_arg, pkg_root, where):
|
||||
# meant, so a ./ or ../ match is held to the script rules only in command
|
||||
# position or when it names a script by extension (or a package entry that
|
||||
# is not a file).
|
||||
strong = kind_ == 'root' or first or interp_arg or bool(SCRIPT_EXT_RE.search(rel))
|
||||
strong = kind_ == 'root' or direct or interp_arg or bool(SCRIPT_EXT_RE.search(rel))
|
||||
if kind_ == 'up':
|
||||
in_pkg = os.path.exists(os.path.join(pkg_root, rel)) and not os.path.isfile(os.path.join(pkg_root, rel))
|
||||
if strong or in_pkg:
|
||||
@@ -468,7 +509,7 @@ def check_script(kind_, rel, first, interp_arg, pkg_root, where):
|
||||
else:
|
||||
suggest(f"argument './{rel}' matches apm's ./ script pattern but names no package file — apm will warn 'Hook script not found' and leave it unrewritten; harmless if it is a path in the consumer's working directory — {where}")
|
||||
return
|
||||
if first and not os.access(found, os.X_OK):
|
||||
if direct and not os.access(found, os.X_OK):
|
||||
fail(f"script '{rel}' is run directly but is not executable — chmod +x it, or invoke it through an interpreter — {where}")
|
||||
|
||||
|
||||
@@ -510,7 +551,10 @@ def package_targets(pkg_root):
|
||||
tokens = {TARGET_ALIASES.get(t, t) for t in tokens if t}
|
||||
if not tokens or 'all' in tokens:
|
||||
return every
|
||||
return tokens & HOOK_TARGETS
|
||||
known = tokens & HOOK_TARGETS
|
||||
if not known:
|
||||
info(f"targets: in apm.yml names no hook target apm 0.28.0 recognises ({', '.join(sorted(tokens))}) — event names were checked against no harness; apm's hook targets are {', '.join(sorted(HOOK_TARGETS))} — {fname}")
|
||||
return known
|
||||
|
||||
|
||||
def check_event(event, deploys_to):
|
||||
@@ -653,8 +697,8 @@ def audit_hook():
|
||||
continue
|
||||
if '${CLAUDE_PLUGIN_ROOT}' in cmd:
|
||||
uses_claude_token = True
|
||||
for kind_, rel, first, interp_arg in extract_script_refs(cmd, pkg_root, where):
|
||||
check_script(kind_, rel, first, interp_arg, pkg_root, where)
|
||||
for kind_, rel, direct, interp_arg in extract_script_refs(cmd, pkg_root, where):
|
||||
check_script(kind_, rel, direct, interp_arg, pkg_root, where)
|
||||
check_unanchored_script(cmd, pkg_root, where)
|
||||
|
||||
if uses_claude_token:
|
||||
@@ -692,6 +736,28 @@ def split_top_level(value):
|
||||
return [s.strip() for s in segs if s.strip()]
|
||||
|
||||
|
||||
def _balanced(glob):
|
||||
# A depth walk per bracket kind: a closer before its opener (`}{`) is as
|
||||
# unbalanced as a missing one, which equal counts would not catch.
|
||||
for opener, closer in ('{}', '[]'):
|
||||
depth, i = 0, 0
|
||||
while i < len(glob):
|
||||
c = glob[i]
|
||||
if c == '\\':
|
||||
i += 2
|
||||
continue
|
||||
if c == opener:
|
||||
depth += 1
|
||||
elif c == closer:
|
||||
depth -= 1
|
||||
if depth < 0:
|
||||
return False
|
||||
i += 1
|
||||
if depth:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
def check_apply_to(apply_to):
|
||||
if isinstance(apply_to, list):
|
||||
entries = [e for e in apply_to if e is not None and str(e).strip()]
|
||||
@@ -706,7 +772,7 @@ def check_apply_to(apply_to):
|
||||
return False
|
||||
ok = True
|
||||
for g in globs:
|
||||
if g.count('{') != g.count('}') or g.count('[') != g.count(']'):
|
||||
if not _balanced(g):
|
||||
fail(f"applyTo glob '{g}' has unbalanced braces or brackets — it matches nothing, so the rule never fires — {fname}")
|
||||
ok = False
|
||||
return ok
|
||||
@@ -850,7 +916,7 @@ def audit_prompt():
|
||||
for m in INPUT_REF_RE.finditer(body):
|
||||
if m.group(1) not in used:
|
||||
used.append(m.group(1))
|
||||
if used and not declared:
|
||||
if used and fm.get('input') is None:
|
||||
fail(f"body uses {', '.join('${input:' + u + '}' for u in used)} but no input: is declared — apm rewrites references only when input: names them, so Claude receives the literal text — {fname}")
|
||||
else:
|
||||
for u in used:
|
||||
|
||||
@@ -133,7 +133,8 @@ the target:
|
||||
hook mode the target is a *.json file directly under a hooks/
|
||||
directory (.apm/hooks, or a hooks/ at a package root: beside
|
||||
apm.yml or a plugin.json manifest; any other hooks/
|
||||
directory is apm's deployed output and FAILs).
|
||||
directory is deployed output or no package at all, and
|
||||
FAILs at exit 1).
|
||||
instruction mode the target is a *.instructions.md file.
|
||||
prompt mode the target is a *.prompt.md file.
|
||||
|
||||
@@ -160,7 +161,8 @@ Exit codes:
|
||||
target does not exist, an unrecognized file extension, a missing
|
||||
references/agent-field-inventory.md, a missing or unreadable lib-*.sh
|
||||
beside this script, or, for a hook, instruction or prompt, a missing
|
||||
python3 or PyYAML)
|
||||
python3 or PyYAML, or a crash inside the hook, instruction or prompt
|
||||
checks)
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ suite must mean a differently named script.
|
||||
Each entry point decides for itself what it was handed. ADR-0025 states the
|
||||
skill and agent rule: a directory containing `SKILL.md` takes the skill flow; an
|
||||
`.agent.md` file, or a file under a directory named `agents/`, takes the agent
|
||||
flow. `scripts/validate.sh` adds three primitive shapes: a `*.instructions.md`
|
||||
flow. `scripts/validate.sh` adds the hook, instruction and prompt shapes: a `*.instructions.md`
|
||||
or `*.prompt.md` file takes the instruction or prompt flow wherever it sits, and
|
||||
a `.json` file directly under a `hooks/` directory takes the hook flow. Any
|
||||
shape outside the five is rejected rather than guessed at. Classification could
|
||||
@@ -66,17 +66,17 @@ not be wrong before the merge — each script was hard-wired to one artifact typ
|
||||
— so it is asserted from every side rather than in one place:
|
||||
|
||||
- the skill-side suites pin the skill-directory classification and the
|
||||
neither-shape rejection,
|
||||
no-shape rejection,
|
||||
- the agent-side suites pin the two agent rules *separately* — `.agent.md` in a
|
||||
directory that is not `agents/`, and a plain `.md` under `.apm/agents/` — so
|
||||
that a detector implementing only one of them cannot pass both. Plus a control
|
||||
asserting an agent file never picks up a skill-only gate.
|
||||
- `validate-primitive.bats` pins the hook, instruction and prompt shapes,
|
||||
including the precedence that makes a `*.instructions.md` or `*.prompt.md`
|
||||
under `agents/` take the primitive flow rather than the agent flow, a hook
|
||||
under `agents/` take the instruction or prompt flow rather than the agent flow, a hook
|
||||
file under a package-root `hooks/`, and a `.json` outside `hooks/` matching
|
||||
no shape. It also pins the primitive exit tiers: every negative case asserts
|
||||
exit 1 (`assert_failure 1`), and a missing python3 or PyYAML asserts exit 2.
|
||||
no shape. It also pins their exit tiers: every negative case asserts
|
||||
exit 1 (`assert_failure 1`), and a missing python3 or PyYAML, or a crash inside the checks, asserts exit 2.
|
||||
|
||||
Both skill-side suites additionally pin the `SKILL.md` **file** path, not just
|
||||
the directory: a pre-commit `files:` hook matches files, so every hook-driven
|
||||
|
||||
@@ -535,6 +535,150 @@ teardown() {
|
||||
refute_output --partial "FAIL"
|
||||
}
|
||||
|
||||
@test "hook: an unbraced plugin-root token is a FAIL — apm rewrites only \${TOKEN}/<path>" {
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"\"$PLUGIN_ROOT/scripts/missing.sh\"","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "unbraced \$PLUGIN_ROOT"
|
||||
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"bash $CLAUDE_PLUGIN_ROOT/scripts/x.sh","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "unbraced \$CLAUDE_PLUGIN_ROOT"
|
||||
}
|
||||
|
||||
@test "hook: a braced plugin-root token not followed directly by a path separator is a FAIL" {
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"cd ${PLUGIN_ROOT} && node index.js","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "\${PLUGIN_ROOT} is not followed directly by / or \\"
|
||||
|
||||
# The split-quote form keeps its own, more specific FAIL and is not double-reported.
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"\"${PLUGIN_ROOT}\"/.apm/hooks/scripts/check.sh","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "splits the quote"
|
||||
refute_output --partial "is not followed directly by"
|
||||
}
|
||||
|
||||
@test "hook: a script run as the first token of a -c command string must be executable" {
|
||||
chmod -x "$PKG/.apm/hooks/scripts/check.sh"
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"bash -c \"${PLUGIN_ROOT}/.apm/hooks/scripts/check.sh\"","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "is run directly but is not executable"
|
||||
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"sh -xc ./scripts/check.sh","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "is run directly but is not executable"
|
||||
|
||||
# Through an interpreter inside the command string, the exec bit is not needed.
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"bash -c \"bash ${PLUGIN_ROOT}/.apm/hooks/scripts/check.sh\"","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_success
|
||||
refute_output --partial "FAIL"
|
||||
}
|
||||
|
||||
@test "hook: env options and NAME=value assignments are skipped to reach the interpreter's script" {
|
||||
local cmd
|
||||
for cmd in 'env FOO=1 bash scripts/check.sh' 'env -i FOO=1 bash scripts/check.sh' 'env -u HOME bash scripts/check.sh' 'FOO=1 bash scripts/check.sh'; do
|
||||
write_hook hooks.json "{\"hooks\":{\"Stop\":[{\"hooks\":[{\"type\":\"command\",\"command\":\"$cmd\",\"timeout\":5}]}]}}"
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "script 'scripts/check.sh' is a bare relative path"
|
||||
done
|
||||
}
|
||||
|
||||
@test "hook: targets: naming no recognised hook target is an INFO, not a silent skip" {
|
||||
printf 'name: test-package\nversion: 0.1.0\ntargets: [claude-code]\n' > "$PKG/apm.yml"
|
||||
write_hook hooks.json '{"hooks":{"stop":[{"hooks":[{"type":"command","command":"true","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_success
|
||||
assert_output --partial "INFO targets: in apm.yml names no hook target apm 0.28.0 recognises (claude-code)"
|
||||
}
|
||||
|
||||
@test "hook: malformed shapes are FAILs — top level, hooks value, entry and nested hooks" {
|
||||
write_hook hooks.json '[]'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "top level is not a JSON object"
|
||||
|
||||
write_hook hooks.json '{"hooks":[]}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "'hooks' is not an object"
|
||||
|
||||
write_hook hooks.json '{"hooks":{"Stop":["true"]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "event 'Stop' entry 0 is not an object"
|
||||
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":"true"}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "nested 'hooks' is not a list of objects"
|
||||
}
|
||||
|
||||
@test "hook: an empty event name is a FAIL" {
|
||||
write_hook hooks.json '{"hooks":{"":[{"hooks":[{"type":"command","command":"true","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "empty event name"
|
||||
}
|
||||
|
||||
@test "hook: a script path containing \$ or a backtick is a FAIL" {
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"${PLUGIN_ROOT}/scripts/$X.sh","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "contains '\$' or a backtick"
|
||||
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"${PLUGIN_ROOT}/scripts/`x`.sh","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "contains '\$' or a backtick"
|
||||
}
|
||||
|
||||
@test "hook: a lowercase event reaching an unlisted harness is judged after apm's rename" {
|
||||
printf 'name: test-package\nversion: 0.1.0\ntargets: [gemini]\n' > "$PKG/apm.yml"
|
||||
# Gemini renames preToolUse to BeforeTool: PascalCase after the rename, no finding.
|
||||
write_hook hooks.json '{"hooks":{"preToolUse":[{"matcher":"x","hooks":[{"type":"command","command":"true","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_success
|
||||
refute_output --partial "preToolUse"
|
||||
|
||||
# sessionStart is not in Gemini's map, so it reaches Gemini verbatim.
|
||||
write_hook hooks.json '{"hooks":{"sessionStart":[{"matcher":"x","hooks":[{"type":"command","command":"true","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_success
|
||||
assert_output --partial "SUGGESTION event 'sessionStart' reaches gemini verbatim"
|
||||
}
|
||||
|
||||
@test "hook: no apm.yml at the inferred .apm/ package root is an INFO" {
|
||||
rm "$PKG/apm.yml"
|
||||
write_hook hooks.json '{"hooks":{"Stop":[{"hooks":[{"type":"command","command":"true","timeout":5}]}]}}'
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_success
|
||||
assert_output --partial "INFO no apm.yml at the inferred package root"
|
||||
}
|
||||
|
||||
@test "hook, instruction, prompt: a file that is not valid UTF-8 is a FAIL" {
|
||||
printf '{"hooks":{"Stop":[]}}\xff\n' > "$PKG/.apm/hooks/hooks.json"
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
assert_failure 1
|
||||
assert_output --partial "not valid UTF-8"
|
||||
|
||||
printf -- '---\ndescription: x\n---\n\nbody \xff\n' > "$PKG/.apm/instructions/x.instructions.md"
|
||||
run bash "$SCRIPT" "$PKG/.apm/instructions/x.instructions.md"
|
||||
assert_failure 1
|
||||
assert_output --partial "not valid UTF-8"
|
||||
|
||||
printf -- '---\ndescription: x\n---\n\nbody \xff\n' > "$PKG/.apm/prompts/x.prompt.md"
|
||||
run bash "$SCRIPT" "$PKG/.apm/prompts/x.prompt.md"
|
||||
assert_failure 1
|
||||
assert_output --partial "not valid UTF-8"
|
||||
}
|
||||
|
||||
@test "hook: an unedited primitive-author hook template is an unfilled-placeholder FAIL" {
|
||||
cp "$REPO_ROOT/plugins/kyberforge/.apm/skills/primitive-author/assets/templates/hook.json.template" "$PKG/.apm/hooks/hooks.json"
|
||||
run bash "$SCRIPT" "$PKG/.apm/hooks/hooks.json"
|
||||
@@ -656,6 +800,45 @@ applyTo: "**/*.py"' 'body'
|
||||
assert_output --partial "unfilled template placeholder 'FILL IN'"
|
||||
}
|
||||
|
||||
@test "instruction: no frontmatter block is a FAIL" {
|
||||
printf 'Just a body.\n' > "$PKG/.apm/instructions/x.instructions.md"
|
||||
run bash "$SCRIPT" "$PKG/.apm/instructions/x.instructions.md"
|
||||
assert_failure 1
|
||||
assert_output --partial "has no YAML frontmatter block"
|
||||
}
|
||||
|
||||
@test "instruction: an empty frontmatter block is read as empty, not as a missing block" {
|
||||
printf -- '---\n---\n\nbody\n' > "$PKG/.apm/instructions/x.instructions.md"
|
||||
run bash "$SCRIPT" "$PKG/.apm/instructions/x.instructions.md"
|
||||
assert_failure 1
|
||||
refute_output --partial "has no YAML frontmatter block"
|
||||
assert_output --partial "'description' is missing or empty"
|
||||
}
|
||||
|
||||
@test "instruction: frontmatter that is not a mapping is a FAIL" {
|
||||
write_instruction x '- a
|
||||
- b' 'body'
|
||||
run bash "$SCRIPT" "$PKG/.apm/instructions/x.instructions.md"
|
||||
assert_failure 1
|
||||
assert_output --partial "frontmatter is not a YAML mapping"
|
||||
}
|
||||
|
||||
@test "instruction: an applyTo that is neither a string nor a list is a FAIL" {
|
||||
write_instruction x 'description: x
|
||||
applyTo: 5' 'body'
|
||||
run bash "$SCRIPT" "$PKG/.apm/instructions/x.instructions.md"
|
||||
assert_failure 1
|
||||
assert_output --partial "applyTo is neither a string nor a list"
|
||||
}
|
||||
|
||||
@test "instruction: an applyTo glob closing a brace before opening it is unbalanced" {
|
||||
write_instruction x 'description: x
|
||||
applyTo: "src/}{.py"' 'body'
|
||||
run bash "$SCRIPT" "$PKG/.apm/instructions/x.instructions.md"
|
||||
assert_failure 1
|
||||
assert_output --partial "has unbalanced braces or brackets"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Prompts
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -684,6 +867,7 @@ input:
|
||||
description: The PR' 'Review ${input:pr_number}.'
|
||||
run bash "$SCRIPT" "$PKG/.apm/prompts/review-pr.prompt.md"
|
||||
assert_failure 1
|
||||
assert_output --partial "is one map with several keys — apm reads every key as an argument name"
|
||||
assert_output --partial "yields arguments [name, description]"
|
||||
}
|
||||
|
||||
@@ -809,6 +993,38 @@ $(printf 'line\n%.0s' $(seq 1 80))
|
||||
assert_output --partial "unfilled template placeholder 'FILL IN'"
|
||||
}
|
||||
|
||||
@test "prompt: body references with input: declared but every name invalid do not claim input: is absent" {
|
||||
write_prompt review-pr 'description: Review a PR.
|
||||
input:
|
||||
- 1pr: "The PR"' 'Review ${input:pr_number}.'
|
||||
run bash "$SCRIPT" "$PKG/.apm/prompts/review-pr.prompt.md"
|
||||
assert_failure 1
|
||||
refute_output --partial "no input: is declared"
|
||||
assert_output --partial "input: does not declare 'pr_number'"
|
||||
}
|
||||
|
||||
@test "prompt: a name that is not a safe path segment is a FAIL" {
|
||||
printf -- '---\ndescription: x\n---\n\nbody\n' > "$PKG/.apm/prompts/..prompt.md"
|
||||
run bash "$SCRIPT" "$PKG/.apm/prompts/..prompt.md"
|
||||
assert_failure 1
|
||||
assert_output --partial "is not a safe path segment"
|
||||
}
|
||||
|
||||
@test "prompt: an input entry that is not a string name, and an input of no known shape, are FAILs" {
|
||||
write_prompt review-pr 'description: Review a PR.
|
||||
input:
|
||||
- 5: "x"' 'Review.'
|
||||
run bash "$SCRIPT" "$PKG/.apm/prompts/review-pr.prompt.md"
|
||||
assert_failure 1
|
||||
assert_output --partial "input entry 5 is not a string name"
|
||||
|
||||
write_prompt review-pr 'description: Review a PR.
|
||||
input: 5' 'Review.'
|
||||
run bash "$SCRIPT" "$PKG/.apm/prompts/review-pr.prompt.md"
|
||||
assert_failure 1
|
||||
assert_output --partial "input is neither a name, a list nor a map"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Never ran (exit 2)
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -836,3 +1052,14 @@ $(printf 'line\n%.0s' $(seq 1 80))
|
||||
assert_equal "$status" 2
|
||||
assert_output --partial "PyYAML is required"
|
||||
}
|
||||
|
||||
@test "exit 2: a crash inside the checks is the never-ran tier, not a verdict" {
|
||||
write_prompt review-pr 'description: Review a PR.' 'Review the PR.'
|
||||
local crashyaml="$TMPDIR/crashyaml"
|
||||
mkdir -p "$crashyaml"
|
||||
# Importable, so the preflight passes; safe_load raises what no check expects.
|
||||
printf 'class YAMLError(Exception):\n pass\ndef safe_load(_):\n raise RuntimeError("boom")\n' > "$crashyaml/yaml.py"
|
||||
PYTHONPATH="$crashyaml" run bash "$SCRIPT" "$PKG/.apm/prompts/review-pr.prompt.md"
|
||||
assert_equal "$status" 2
|
||||
assert_output --partial "the prompt checks crashed (RuntimeError: boom)"
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
---
|
||||
name: forge
|
||||
description: >
|
||||
Use when the user wants something built or improved but has not yet named
|
||||
its type ("skill or plugin?"). If named, use instead: skill -> `skill-author`,
|
||||
agent -> `agent-author`, hook/instruction/prompt -> `primitive-author`,
|
||||
plugin -> `apm-workflow`.
|
||||
Use when the user wants to build or improve something of unnamed type ("where
|
||||
does this idea go?"). If named, use instead: skill -> `skill-author`, agent ->
|
||||
`agent-author`, apm hook/instruction/prompt -> `primitive-author`, plugin ->
|
||||
`apm-workflow`.
|
||||
metadata:
|
||||
version: "1.0.2"
|
||||
category: factory
|
||||
|
||||
@@ -15,15 +15,17 @@ removed per ADR-0015 once issue #90 landed, and `apm-workflow` is their sole suc
|
||||
## Always inline, never forked
|
||||
|
||||
Run these routes inline, in the current conversation. Their flows are short, prompt-heavy or
|
||||
gated — `apm publish` is not trivially reversible and removing a marketplace entry takes a
|
||||
conversational confirmation — and a backgrounded fork cannot surface those checkpoints to the
|
||||
user in real time.
|
||||
gated — editing a package's manifest metadata republishes its public `plugin.json` description,
|
||||
and removing a marketplace entry takes a conversational confirmation before `apm pack` changes the
|
||||
consumed catalog — and a backgrounded fork cannot surface those checkpoints to the user in real
|
||||
time.
|
||||
|
||||
## No clean-context recheck, and no automatic audit
|
||||
|
||||
Skill, agent and primitive routes close with a clean-context audit rerun; these two do not, and the omission
|
||||
is deliberate rather than an oversight. Neither artifact type has an audit skill counterpart to
|
||||
re-run, so detaching the route to earn a recheck it would never get buys nothing.
|
||||
Skill, agent, and hook, instruction or prompt routes close with a clean-context audit rerun; these
|
||||
two do not, and the omission is deliberate rather than an oversight. Neither artifact type has an
|
||||
audit skill counterpart to re-run, so detaching the route to earn a recheck it would never get buys
|
||||
nothing.
|
||||
|
||||
These routes get no automated terminal check either. `apm audit` is a separate action on
|
||||
`apm-workflow`'s own dispatch table, not a closing step of the configure or marketplace flow a
|
||||
|
||||
@@ -8,8 +8,8 @@ source_keys:
|
||||
Reached from `SKILL.md` Step 2 when the classified artifact is a skill, an agent/subagent
|
||||
definition, or a hook, instruction or prompt. Route a skill to `skill-author`, an agent to
|
||||
`agent-author`, and a hook, instruction or prompt to `primitive-author`. The branches differ on
|
||||
the author skill only — all verify the result with `factory-audit`, which detects the artifact type
|
||||
itself — and everything below applies to all of them.
|
||||
the author skill only — all verify the result with `factory-audit`, which detects the artifact
|
||||
type itself — and everything below applies to all of them.
|
||||
|
||||
## Choose fork or inline
|
||||
|
||||
@@ -27,12 +27,12 @@ Fall back to an **inline invocation** — same conversation, no subagent — whe
|
||||
## Two-tier verification
|
||||
|
||||
Every author skill already closes out with its own inline audit, in the same context as the
|
||||
authoring work: `skill-author`, `agent-author` and `primitive-author` each invoke `factory-audit` on what they wrote.
|
||||
That is tier one, and forge does not change it.
|
||||
authoring work: `skill-author`, `agent-author` and `primitive-author` each invoke `factory-audit`
|
||||
on what they wrote. That is tier one, and forge does not change it.
|
||||
|
||||
Tier two belongs to forge. Once the author skill's run has finished, spin up a separate
|
||||
**clean-context subagent** — fresh, not forked, no inherited context — to independently re-run the
|
||||
same audit skill against the finished artifact. This is a distinct verification layer, not a
|
||||
**clean-context subagent** — fresh, not forked, no inherited context — to independently re-run
|
||||
the same audit skill against the finished artifact. This is a distinct verification layer, not a
|
||||
duplicate: the inline audit shares context with the work it is checking and can share its blind
|
||||
spots, while the clean rerun has no stake in the result.
|
||||
|
||||
|
||||
@@ -25,9 +25,11 @@ Skip this step entirely if no ancestor `apm.yml` carries a `type:` field: the ar
|
||||
standalone or scoped to a user agent directory, and there is no package to version.
|
||||
|
||||
Skip the bump, and report that you skipped it, if the branch already moved this package's `version`
|
||||
for unreleased work: `git diff $(git merge-base HEAD main) -- <package>/apm.yml` shows a changed
|
||||
`version:` line. One bump covers all unreleased work on a branch — `primitive-author` skips on the
|
||||
same condition — so bumping again here double-counts it.
|
||||
for unreleased work: `git diff $(git merge-base HEAD origin/main) -- <package>/apm.yml` shows a
|
||||
changed `version:` line. Diff against the remote default branch, not a local `main` that may be
|
||||
stale; if it is not `main`, resolve it with `git symbolic-ref refs/remotes/origin/HEAD`. One bump
|
||||
covers all unreleased work on a branch — `agent-author` and `primitive-author` skip on the same
|
||||
condition — so bumping again here double-counts it.
|
||||
|
||||
## Delegate the bump
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
---
|
||||
name: primitive-author
|
||||
description: >
|
||||
Use when the user wants an apm hook, instruction or prompt file created, or
|
||||
audit findings or feedback applied to an existing one. Not read-only
|
||||
review -> factory-audit. Not skills -> skill-author. Not agents -> agent-author.
|
||||
Use when the user wants an apm hook, instruction or prompt created, or
|
||||
findings applied to one. Not read-only review -> factory-audit. Not skills
|
||||
-> skill-author. Not agents -> agent-author. Not apm.yml, targets or package
|
||||
config -> apm-workflow.
|
||||
allowed-tools: Bash Read Write Edit
|
||||
metadata:
|
||||
version: "0.1.0"
|
||||
@@ -25,9 +26,10 @@ metadata:
|
||||
|---|---|---|
|
||||
| A hook — `.apm/hooks/<name>.json`, or "run X whenever Y happens" | hook | `references/hook.md` |
|
||||
| An instruction — `.apm/instructions/<name>.instructions.md`, or a rule for files matching a pattern | instruction | `references/instruction.md` |
|
||||
| A prompt — `.apm/prompts/<name>.prompt.md`, or a reusable message the user types to kick off work | prompt | `references/prompt.md` |
|
||||
| A prompt — `.apm/prompts/<name>.prompt.md`, or a slash command steering existing skills | prompt | `references/prompt.md` |
|
||||
| Anything else (agent file, context/memory file) | none | stop; agents -> `agent-author`, otherwise name the unsupported type |
|
||||
|
||||
Read only the reference matching the resolved type — each is self-contained. If the target sits inside a git worktree, capture `rtk git log --oneline -1` before touching the filesystem; Step 4 needs it.
|
||||
Read only the matching reference. If the target sits inside a git worktree, capture `rtk git log --oneline -1` before touching the filesystem; Step 4 needs it.
|
||||
|
||||
## Step 2 — Boundary gate
|
||||
|
||||
@@ -45,7 +47,7 @@ Signals: grill output, `/factory-audit` findings, inline feedback, session conte
|
||||
|
||||
## Step 4 — Validate and close
|
||||
|
||||
1. Run `/factory-audit` on the file, inline in this context; resolve every FAIL before reporting done, including the `### Prose` FAILs Vale raises on an instruction or prompt body or description.
|
||||
2. Render it: in a fresh `mktemp -d` directory, run `rtk apm install <absolute path to the owning package> --target <its targets:, or all when it declares none>`, then read what each target received — `.claude/settings.json` and `.github/hooks/`, `.claude/rules/` and `.github/instructions/`, or `.claude/commands/` and `.github/prompts/`. A local path deploys the working tree; `--dry-run` renders nothing and a repo-root install resolves the remote's `main`.
|
||||
3. Bump the owning package's `apm.yml` `version:` — minor for a new hook, instruction or prompt, patch for a fix — unless this branch already bumped it for unreleased work. None of these is released on its own version — bump the package even if an instruction carries an optional `version:` key.
|
||||
1. Run `/factory-audit` on the file, inline in this context; resolve every FAIL before reporting done, including Vale's `### Prose` FAILs on an instruction or prompt.
|
||||
2. Render it: in a fresh `mktemp -d` directory, run `rtk apm install <absolute path to the owning package> --target <its targets: joined with commas, or all when it declares none>` (a repeated `--target` keeps only the last; Codex receives no prompts), then read what each target received — `.claude/settings.json` and `.github/hooks/`, `.claude/rules/` and `.github/instructions/`, or `.claude/commands/` and `.github/prompts/`. A local path deploys the working tree; `--dry-run` renders nothing and a repo-root install resolves the remote's `main`.
|
||||
3. Bump the owning package's `apm.yml` `version:` (minor for a new hook, instruction or prompt, patch for a fix; even if an instruction carries its own `version:` key) unless this branch already bumped it for unreleased work.
|
||||
4. **Commit verification.** Inside a git worktree, once the audit is clean, run `rtk git add` and `rtk git commit`, then confirm `rtk git log --oneline -1` changed from Step 1's hash: staged-but-uncommitted work is lost if the tree is cleaned up. Outside a worktree, report done on a clean audit and name that as the reason.
|
||||
@@ -68,7 +68,7 @@ Must:
|
||||
else fails the Copilot install outright. The file contributes at least one entry, and every
|
||||
entry carries at least one handler: an empty list or a handler-less entry deploys nothing, with
|
||||
only a warning.
|
||||
4. Every event is one each target the package deploys to fires, after apm's rename for that target
|
||||
4. Every event is one that each target the package deploys to fires, after apm's rename for that target
|
||||
(`_HOOK_EVENT_MAP`; no `targets:` means every target). Write Claude's PascalCase names
|
||||
(`PreToolUse`, `PostToolUse`, `UserPromptSubmit`, `SessionStart`, `Stop`, …), which apm renames
|
||||
for each target its map covers. A name the map does not cover deploys verbatim with no warning,
|
||||
@@ -84,10 +84,11 @@ Must:
|
||||
the path itself, and no space. When quoting, quote the whole token —
|
||||
`"${PLUGIN_ROOT}/scripts/my-hook.sh"`, never `"${PLUGIN_ROOT}"/scripts/x.sh`: apm rewrites
|
||||
`${PLUGIN_ROOT}` only when a path separator follows it directly, and only up to the next space
|
||||
or quote, so a split quote is left unrewritten and a spaced path is cut short. This is stricter
|
||||
than the research's Should, as with Must 6: either defect fails every time the hook fires. A
|
||||
missing script is only a warning at install time.
|
||||
6. A script run directly as the command's first token is executable. This is stricter than the
|
||||
or quote, so a split quote is left unrewritten and a spaced path is cut short. The quoting and
|
||||
space rules are stricter than the research's Should, as with Must 6: either defect fails every
|
||||
time the hook fires. A missing script is only a warning at install time.
|
||||
6. A script run directly as the command's first token, or as the first token of an interpreter's
|
||||
`-c` command string (`bash -c "${PLUGIN_ROOT}/x.sh"`), is executable. This is stricter than the
|
||||
research's Should: without it the hook fails every time it fires. A script passed to an
|
||||
interpreter (`bash ${PLUGIN_ROOT}/x.sh`) needs no executable bit.
|
||||
|
||||
@@ -105,5 +106,5 @@ Should:
|
||||
12. No filename that routes by target. Case-insensitively, apm routes a stem of exactly
|
||||
`hooks-<target>` and any stem ending `<target>-hooks` — bare (`claude-hooks`), prefixed
|
||||
(`x-claude-hooks`) or combined (`claude-codex-hooks`, the union). That routing is deprecated and
|
||||
reach belongs to `targets:` (see Gate); the research allows it only when deprecated routing is
|
||||
intended.
|
||||
reach belongs to `targets:` (see Gate). The research files this as a Must; it is a Should here
|
||||
because only the author can say deprecated routing is intended.
|
||||
@@ -15,13 +15,16 @@ An instruction is a scoped rule: it applies when the agent touches files matchin
|
||||
glob. On Claude it deploys to `.claude/rules/<stem>.md` with `applyTo` renamed to `paths:`.
|
||||
|
||||
- **A rule for this repo alone** → it belongs in the repo's AGENTS.md, which is the single
|
||||
always-on source. Stop and hand to `agentsmd-author`.
|
||||
always-on source. Stop and hand to `agentsmd-author`; if it is not installed, edit the repo's
|
||||
AGENTS.md directly.
|
||||
- **No file pattern fits** → an instruction without `applyTo` is always-on in every session of
|
||||
every repo that installs this package, and `apm compile` can fold it into the global sections of
|
||||
`AGENTS.md` and `CLAUDE.md` (CLAUDE.md is skipped when `.claude/rules/` is populated, AGENTS.md
|
||||
when `.github/instructions/` is, unless `--force-instructions`). Say exactly that to the user and continue only on an explicit yes.
|
||||
Legitimate when a package deliberately ships guidance to its consumers; never a default.
|
||||
- **Procedure the agent follows step by step** → a skill. Stop and hand to `skill-author`.
|
||||
- **Which harnesses receive it, or other package config** → set by the package `apm.yml`
|
||||
`targets:`, never by the instruction file. Stop and hand to `apm-workflow`.
|
||||
- **A rule scoped to a file pattern** → continue.
|
||||
|
||||
## Checklist
|
||||
|
||||
@@ -26,6 +26,8 @@ worse skill on every harness.
|
||||
`disable-model-invocation: true`: the prompt's body reaches the model, and the model cannot
|
||||
invoke a skill that sets it, so the steering would dead-end (the same check `factory-audit`'s
|
||||
prompt flow applies).
|
||||
- **Which harnesses receive it, or other package config** → set by the package `apm.yml`
|
||||
`targets:`, never by the prompt file. Stop and hand to `apm-workflow`.
|
||||
|
||||
## Description contract
|
||||
|
||||
@@ -36,7 +38,8 @@ trigger clause invites the router to pick the wrapper over the skills it wraps.
|
||||
|
||||
## Checklist
|
||||
|
||||
Copy `assets/templates/name.prompt.md.template` and drop `.template` only on the final path.
|
||||
Copy `assets/templates/name.prompt.md.template` and drop `.template` only on the final path. No
|
||||
parameters: delete `input:` and the `${input:…}` line.
|
||||
|
||||
Must:
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
## apm-cli-installed-source
|
||||
|
||||
- **URL:** file:///root/.local/pipx/venvs/apm-cli/lib/python3.11/site-packages/apm_cli/
|
||||
- **URL:** https://github.com/microsoft/apm/tree/v0.28.0/src/apm_cli/
|
||||
- **Note:** read locally from the pipx install at `~/.local/pipx/venvs/apm-cli/lib/python3.11/site-packages/apm_cli/`
|
||||
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md
|
||||
- **Description:** Installed apm-cli 0.28.0 source — ground truth for what apm deploys from a hook, instruction or prompt file and what it silently skips or only warns on; each Must/Should traces to the research docs' Authoring checklists or audit-only lists, or to ADR-0029, with tier moves annotated inline, and the `**/*.instructions.md` local-discovery glob behind the template-suffix Gotcha is `primitives/discovery.py` `LOCAL_PRIMITIVE_PATTERNS`; the per-target event rename maps are `integration/hook_integrator.py` `_HOOK_EVENT_MAP`; and Step 4.2's render relies on `apm install <local path>` deploying the working tree to every `--target`, verified against 0.28.0
|
||||
- **Contributing files:** SKILL.md, references/hook.md, references/instruction.md, references/prompt.md
|
||||
|
||||
@@ -57,6 +57,6 @@ Gates `/factory-audit` enforces in both flows:
|
||||
|
||||
Run `/factory-audit` on the resolved skill directory; resolve every FAIL before reporting done. It checks name-to-directory match, placeholders, both size budgets, boundary-target resolution and script hygiene — do not hand-check those. Hand-check the one thing it misses: an empty body reports `PASS SKILL.md body word count 0 (ADR-0020 target: 600)`, so confirm at least one non-empty section exists.
|
||||
|
||||
Versioning: on create, keep the scaffold's `0.1.0` — do not bump it (ADR-0022); on improve, bump the **patch** version.
|
||||
Versioning: on create, keep the scaffold's `0.1.0` — do not bump it (ADR-0022, Decision: `0.1.0` means "created and never yet revised"); on improve, bump the **patch** version.
|
||||
|
||||
**Commit verification.** Inside a git worktree: once the audit is clean, run `rtk git add` and `rtk git commit` — do not stop at staging. Re-run `rtk git log --oneline -1` and confirm the hash changed from Step 1's. A non-empty `git diff --stat` is not proof: staged-but-uncommitted work is part of no commit and is silently lost if the tree is cleaned up. Report done only once the hash has changed. Outside a worktree (a skill under `~/.claude/skills/`, say) nothing is committable — report done on a clean audit, naming that as the reason.
|
||||
@@ -1,6 +1,7 @@
|
||||
---
|
||||
source_keys:
|
||||
- agentskills-spec
|
||||
- apm-docs-llms-full
|
||||
---
|
||||
|
||||
# Deployment Modes
|
||||
@@ -11,7 +12,7 @@ Skills deploy standalone, or as part of an APM package (an `apm.yml`-governed `.
|
||||
|
||||
When a host installs a plugin, it copies the plugin directory to a cache. Only the plugin's own files are copied. **Any path that leaves the skill directory breaks post-install:**
|
||||
|
||||
```
|
||||
```text
|
||||
../other-skill/validate.sh # breaks
|
||||
plugins/<plugin>/.apm/skills/other/ # breaks
|
||||
../../shared/utils.sh # breaks
|
||||
@@ -23,7 +24,7 @@ Fix: duplicate the file into the skill's own `scripts/` or `assets/`. There is n
|
||||
|
||||
For a package (an `apm.yml`-governed `.apm/` source tree), the deployable artifact is generated by `apm compile` per target harness — not produced by copying the raw `.apm/` directory wholesale the way a plugin cache install copies a plugin directory. The same self-containment rule still applies at the skill level: **file references inside `.apm/skills/<name>/` must not reach outside that skill's own directory.**
|
||||
|
||||
```
|
||||
```text
|
||||
../other-skill/validate.sh # breaks
|
||||
.apm/skills/other-skill/ # breaks
|
||||
../../shared/utils.sh # breaks
|
||||
|
||||
@@ -7,6 +7,7 @@ source_keys:
|
||||
- agentskills-evaluating-skills
|
||||
- agentskills-using-scripts
|
||||
- agentskills-quickstart
|
||||
- apm-docs-llms-full
|
||||
---
|
||||
|
||||
# Sources
|
||||
@@ -68,3 +69,11 @@ source_keys:
|
||||
- **Description:** Step-by-step guide to creating a first skill (roll-dice example), how discovery/activation/execution work in practice
|
||||
- **Contributing files:** SKILL.md, references/create.md
|
||||
- **Status:** `extracted`
|
||||
|
||||
## apm-docs-llms-full
|
||||
|
||||
- **URL:** https://microsoft.github.io/apm/llms-full.txt
|
||||
- **Research doc:** plugins/kyberforge/docs/research/docs/microsoft-apm/sources.md
|
||||
- **Description:** Published apm docs bundle — `apm compile` producing per-target output from an `apm.yml` package, the target-neutral `${PLUGIN_ROOT}` hook token apm rewrites per target, and hooks as primitives under `.apm/hooks/`
|
||||
- **Contributing files:** references/deployment-modes.md
|
||||
- **Status:** `extracted`
|
||||
@@ -42,7 +42,8 @@ Output:
|
||||
Exit codes:
|
||||
0 Scaffold created, destination already complete (no-op), or a partial
|
||||
scaffold from an earlier failed run repaired
|
||||
1 Invalid arguments, missing path, or templates not found
|
||||
1 Invalid arguments, missing path, templates not found, name
|
||||
substitution failed, or the destination appeared mid-build
|
||||
EOF
|
||||
}
|
||||
|
||||
@@ -162,41 +163,60 @@ SUBST_MARKERS=("name: SKILL_NAME" "bats <destination-dir>/SKILL_NAME/tests/")
|
||||
# Replace SKILL_NAME in one file. `sed -i` is not portable — GNU takes an
|
||||
# optional attached suffix, BSD/macOS requires a separate suffix argument and
|
||||
# reads the expression as one — so write to a temp file and move it over.
|
||||
# The move runs only if sed succeeded: a failed sed leaves an empty or partial
|
||||
# temp file, and moving that over the original would destroy it.
|
||||
substitute_file() {
|
||||
local f="$1"
|
||||
sed "s/SKILL_NAME/$SKILL_NAME/g" "$f" > "$f.tmp"
|
||||
mv "$f.tmp" "$f"
|
||||
if sed "s/SKILL_NAME/$SKILL_NAME/g" "$f" > "$f.tmp" && mv "$f.tmp" "$f"; then
|
||||
return 0
|
||||
fi
|
||||
rm -f "$f.tmp"
|
||||
echo "Error: could not substitute the skill name in '$f'." >&2
|
||||
return 1
|
||||
}
|
||||
|
||||
# Substitute every placeholder file under dir $1 (a fresh template copy).
|
||||
substitute_name() {
|
||||
local dir="$1" rel
|
||||
for rel in "${SUBST_FILES[@]}"; do
|
||||
[[ -f "$dir/$rel" ]] && substitute_file "$dir/$rel"
|
||||
if [[ -f "$dir/$rel" ]]; then
|
||||
substitute_file "$dir/$rel" || return 1
|
||||
fi
|
||||
done
|
||||
return 0
|
||||
}
|
||||
|
||||
# Substitute only the placeholder files under dir $1 that still carry their
|
||||
# template marker line; print how many were repaired.
|
||||
# template marker line. Sets REPAIRED to how many were repaired; returns 1 on
|
||||
# the first failure. Called directly, never inside $(...): a command
|
||||
# substitution would swallow the failure and let the caller report success.
|
||||
REPAIRED=0
|
||||
repair_placeholders() {
|
||||
local dir="$1" i f n=0
|
||||
local dir="$1" i f
|
||||
REPAIRED=0
|
||||
for i in "${!SUBST_FILES[@]}"; do
|
||||
f="$dir/${SUBST_FILES[$i]}"
|
||||
if [[ -f "$f" ]] && grep -qxF "${SUBST_MARKERS[$i]}" "$f"; then
|
||||
substitute_file "$f"
|
||||
n=$((n + 1))
|
||||
substitute_file "$f" || return 1
|
||||
REPAIRED=$((REPAIRED + 1))
|
||||
fi
|
||||
done
|
||||
echo "$n"
|
||||
return 0
|
||||
}
|
||||
|
||||
if [[ -d "$TARGET" ]]; then
|
||||
# A scaffold left half-built by an earlier failed run still carries a
|
||||
# template marker line; finish it instead of reporting a silent no-op.
|
||||
# Anything else — including a complete skill — is left untouched.
|
||||
if [[ "$(repair_placeholders "$TARGET")" -gt 0 ]]; then
|
||||
echo "Repaired partial scaffold at '$TARGET' — substituted SKILL_NAME." >&2
|
||||
if ! repair_placeholders "$TARGET"; then
|
||||
echo "Error: repair of '$TARGET' failed; no file was left half-written." >&2
|
||||
exit 1
|
||||
fi
|
||||
if [[ "$REPAIRED" -gt 0 ]]; then
|
||||
# The marker line proves only that the name was never substituted, not
|
||||
# that the earlier copy finished — a file may still be missing.
|
||||
echo "Repaired partial scaffold at '$TARGET' — only the name placeholder (SKILL_NAME) was substituted." >&2
|
||||
echo "The earlier run may also have left files missing: run /factory-audit on it, or delete it and re-run this script." >&2
|
||||
exit 0
|
||||
fi
|
||||
echo "Scaffold already exists at '$TARGET' — nothing to do." >&2
|
||||
@@ -207,10 +227,23 @@ mkdir -p "$(dirname "$TARGET")"
|
||||
|
||||
# Build in a sibling staging directory and rename it into place only once
|
||||
# complete, so a failure mid-build never leaves a half-built $TARGET behind.
|
||||
STAGING="$TARGET.partial.$$"
|
||||
# The dot prefix matters: a SIGKILL skips the trap, and a leftover must not
|
||||
# look like a skill to anything scanning .apm/skills/.
|
||||
STAGING="$(mktemp -d "$(dirname "$TARGET")/.new-skill.XXXXXX")"
|
||||
trap 'rm -rf "$STAGING"' EXIT
|
||||
cp -r "$TEMPLATES_DIR" "$STAGING"
|
||||
# mktemp creates the directory 0700; give the skill the umask default instead.
|
||||
chmod "$(umask -S)" "$STAGING"
|
||||
cp -R "$TEMPLATES_DIR/." "$STAGING"
|
||||
substitute_name "$STAGING"
|
||||
|
||||
# $TARGET may have appeared since the check above (a concurrent run). `mv`
|
||||
# onto an existing directory nests the source inside it instead of failing,
|
||||
# and GNU `mv -T` is not portable, so re-check immediately before the rename.
|
||||
# This narrows the window to the gap between two syscalls; it does not close it.
|
||||
if [[ -e "$TARGET" ]]; then
|
||||
echo "Error: '$TARGET' appeared while the scaffold was being built; left it untouched." >&2
|
||||
exit 1
|
||||
fi
|
||||
mv "$STAGING" "$TARGET"
|
||||
trap - EXIT
|
||||
|
||||
|
||||
@@ -113,9 +113,90 @@ teardown() {
|
||||
assert_failure
|
||||
}
|
||||
|
||||
# Lists every entry in $1 other than my-tool and the fixture copies, so a
|
||||
# staging directory of any name (dotted or not) left behind is caught.
|
||||
leftovers() {
|
||||
local entry name
|
||||
for entry in "$1"/* "$1"/.[!.]* "$1"/..?*; do
|
||||
[[ -e "$entry" ]] || continue
|
||||
name=${entry##*/}
|
||||
case "$name" in my-tool|bin|skill.orig) ;; *) printf '%s\n' "$name" ;; esac
|
||||
done
|
||||
}
|
||||
|
||||
# Puts a `sed` on PATH that fails without writing output, so a test can
|
||||
# inject a failure into the substitution step.
|
||||
stub_failing_sed() {
|
||||
mkdir -p "$DEST/bin"
|
||||
printf '#!/usr/bin/env bash\nexit 1\n' > "$DEST/bin/sed"
|
||||
chmod +x "$DEST/bin/sed"
|
||||
}
|
||||
|
||||
@test "leaves no staging directory behind after a successful run" {
|
||||
bash "$SCRIPT" my-tool "$DEST"
|
||||
run bash -c "ls -d '$DEST'/my-tool.partial.* 2>/dev/null"
|
||||
run leftovers "$DEST"
|
||||
assert_output ""
|
||||
}
|
||||
|
||||
@test "stages the build in a dot-prefixed directory that cannot pass for a skill" {
|
||||
# A SIGKILL skips the cleanup trap, so the staging directory's name is what
|
||||
# keeps a leftover from looking like a skill under .apm/skills/.
|
||||
mkdir -p "$DEST/bin"
|
||||
real_sed="$(command -v sed)"
|
||||
printf '#!/usr/bin/env bash\nprintf "%%s\\n" "${@: -1}" >> "%s/sed.log"\nexec "%s" "$@"\n' \
|
||||
"$DEST/bin" "$real_sed" > "$DEST/bin/sed"
|
||||
chmod +x "$DEST/bin/sed"
|
||||
PATH="$DEST/bin:$PATH" run bash "$SCRIPT" my-tool "$DEST"
|
||||
assert_success
|
||||
run grep -c . "$DEST/bin/sed.log"
|
||||
refute_output "0"
|
||||
run grep -vE "^$DEST/\.[^/]+/" "$DEST/bin/sed.log"
|
||||
assert_output ""
|
||||
}
|
||||
|
||||
@test "scaffold directory gets umask-default permissions, not mktemp's 0700" {
|
||||
bash "$SCRIPT" my-tool "$DEST"
|
||||
mkdir "$DEST/reference-dir"
|
||||
assert_equal "$(ls -ld "$DEST/my-tool" | cut -c1-10)" \
|
||||
"$(ls -ld "$DEST/reference-dir" | cut -c1-10)"
|
||||
rmdir "$DEST/reference-dir"
|
||||
}
|
||||
|
||||
@test "fresh scaffold: a failing sed aborts non-zero with no target and no staging left" {
|
||||
stub_failing_sed
|
||||
PATH="$DEST/bin:$PATH" run bash "$SCRIPT" my-tool "$DEST"
|
||||
assert_failure
|
||||
assert [ ! -e "$DEST/my-tool" ]
|
||||
run leftovers "$DEST"
|
||||
assert_output ""
|
||||
}
|
||||
|
||||
@test "repair: a failing sed aborts non-zero and leaves the original file unchanged" {
|
||||
cp -r "$BATS_TEST_DIRNAME/../assets/templates" "$DEST/my-tool"
|
||||
cp "$DEST/my-tool/SKILL.md" "$DEST/skill.orig"
|
||||
stub_failing_sed
|
||||
PATH="$DEST/bin:$PATH" run bash "$SCRIPT" my-tool "$DEST"
|
||||
assert_failure
|
||||
refute_output --partial "Repaired"
|
||||
run cmp "$DEST/skill.orig" "$DEST/my-tool/SKILL.md"
|
||||
assert_success
|
||||
run find "$DEST/my-tool" -name '*.tmp'
|
||||
assert_output ""
|
||||
}
|
||||
|
||||
@test "a target that appears after the existence check is not nested into" {
|
||||
# A sed wrapper creates the target mid-build, standing in for a concurrent
|
||||
# run winning the race between the check and the final rename.
|
||||
mkdir -p "$DEST/bin"
|
||||
real_sed="$(command -v sed)"
|
||||
printf '#!/usr/bin/env bash\nmkdir -p "%s/my-tool"\nexec "%s" "$@"\n' \
|
||||
"$DEST" "$real_sed" > "$DEST/bin/sed"
|
||||
chmod +x "$DEST/bin/sed"
|
||||
PATH="$DEST/bin:$PATH" run bash "$SCRIPT" my-tool "$DEST"
|
||||
assert_failure
|
||||
run ls -A "$DEST/my-tool"
|
||||
assert_output ""
|
||||
run leftovers "$DEST"
|
||||
assert_output ""
|
||||
}
|
||||
|
||||
@@ -126,6 +207,7 @@ teardown() {
|
||||
run bash "$SCRIPT" my-tool "$DEST"
|
||||
assert_success
|
||||
assert_output --partial "Repaired partial scaffold"
|
||||
assert_output --partial "only the name placeholder"
|
||||
run grep -r "SKILL_NAME" "$DEST/my-tool"
|
||||
assert_failure
|
||||
run grep -E '^name: my-tool$' "$DEST/my-tool/SKILL.md"
|
||||
|
||||
@@ -33,7 +33,7 @@ Authoring source lives in `.apm/`; it is the only content source and the only th
|
||||
| Agents | `.apm/agents/*.agent.md` | Role-based agents; one vendor-neutral `.agent.md` per agent (ADR-0016) |
|
||||
| Hooks | `.apm/hooks/` | Event-triggered automation — authored for Claude Code, see below |
|
||||
|
||||
**Hooks are authored for Claude Code, but apm writes them for every package target.** apm merges `.apm/hooks/*.json` into the consuming project's `.claude/settings.json` at install. Because kyberforge also targets Copilot and Codex, apm writes the same hook to `.github/hooks/kyberforge-hooks.json` (nested shape passed through, not reshaped) and into `.codex/hooks.json` when `.codex/` exists. Whether those harnesses execute it is unverified; if they do, it exits immediately, because the script exits 0 unless `CLAUDE_PROJECT_DIR`, which Claude Code exports for SessionStart hooks, is set. Details are in `docs/hooks.md` and ADR-0019's 2026-09-28 amendment and correction.
|
||||
**Hooks are authored for Claude Code, but apm writes them for every package target.** apm merges `.apm/hooks/*.json` into the consuming project's `.claude/settings.json` at install. Because kyberforge also targets Copilot and Codex, apm writes the same hook to `.github/hooks/kyberforge-hooks.json` (nested shape passed through, not reshaped) and into `.codex/hooks.json` when `.codex/` exists. Whether those harnesses execute it is unverified; if they do, it exits immediately, because the script exits 0 unless `CLAUDE_PROJECT_DIR` is set, and of the three only Claude Code documents exporting it for SessionStart hooks (unless the variable is inherited from the user's environment). Details are in `docs/hooks.md` and ADR-0019's 2026-09-28 amendment and correction.
|
||||
|
||||
## Skills
|
||||
|
||||
|
||||
@@ -9,9 +9,10 @@ Author hooks in `plugins/kyberforge/.apm/hooks/*.json`. `.apm/` is the only cont
|
||||
`apm install` is the only supported install path (ADR-0024) — there is no generated mirror at the
|
||||
plugin root and no per-plugin `plugin.json`, so `.apm/hooks/` is both where you edit and what ships.
|
||||
|
||||
apm merges every `*.json` in that directory into a single hook definition and writes the event
|
||||
bindings into the consuming project's `.claude/settings.json`; see "Deployed shape" below. Scripts a
|
||||
hook invokes live in the same directory, alongside the JSON that references them.
|
||||
For Claude, apm merges the event bindings from every `*.json` in that directory into the consuming
|
||||
project's `.claude/settings.json`; see "Deployed shape" below. That merge is Claude's rendering, not
|
||||
a general rule: Copilot gets one file per source file (see "GitHub Copilot CLI and Codex"). Scripts
|
||||
a hook invokes live in the same directory, alongside the JSON that references them.
|
||||
|
||||
## Hook file structure
|
||||
|
||||
@@ -32,14 +33,12 @@ The shape Claude Code reads, and therefore the shape to author under `.apm/hooks
|
||||
}
|
||||
```
|
||||
|
||||
Events (**partial list**): `PreToolUse`, `PostToolUse`, `Notification`, `Stop`, and `SessionStart`
|
||||
(verified end-to-end by the hook below). Claude Code's plugin hook set is larger — `SessionEnd`,
|
||||
`UserPromptSubmit`, `PreCompact` and `SubagentStop` also exist — and this repo's vendored corpus does
|
||||
not enumerate it anywhere: `docs/research/docs/claude-code-plugins/configuration.md:100` describes
|
||||
the file as "Event handlers (PreToolUse, PostToolUse, etc.)", and `agent-definition.md:53` covers
|
||||
only the per-agent `hooks` field, not the plugin-level set. Treat the five names above as the ones
|
||||
this repo has verified, not as the schema. Check Claude Code's own hooks documentation before wiring
|
||||
an event not listed here.
|
||||
Events: see `plugins/kyberforge/docs/research/docs/microsoft-apm/hooks-primitive-schema.md`,
|
||||
section "Events: `_HOOK_EVENT_MAP`", for which names apm renames per target and which it passes
|
||||
through unchanged. For Claude, author every event in PascalCase (`SessionStart`, `UserPromptSubmit`,
|
||||
`PreCompact`, and so on). A camelCase name apm does not map, such as `userPromptSubmit`, draws only
|
||||
a non-fatal warning and never fires; an all-lowercase one draws no warning at all and never fires
|
||||
either.
|
||||
|
||||
## Referencing a script — use the `.apm/` path
|
||||
|
||||
@@ -85,7 +84,9 @@ mechanic. See ADR-0019, correction 2026-09-19, and the comment above `executable
|
||||
|
||||
`check-apm-current.sh` keeps an apm-consumed install level with its remote: it runs `apm outdated`,
|
||||
and if anything is behind, runs `apm update --yes` and returns `reloadSkills: true` so the running
|
||||
session picks up the redeployed content. Rationale, measurements, and the failure modes are in
|
||||
session picks up the redeployed content. `reloadSkills` is a documented `SessionStart`
|
||||
`hookSpecificOutput` field that makes Claude Code re-scan skill directories once the hooks finish
|
||||
(code.claude.com/docs/en/hooks, checked 2026-09-29). Rationale, measurements, and the failure modes are in
|
||||
ADR-0019.
|
||||
|
||||
**Claude Code only, and where it looks for the lockfile.** The hook exits 0 at once, silently and
|
||||
@@ -101,12 +102,26 @@ host that sets no `CLAUDE_PROJECT_DIR` the lockfile guard passes in every apm co
|
||||
fallback ran `apm update --yes` there (ADR-0019, correction 2026-09-28).
|
||||
|
||||
**The `timeout` in `hooks.json` must exceed the script's own budget.** The script spends at most
|
||||
`timeout 60 apm outdated` plus `timeout 300 apm update`; the hook entry declares `timeout: 380`, the
|
||||
sum plus a buffer. Set it lower and a slow remote gets the hook SIGKILLed mid-`apm update`, leaving a
|
||||
`timeout -k 5 60 apm outdated` plus `timeout -k 5 300 apm update`, 370 s counting each 5 s SIGKILL
|
||||
grace; the hook entry declares `timeout: 380`, the sum plus a buffer. Set it lower and a slow remote gets the hook SIGKILLed mid-`apm update`, leaving a
|
||||
partially redeployed `.claude/skills/` and emitting no notice — precisely the silent failure the hook
|
||||
exists to prevent. `tests/test-apm-current-hook.sh` pins the relationship (host timeout > sum of the
|
||||
script's internal timeouts) rather than the literal, so raising either side alone fails the suite.
|
||||
|
||||
**The time limits are portable and hard to escape (ADR-0019, amendment 2026-09-29).** The script
|
||||
uses `timeout`, or `gtimeout` where only Homebrew coreutils provides it (stock macOS). With neither,
|
||||
it emits a notice and exits without running `apm`, instead of dying silently on exit 127. It exports
|
||||
`GIT_TERMINAL_PROMPT=0`, so a remote that wants credentials fails at once instead of waiting out the
|
||||
timeout on a prompt nobody can see. Where `flock` exists and `apm_modules/` does too, `apm update`
|
||||
runs under a non-blocking lock on `apm_modules/.kyberforge-apm-update.lock`. A second session that
|
||||
starts during a refresh skips its own and says so. Without `flock` the refresh runs unserialised.
|
||||
|
||||
**The lock advice is neutral when the default branch is unknown.** The notice tells you to discard
|
||||
the rewritten `apm.lock.yaml` on a feature branch and to decide deliberately on the default branch.
|
||||
It learns the default from `refs/remotes/origin/HEAD`, which `git remote add` never writes. When
|
||||
that ref is unset, on a detached HEAD, or outside a git checkout, it says only "commit it or
|
||||
discard it deliberately" rather than guessing `main` (ADR-0019, amendment 2026-09-19).
|
||||
|
||||
**Staleness is detected by matching apm's summary line, and both spellings count.** `apm outdated`
|
||||
has no `--json` or otherwise machine-readable output (verified against apm 0.28.0), so the hook
|
||||
greps its text. apm prints `1 outdated dependency found` in the singular when exactly one package is
|
||||
|
||||
@@ -4,7 +4,7 @@ source_keys:
|
||||
- apm-cli-installed-source
|
||||
- apm-docs-llms-full
|
||||
- apm-github-repo
|
||||
- context7-microsoft-apm
|
||||
- context7-microsoft-apm # partial: earlier pass only; the 2026-09-28 re-verification could not reach Context7 (see sources.md)
|
||||
---
|
||||
|
||||
Ground truth for this file is the installed apm-cli **0.28.0** source (`apm_cli/integration/hook_integrator.py`, `hook_native_formats.py`, `hook_ir.py`, `hook_file_routing.py`, `_hook_dropped_targets.py`, `targets.py`, `security/executables.py`) plus a live `apm install` of a scratch package targeting `claude` and `copilot` (2026-09-28). Where the published docs (`llms-full.txt`) disagree with 0.28.0, the disagreement is called out; the published docs track upstream `main` and may describe a newer release.
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@ source_keys:
|
||||
- apm-cli-installed-source
|
||||
- apm-docs-llms-full
|
||||
- apm-github-repo
|
||||
- context7-microsoft-apm
|
||||
- context7-microsoft-apm # partial: earlier pass only; the 2026-09-28 re-verification could not reach Context7 (see sources.md)
|
||||
---
|
||||
|
||||
This file is checked against the installed apm-cli **0.28.0** source (`primitives/models.py`, `primitives/parser.py`, `primitives/discovery.py`, `utils/patterns.py`, `integration/instruction_integrator.py`, `integration/base_integrator.py`, `integration/targets.py`, `compilation/agents_compiler.py`, `commands/compile/cli.py`) and against a live `apm install` / `apm compile` of a scratch package (2026-09-28).
|
||||
|
||||
@@ -4,7 +4,7 @@ source_keys:
|
||||
- apm-cli-installed-source
|
||||
- apm-docs-llms-full
|
||||
- apm-github-repo
|
||||
- context7-microsoft-apm
|
||||
- context7-microsoft-apm # partial: earlier pass only; the 2026-09-28 re-verification could not reach Context7 (see sources.md)
|
||||
---
|
||||
|
||||
Checked against the installed apm-cli **0.28.0** source (`integration/prompt_integrator.py`, `integration/command_integrator.py`, `integration/base_integrator.py`, `integration/targets.py`, `security/gate.py`) and a live `apm install` of a scratch package targeting `claude` and `copilot` (2026-09-28).
|
||||
|
||||
@@ -16,7 +16,8 @@
|
||||
|
||||
## apm-cli-installed-source
|
||||
|
||||
- **URL:** file:///root/.local/pipx/venvs/apm-cli/lib/python3.11/site-packages/apm_cli/
|
||||
- **URL:** https://github.com/microsoft/apm/tree/v0.28.0/src/apm_cli/
|
||||
- **Local copy read:** the installed package at `~/.local/pipx/venvs/apm-cli/lib/python3.11/site-packages/apm_cli/` (pipx, apm-cli 0.28.0), which is what was actually read; the URL above is the matching upstream tag, for readers without that install.
|
||||
- **Description:** Installed apm-cli 0.28.0 package source, which is the version this repo runs. Read as ground truth for the hooks, instructions and prompts docs, including `integration/hook_integrator.py`, `hook_native_formats.py`, `hook_ir.py`, `hook_file_routing.py`, `instruction_integrator.py`, `command_integrator.py`, `prompt_integrator.py`, `targets.py`, `primitives/`, `utils/patterns.py`, `compilation/agents_compiler.py`, `commands/compile/cli.py` and `security/executables.py`. Cross-checked by live `apm install` / `apm compile` runs of a throwaway package (claude and copilot targets) in a scratch dir on 2026-09-28.
|
||||
- **Contributing files:** hooks-primitive-schema.md, instructions-primitive-schema.md, prompt-primitive-schema.md
|
||||
- **Status:** `extracted`
|
||||
@@ -28,6 +29,6 @@
|
||||
- **Contributing files:** hooks-primitive-schema.md, instructions-primitive-schema.md, prompt-primitive-schema.md
|
||||
- **Status:** `extracted`
|
||||
|
||||
Note (2026-09-28): during the verification pass for the hooks, instructions and prompts docs, the Context7 `/microsoft/apm` endpoint returned an invalid-API-key error. Those three files were re-verified against `apm-cli-installed-source` and `apm-docs-llms-full` only. Their `context7-microsoft-apm` key reflects the earlier pass.
|
||||
Note (2026-09-28): during the verification pass for the hooks, instructions and prompts docs, the Context7 `/microsoft/apm` endpoint returned an invalid-API-key error. Those three files were re-verified against `apm-cli-installed-source` and `apm-docs-llms-full` only. Their `context7-microsoft-apm` key reflects the earlier pass, and each of the three carries a note saying so next to the key.
|
||||
|
||||
Note: `releasing.md`'s `--check-clean`/`--check-versions` scope, `apm pack` exit-code semantics, and the `.apm/`-vs-root-flat-dir mutual exclusivity referenced there were additionally cross-checked directly against `apm_cli/bundle/plugin_exporter.py`, `apm_cli/commands/pack.py`, and `apm_cli/marketplace/drift_check.py` in the installed `apm-cli` 0.28.0 package (`/root/.local/pipx/venvs/apm-cli/`), not just Context7 doc snippets — confirmed by a live `apm pack --format plugin` run inside `plugins/bin` that reproduced the documented `[!] Skipping root-level skills/ because .apm/ is present` warning.
|
||||
+158
-12
@@ -36,6 +36,7 @@ make_apm() {
|
||||
cat > "$FAKE_BIN/apm" << EOF
|
||||
#!/usr/bin/env bash
|
||||
pwd > "$WORK/apm-cwd"
|
||||
echo "\${GIT_TERMINAL_PROMPT-unset}" > "$WORK/gtp-\$1"
|
||||
case "\$1" in
|
||||
outdated) echo "$outdated_line"; exit 0 ;;
|
||||
update) touch "$WORK/update-was-called"; exit $update_exit ;;
|
||||
@@ -297,14 +298,147 @@ out="$(run_hook_in "$WORK" "")"; rc=$?
|
||||
|
||||
rm -f "$WORK/update-was-called" "$WORK/apm-cwd"
|
||||
out="$(run_hook_in "$ELSEWHERE" "$ELSEWHERE")"; rc=$?
|
||||
[[ $rc -eq 0 ]] && pass "exits 0 when neither the project dir nor the cwd has a lockfile" \
|
||||
|| fail "should exit 0 when there is no lockfile anywhere"
|
||||
[[ -z "$out" ]] && pass "stays silent when neither the project dir nor the cwd has a lockfile" \
|
||||
|| fail "should stay silent when there is no lockfile anywhere"
|
||||
[[ $rc -eq 0 ]] && pass "exits 0 when the project dir has no lockfile" \
|
||||
|| fail "should exit 0 when the project dir has no lockfile"
|
||||
[[ -z "$out" ]] && pass "stays silent when the project dir has no lockfile" \
|
||||
|| fail "should stay silent when the project dir has no lockfile"
|
||||
[[ ! -f "$WORK/update-was-called" ]] \
|
||||
&& pass "does not run apm update when there is no lockfile anywhere" \
|
||||
&& pass "does not run apm update when the project dir has no lockfile" \
|
||||
|| fail "must not touch a project that does not use apm"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "--- git never prompts ---"
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# A remote that wants credentials must fail fast inside apm's git calls, not
|
||||
# block on a terminal prompt until the timeout fires. Cleared on the way in so
|
||||
# the assertion cannot pass on an inherited value.
|
||||
make_apm "[!] 6 outdated dependencies found" 0
|
||||
rm -f "$WORK/gtp-outdated" "$WORK/gtp-update"
|
||||
(cd "$WORK" && env -u GIT_TERMINAL_PROMPT CLAUDE_PROJECT_DIR="$WORK" PATH="$FAKE_BIN:$PATH" bash "$HOOK" > /dev/null 2>&1)
|
||||
[[ "$(cat "$WORK/gtp-outdated" 2>/dev/null)" == "0" ]] \
|
||||
&& pass "apm outdated runs with GIT_TERMINAL_PROMPT=0" \
|
||||
|| fail "apm outdated saw GIT_TERMINAL_PROMPT='$(cat "$WORK/gtp-outdated" 2>/dev/null)' — must be 0"
|
||||
[[ "$(cat "$WORK/gtp-update" 2>/dev/null)" == "0" ]] \
|
||||
&& pass "apm update runs with GIT_TERMINAL_PROMPT=0" \
|
||||
|| fail "apm update saw GIT_TERMINAL_PROMPT='$(cat "$WORK/gtp-update" 2>/dev/null)' — must be 0"
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "--- timeout(1) resolution ---"
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
# Stock macOS has no timeout(1); Homebrew coreutils ships it as gtimeout. A PATH
|
||||
# that holds only what the hook and the mock need — and no timeout — stands in
|
||||
# for that host. bash is invoked by absolute path; `env` and `bash` are still
|
||||
# linked in because the mock's shebang resolves them through PATH.
|
||||
REAL_TIMEOUT="$(command -v timeout || true)"
|
||||
BASH_BIN="$(command -v bash)"
|
||||
SANDBOX_BIN="$(mktemp -d)"
|
||||
GT_BIN="$(mktemp -d)"
|
||||
trap 'rm -rf "$FAKE_BIN" "$WORK" "$SANDBOX_BIN" "$GT_BIN" "${PROBE:-}"' EXIT
|
||||
for tool in bash env grep touch git; do
|
||||
src="$(command -v "$tool" || true)"
|
||||
[[ -n "$src" ]] && ln -s "$src" "$SANDBOX_BIN/$tool"
|
||||
done
|
||||
|
||||
make_apm "[!] 6 outdated dependencies found" 0
|
||||
rm -f "$WORK/update-was-called" "$WORK/apm-cwd"
|
||||
out="$( (cd "$WORK" && env CLAUDE_PROJECT_DIR="$WORK" PATH="$FAKE_BIN:$SANDBOX_BIN" "$BASH_BIN" "$HOOK" 2>/dev/null) )"; rc=$?
|
||||
[[ $rc -eq 0 ]] && pass "exits 0 when neither timeout nor gtimeout is on PATH" \
|
||||
|| fail "exited $rc with no timeout binary — must exit 0"
|
||||
if echo "$out" | python3 -m json.tool > /dev/null 2>&1; then
|
||||
pass "emits valid JSON when timeout(1) is missing"
|
||||
[[ "$(echo "$out" | json_field reloadSkills)" == "False" ]] \
|
||||
&& pass "does not ask for a skill reload when timeout(1) is missing" || fail "reloadSkills should be false"
|
||||
grep -q "neither timeout nor gtimeout" <<< "$(json_field additionalContext <<< "$out")" \
|
||||
&& pass "says timeout(1) is missing instead of failing silently" \
|
||||
|| fail "the notice should name the missing timeout binary"
|
||||
else
|
||||
fail "emits valid JSON when timeout(1) is missing: $out"
|
||||
fi
|
||||
[[ ! -f "$WORK/apm-cwd" ]] && pass "runs no apm command without a time limit" \
|
||||
|| fail "ran apm unbounded with no timeout binary"
|
||||
|
||||
if [[ -n "$REAL_TIMEOUT" ]]; then
|
||||
cat > "$GT_BIN/gtimeout" << EOF
|
||||
#!/usr/bin/env bash
|
||||
touch "$WORK/gtimeout-was-called"
|
||||
exec "$REAL_TIMEOUT" "\$@"
|
||||
EOF
|
||||
chmod +x "$GT_BIN/gtimeout"
|
||||
|
||||
rm -f "$WORK/update-was-called" "$WORK/gtimeout-was-called"
|
||||
out="$( (cd "$WORK" && env CLAUDE_PROJECT_DIR="$WORK" PATH="$FAKE_BIN:$GT_BIN:$SANDBOX_BIN" "$BASH_BIN" "$HOOK" 2>/dev/null) )"
|
||||
[[ -f "$WORK/gtimeout-was-called" ]] && pass "falls back to gtimeout when timeout is absent" \
|
||||
|| fail "should use gtimeout when timeout is not on PATH"
|
||||
[[ -f "$WORK/update-was-called" && "$(echo "$out" | json_field reloadSkills 2>/dev/null)" == "True" ]] \
|
||||
&& pass "refreshes normally through gtimeout" || fail "the gtimeout path should refresh and reload: $out"
|
||||
|
||||
rm -f "$WORK/gtimeout-was-called"
|
||||
(cd "$WORK" && env CLAUDE_PROJECT_DIR="$WORK" PATH="$FAKE_BIN:$GT_BIN:$(dirname "$REAL_TIMEOUT"):$SANDBOX_BIN" "$BASH_BIN" "$HOOK" > /dev/null 2>&1)
|
||||
[[ ! -f "$WORK/gtimeout-was-called" ]] && pass "prefers timeout over gtimeout when both exist" \
|
||||
|| fail "used gtimeout although timeout is on PATH"
|
||||
else
|
||||
echo " (timeout not on PATH — gtimeout fallback cases not run)"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "--- concurrent sessions do not both update ---"
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
if command -v flock > /dev/null 2>&1; then
|
||||
LOCK_PROJECT="$WORK/lock-project"
|
||||
mkdir -p "$LOCK_PROJECT/apm_modules"
|
||||
touch "$LOCK_PROJECT/apm.lock.yaml"
|
||||
LOCKFILE="$LOCK_PROJECT/apm_modules/.kyberforge-apm-update.lock"
|
||||
make_apm "[!] 6 outdated dependencies found" 0
|
||||
|
||||
# Lock free: the refresh runs and the lock lands under the gitignored
|
||||
# apm_modules/, never in the project root where git would see it.
|
||||
rm -f "$WORK/update-was-called"
|
||||
out="$(run_hook_in "$LOCK_PROJECT" "$LOCK_PROJECT")"
|
||||
[[ -f "$WORK/update-was-called" ]] && pass "updates when the lock is free" \
|
||||
|| fail "should update when no other session holds the lock"
|
||||
[[ -f "$LOCKFILE" ]] && pass "takes its lock under apm_modules/" \
|
||||
|| fail "expected the lock at apm_modules/.kyberforge-apm-update.lock"
|
||||
|
||||
# Lock held by another session: this one must not update, must still exit 0
|
||||
# with valid JSON, and must say why nothing was refreshed.
|
||||
exec 8> "$LOCKFILE"
|
||||
flock 8
|
||||
rm -f "$WORK/update-was-called"
|
||||
out="$(run_hook_in "$LOCK_PROJECT" "$LOCK_PROJECT" 8>&-)"; rc=$?
|
||||
exec 8>&-
|
||||
[[ $rc -eq 0 ]] && pass "exits 0 when another session holds the update lock" \
|
||||
|| fail "exited $rc with the lock held — must exit 0"
|
||||
[[ ! -f "$WORK/update-was-called" ]] && pass "skips apm update when another session holds the lock" \
|
||||
|| fail "ran apm update while another session held the lock"
|
||||
if echo "$out" | python3 -m json.tool > /dev/null 2>&1; then
|
||||
[[ "$(echo "$out" | json_field reloadSkills)" == "False" ]] \
|
||||
&& pass "does not ask for a skill reload when it skipped the refresh" || fail "reloadSkills should be false"
|
||||
grep -q "another session is refreshing it" <<< "$(json_field additionalContext <<< "$out")" \
|
||||
&& pass "says another session is refreshing" || fail "the notice should say another session holds the refresh"
|
||||
else
|
||||
fail "emits valid JSON when the lock is held: $out"
|
||||
fi
|
||||
|
||||
# No apm_modules/ yet (fresh clone before install): proceed unserialised
|
||||
# rather than create the directory.
|
||||
NO_MODULES="$WORK/no-modules"
|
||||
mkdir -p "$NO_MODULES"
|
||||
touch "$NO_MODULES/apm.lock.yaml"
|
||||
rm -f "$WORK/update-was-called"
|
||||
run_hook_in "$NO_MODULES" "$NO_MODULES" > /dev/null
|
||||
[[ -f "$WORK/update-was-called" && ! -e "$NO_MODULES/apm_modules" ]] \
|
||||
&& pass "without apm_modules/, updates unserialised and creates nothing" \
|
||||
|| fail "without apm_modules/ the hook should update and not create the directory"
|
||||
else
|
||||
echo " (flock not on PATH — lock cases not run)"
|
||||
fi
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
echo ""
|
||||
echo "--- hooks.json wiring ---"
|
||||
@@ -333,15 +467,27 @@ matcher="$(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d[
|
||||
# literal, so raising either internal `timeout` without raising the host budget
|
||||
# fails here instead of reintroducing the gap quietly.
|
||||
#
|
||||
# Every `timeout N` in the script counts, comments included: a stray "timeout
|
||||
# 300" in prose only makes this stricter, which is the safe direction.
|
||||
# Both spellings count, comments included: `-k K N` (the binary is resolved at
|
||||
# run time, so the call reads `"$timeout_bin" -k 5 60 …`) contributes the limit N
|
||||
# plus the kill-after grace K, since SIGKILL lands only K seconds after N; a
|
||||
# bare `timeout N` contributes N. A stray match in prose only makes this
|
||||
# stricter, which is the safe direction.
|
||||
script_budget=0
|
||||
timeout_count=0
|
||||
while read -r n; do
|
||||
[[ -n "$n" ]] || continue
|
||||
script_budget=$((script_budget + n))
|
||||
while read -r k n; do
|
||||
[[ -n "$k" ]] || continue
|
||||
script_budget=$((script_budget + k + ${n:-0}))
|
||||
timeout_count=$((timeout_count + 1))
|
||||
done < <(grep -oE '\btimeout [0-9]+\b' "$HOOK" | grep -oE '[0-9]+')
|
||||
done < <(
|
||||
grep -oE -- '-k [0-9]+ [0-9]+\b' "$HOOK" | grep -oE '[0-9]+ [0-9]+' || true
|
||||
grep -oE '\btimeout [0-9]+\b' "$HOOK" | grep -oE '[0-9]+' || true
|
||||
)
|
||||
|
||||
# Without -k a child that ignores SIGTERM outlives its limit and the budget
|
||||
# above is fiction. Every time-boxed call must carry the grace.
|
||||
unkilled="$(grep -E '"\$timeout_bin" ' "$HOOK" | grep -vE -- '-k [0-9]+ [0-9]+' || true)"
|
||||
[[ -z "$unkilled" ]] && pass "every time-boxed apm call carries a -k kill-after grace" \
|
||||
|| fail "a time-boxed call has no -k grace: $unkilled"
|
||||
|
||||
hook_timeout="$(python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(d["hooks"]["SessionStart"][0]["hooks"][0]["timeout"])' "$HOOKS_JSON")"
|
||||
|
||||
@@ -381,7 +527,7 @@ if ! command -v apm > /dev/null 2>&1 || ! command -v git > /dev/null 2>&1; then
|
||||
echo " $SKIP_REASON"
|
||||
else
|
||||
PROBE="$(mktemp -d)"
|
||||
trap 'rm -rf "$FAKE_BIN" "$WORK" "$PROBE"' EXIT
|
||||
trap 'rm -rf "$FAKE_BIN" "$WORK" "$SANDBOX_BIN" "$GT_BIN" "$PROBE"' EXIT
|
||||
|
||||
UPSTREAM="$PROBE/upstream.git"
|
||||
git init -q "$UPSTREAM"
|
||||
|
||||
Reference in new issue
Block a user