@aperant/framework 0.8.7 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +74 -0
  2. package/agents/apt-pr-review-fixer.md +9 -4
  3. package/dist/cli/commands/init.mjs +140 -22
  4. package/dist/cli/commands/init.mjs.map +1 -1
  5. package/dist/cli/commands/toolchain-detect.d.mts.map +1 -1
  6. package/dist/cli/commands/toolchain-detect.mjs +44 -0
  7. package/dist/cli/commands/toolchain-detect.mjs.map +1 -1
  8. package/dist/cli/commands/triage.d.mts.map +1 -1
  9. package/dist/cli/commands/triage.mjs +346 -13
  10. package/dist/cli/commands/triage.mjs.map +1 -1
  11. package/dist/cli/commands/uninstall.d.mts.map +1 -1
  12. package/dist/cli/commands/uninstall.mjs +11 -8
  13. package/dist/cli/commands/uninstall.mjs.map +1 -1
  14. package/dist/cli/install/runtime-detect.d.mts +26 -0
  15. package/dist/cli/install/runtime-detect.d.mts.map +1 -1
  16. package/dist/cli/install/runtime-detect.mjs +27 -0
  17. package/dist/cli/install/runtime-detect.mjs.map +1 -1
  18. package/dist/cli/util/aperant-section.d.mts +12 -0
  19. package/dist/cli/util/aperant-section.d.mts.map +1 -1
  20. package/dist/cli/util/aperant-section.mjs +12 -0
  21. package/dist/cli/util/aperant-section.mjs.map +1 -1
  22. package/dist/cli/util/copy.d.mts +27 -0
  23. package/dist/cli/util/copy.d.mts.map +1 -1
  24. package/dist/cli/util/copy.mjs +49 -5
  25. package/dist/cli/util/copy.mjs.map +1 -1
  26. package/dist/cli/verify-proof/idl/index.d.mts +12 -1
  27. package/dist/cli/verify-proof/idl/index.d.mts.map +1 -1
  28. package/dist/cli/verify-proof/idl/index.mjs +50 -1
  29. package/dist/cli/verify-proof/idl/index.mjs.map +1 -1
  30. package/dist/cli/verify-proof/resolver.d.mts.map +1 -1
  31. package/dist/cli/verify-proof/resolver.mjs +51 -1
  32. package/dist/cli/verify-proof/resolver.mjs.map +1 -1
  33. package/dist/plugin/.claude-plugin/plugin.json +1 -1
  34. package/dist/plugin/agents/apt-pr-review-fixer.md +9 -4
  35. package/dist/plugin/skills/apt-pr-review/SKILL.md +52 -15
  36. package/dist/plugin/skills/apt-setup/SKILL.md +7 -6
  37. package/dist/plugin/skills/apt-triage/SKILL.md +8 -6
  38. package/dist/plugin/skills/apt-update/SKILL.md +1 -1
  39. package/package.json +1 -1
  40. package/skills/apt-pr-review/SKILL.md +52 -15
  41. package/skills/apt-setup/SKILL.md +7 -6
  42. package/skills/apt-triage/SKILL.md +8 -6
  43. package/skills/apt-update/SKILL.md +1 -1
  44. package/src/cli/commands/init.mjs +144 -19
  45. package/src/cli/commands/toolchain-detect.mjs +44 -0
  46. package/src/cli/commands/triage.mjs +352 -11
  47. package/src/cli/commands/uninstall.mjs +11 -8
  48. package/src/cli/install/runtime-detect.mjs +27 -0
  49. package/src/cli/util/aperant-section.mjs +14 -0
  50. package/src/cli/util/copy.mjs +53 -8
  51. package/src/cli/verify-proof/idl/index.mjs +49 -11
  52. package/src/cli/verify-proof/resolver.mjs +49 -2
@@ -20,7 +20,21 @@ import {
20
20
  writeFileSync,
21
21
  } from 'node:fs'
22
22
  import { join } from 'node:path'
23
- import { extractAptSectionRowIds } from './aperant-section.mjs'
23
+ import { APT_SECTION_RE, extractAptSectionRowIds } from './aperant-section.mjs'
24
+
25
+ /**
26
+ * Return the row IDs present in `existing` that are NOT present in
27
+ * `aptSection`. An empty array means no foreign rows (safe to overwrite).
28
+ *
29
+ * @param {string} existing Current on-disk file contents.
30
+ * @param {string} aptSection Output of buildAptSection().
31
+ * @returns {string[]}
32
+ */
33
+ function computeForeignRowIds(existing, aptSection) {
34
+ const existingIds = new Set(extractAptSectionRowIds(existing))
35
+ const generatedIds = new Set(extractAptSectionRowIds(aptSection))
36
+ return [...existingIds].filter((id) => !generatedIds.has(id))
37
+ }
24
38
 
25
39
  export function copyDirRecursive(src, dest) {
26
40
  mkdirSync(dest, { recursive: true })
@@ -35,6 +49,42 @@ export function copyDirRecursive(src, dest) {
35
49
  }
36
50
  }
37
51
 
52
+ /**
53
+ * Preflight-only sibling of `injectInstructionFile`. Runs the same
54
+ * foreign-row defensive check against `filePath` but NEVER writes — used by
55
+ * the multi-target init flow to check every instruction target up-front so a
56
+ * single aborting target leaves NO file partially written (US-03 / AC3).
57
+ *
58
+ * Returns the same status vocabulary as `injectInstructionFile` minus the
59
+ * write side-effect: `'created'` (file absent → would be appended-to),
60
+ * `'updated'` (markers present, no foreign rows → would be replaced),
61
+ * `'aborted-foreign-rows'` (markers present with rows not in the generated
62
+ * set → init must abort). `force` short-circuits the foreign-row gate exactly
63
+ * as the writer does.
64
+ *
65
+ * @param {string} filePath
66
+ * @param {Object} opts
67
+ * @param {string} opts.aptSection Output of buildAptSection().
68
+ * @param {boolean} [opts.force=false]
69
+ * Bypass the foreign-row check.
70
+ * @returns {{ status: 'created' | 'updated' | 'aborted-foreign-rows', foreignRowIds?: string[] }}
71
+ */
72
+ export function checkInstructionFile(filePath, { aptSection, force = false }) {
73
+ const existing = existsSync(filePath) ? readFileSync(filePath, 'utf-8') : ''
74
+
75
+ if (existing.includes('<!-- APT:framework-start -->')) {
76
+ if (!force) {
77
+ const foreignRowIds = computeForeignRowIds(existing, aptSection)
78
+ if (foreignRowIds.length > 0) {
79
+ return { status: 'aborted-foreign-rows', foreignRowIds }
80
+ }
81
+ }
82
+ return { status: 'updated' }
83
+ }
84
+
85
+ return { status: 'created' }
86
+ }
87
+
38
88
  /**
39
89
  * Write the (already-generated) APT section into `filePath`. Creates the
40
90
  * file if missing; replaces the section in-place if the markers are
@@ -60,17 +110,12 @@ export function injectInstructionFile(filePath, { aptSection, force = false }) {
60
110
 
61
111
  if (existing.includes('<!-- APT:framework-start -->')) {
62
112
  if (!force) {
63
- const existingIds = new Set(extractAptSectionRowIds(existing))
64
- const generatedIds = new Set(extractAptSectionRowIds(aptSection))
65
- const foreignRowIds = [...existingIds].filter((id) => !generatedIds.has(id))
113
+ const foreignRowIds = computeForeignRowIds(existing, aptSection)
66
114
  if (foreignRowIds.length > 0) {
67
115
  return { status: 'aborted-foreign-rows', written: false, foreignRowIds }
68
116
  }
69
117
  }
70
- const updated = existing.replace(
71
- /<!-- APT:framework-start -->[\s\S]*?<!-- APT:framework-end -->/,
72
- aptSection,
73
- )
118
+ const updated = existing.replace(APT_SECTION_RE, aptSection)
74
119
  writeFileSync(filePath, updated, 'utf-8')
75
120
  return { status: 'updated', written: true }
76
121
  }
@@ -8,16 +8,54 @@
8
8
  * refactor of every callsite.
9
9
  *
10
10
  * If you add a verb, edit packages/framework/src/driver-sdk/idl.ts.
11
+ *
12
+ * Defense-in-depth (issue #248). `@aperant/framework/driver-sdk` resolves
13
+ * via the package `exports` map to `dist/driver-sdk/index.js`. A *static*
14
+ * `export … from '@aperant/framework/driver-sdk'` here made this barrel —
15
+ * and therefore the whole apt-tools CLI, since `dispatch.mjs` eagerly
16
+ * imports `driver-doctor.mjs` which imports this barrel — crash at
17
+ * module-resolution time with an opaque `ERR_MODULE_NOT_FOUND` when the
18
+ * dist was not built (e.g. a CI step that skipped `pnpm build`), before
19
+ * any command body could run. Resolving the registry via a *dynamic*
20
+ * `await import()` wrapped in try/catch keeps that dependency off the
21
+ * hard module-link path: dist present (tests, post-build CI, published
22
+ * tarball) → the REAL registry values are re-exported unchanged; dist
23
+ * absent → empty/no-op fallbacks let the CLI load (so commands that don't
24
+ * touch the IDL registry, like `route`, still run) instead of crashing.
11
25
  */
12
26
 
13
- export {
14
- ASSERTION_VERBS,
15
- ASYNC_VERBS,
16
- EVIDENCE_VERBS,
17
- IDL_VERB_ARGS,
18
- IDL_VERB_NAMES,
19
- INTERACTION_VERBS,
20
- isVerbResult,
21
- LIFECYCLE_VERBS,
22
- validateVerbArgs,
23
- } from '@aperant/framework/driver-sdk'
27
+ /** @type {typeof import('@aperant/framework/driver-sdk')} */
28
+ let _sdk
29
+ try {
30
+ _sdk = await import('@aperant/framework/driver-sdk')
31
+ } catch (err) {
32
+ // Only the intended "dist not built" condition degrades. A corrupt or
33
+ // partially-written dist (SyntaxError, broken transitive load) raises a
34
+ // different code and MUST surface, not be masked into an empty registry.
35
+ if (err?.code !== 'ERR_MODULE_NOT_FOUND') throw err
36
+ // dist/driver-sdk absent — degrade to empty registry so module load
37
+ // does not crash. Any code path that actually needs a verb registry
38
+ // (driver-doctor, the bundled drivers) requires a built dist anyway;
39
+ // commands that don't (e.g. `route`) keep working.
40
+ _sdk = {
41
+ ASSERTION_VERBS: [],
42
+ ASYNC_VERBS: [],
43
+ EVIDENCE_VERBS: [],
44
+ IDL_VERB_ARGS: {},
45
+ IDL_VERB_NAMES: [],
46
+ INTERACTION_VERBS: [],
47
+ isVerbResult: () => false,
48
+ LIFECYCLE_VERBS: [],
49
+ validateVerbArgs: () => ({ ok: true, errors: [] }),
50
+ }
51
+ }
52
+
53
+ export const ASSERTION_VERBS = _sdk.ASSERTION_VERBS
54
+ export const ASYNC_VERBS = _sdk.ASYNC_VERBS
55
+ export const EVIDENCE_VERBS = _sdk.EVIDENCE_VERBS
56
+ export const IDL_VERB_ARGS = _sdk.IDL_VERB_ARGS
57
+ export const IDL_VERB_NAMES = _sdk.IDL_VERB_NAMES
58
+ export const INTERACTION_VERBS = _sdk.INTERACTION_VERBS
59
+ export const isVerbResult = _sdk.isVerbResult
60
+ export const LIFECYCLE_VERBS = _sdk.LIFECYCLE_VERBS
61
+ export const validateVerbArgs = _sdk.validateVerbArgs
@@ -30,13 +30,60 @@
30
30
  * Existing `resolveDriver()` and `scoreDriver()` exports are unchanged.
31
31
  */
32
32
 
33
- import { UnsatisfiedRequiredCapabilityError } from '@aperant/framework/driver-sdk'
34
-
35
33
  /**
36
34
  * @typedef {import('@aperant/framework/driver-sdk').DriverManifest} DriverManifest
37
35
  * @typedef {import('./runtime-detect.mjs').RuntimeCapabilities} RuntimeCapabilities
38
36
  */
39
37
 
38
+ /**
39
+ * Defense-in-depth (issue #248). The driver-sdk error class lives in
40
+ * `@aperant/framework/driver-sdk`, whose `exports` map resolves to
41
+ * `dist/driver-sdk/index.js`. An eager *static* top-level
42
+ * `import { UnsatisfiedRequiredCapabilityError } from '@aperant/framework/driver-sdk'`
43
+ * made the WHOLE apt-tools CLI crash at module-resolution time when the
44
+ * dist was not built (e.g. a CI step that skipped `pnpm build`): the
45
+ * static import is resolved at module-link, so an opaque
46
+ * `ERR_MODULE_NOT_FOUND` was raised before any command body — or any
47
+ * `--no-fail` downgrade in run-route-eval.mjs — could run.
48
+ *
49
+ * We instead resolve the class via a *dynamic* `await import()` that is
50
+ * wrapped in try/catch. Dynamic import is still evaluated at module
51
+ * load (top-level await), but its failure is now swallowable rather than
52
+ * a hard link-time crash:
53
+ * - dist present (tests, post-build CI, published tarball) → the REAL
54
+ * class is bound, so any thrown error stays
55
+ * `instanceof UnsatisfiedRequiredCapabilityError` for every consumer
56
+ * (including the resolver suites that import the class from the same
57
+ * `@aperant/framework/driver-sdk` ESM specifier);
58
+ * - dist absent → we fall back to a structurally identical local class
59
+ * (same `.name` / `.capability` / `.attempts` shape, which
60
+ * `detect-runtime.mjs` inspects via `.attempts`) so the CLI degrades
61
+ * to a clear, catchable error instead of crashing at load.
62
+ *
63
+ * `resolveDriver` stays fully synchronous — the class is already bound by
64
+ * the time any importer of this module finishes linking.
65
+ *
66
+ * @type {new (message: string, capability?: string, attempts?: ReadonlyArray<{driver_id: string, reason: string}>) => Error}
67
+ */
68
+ let UnsatisfiedRequiredCapabilityError
69
+ try {
70
+ ;({ UnsatisfiedRequiredCapabilityError } = await import('@aperant/framework/driver-sdk'))
71
+ } catch (err) {
72
+ // Only the intended "dist not built" condition degrades. A corrupt or
73
+ // partially-written dist (SyntaxError, broken transitive load) raises a
74
+ // different code and MUST surface, not be masked into a silent fallback.
75
+ if (err?.code !== 'ERR_MODULE_NOT_FOUND') throw err
76
+ // dist/driver-sdk absent — degrade instead of crashing the CLI.
77
+ UnsatisfiedRequiredCapabilityError = class UnsatisfiedRequiredCapabilityError extends Error {
78
+ constructor(message, capability, attempts = []) {
79
+ super(message)
80
+ this.name = 'UnsatisfiedRequiredCapabilityError'
81
+ this.capability = capability
82
+ this.attempts = attempts
83
+ }
84
+ }
85
+ }
86
+
40
87
  const STABILITY_RANK = { ga: 3, beta: 2, experimental: 1 }
41
88
  const LOCALITY_RANK = { bundled: 3, user: 2, registry: 1 }
42
89