@brunosouzas/stackledger 0.0.0-stage → 0.5.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.
- package/LICENSE +202 -0
- package/README.md +261 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +97 -0
- package/dist/cli.js.map +1 -0
- package/dist/control.d.ts +2 -0
- package/dist/control.js +22 -0
- package/dist/control.js.map +1 -0
- package/dist/discover-command.d.ts +7 -0
- package/dist/discover-command.js +60 -0
- package/dist/discover-command.js.map +1 -0
- package/dist/discovery/annotations.d.ts +24 -0
- package/dist/discovery/annotations.js +37 -0
- package/dist/discovery/annotations.js.map +1 -0
- package/dist/discovery/host.d.ts +47 -0
- package/dist/discovery/host.js +56 -0
- package/dist/discovery/host.js.map +1 -0
- package/dist/discovery/index.d.ts +15 -0
- package/dist/discovery/index.js +30 -0
- package/dist/discovery/index.js.map +1 -0
- package/dist/discovery/machine.d.ts +14 -0
- package/dist/discovery/machine.js +17 -0
- package/dist/discovery/machine.js.map +1 -0
- package/dist/discovery/run.d.ts +39 -0
- package/dist/discovery/run.js +130 -0
- package/dist/discovery/run.js.map +1 -0
- package/dist/discovery/snapshot.d.ts +60 -0
- package/dist/discovery/snapshot.js +161 -0
- package/dist/discovery/snapshot.js.map +1 -0
- package/dist/discovery/sources/apps.d.ts +3 -0
- package/dist/discovery/sources/apps.js +136 -0
- package/dist/discovery/sources/apps.js.map +1 -0
- package/dist/discovery/sources/brew.d.ts +15 -0
- package/dist/discovery/sources/brew.js +69 -0
- package/dist/discovery/sources/brew.js.map +1 -0
- package/dist/discovery/sources/common.d.ts +39 -0
- package/dist/discovery/sources/common.js +70 -0
- package/dist/discovery/sources/common.js.map +1 -0
- package/dist/discovery/sources/index.d.ts +8 -0
- package/dist/discovery/sources/index.js +12 -0
- package/dist/discovery/sources/index.js.map +1 -0
- package/dist/discovery/sources/launchd.d.ts +3 -0
- package/dist/discovery/sources/launchd.js +65 -0
- package/dist/discovery/sources/launchd.js.map +1 -0
- package/dist/discovery/sources/mas.d.ts +9 -0
- package/dist/discovery/sources/mas.js +25 -0
- package/dist/discovery/sources/mas.js.map +1 -0
- package/dist/discovery/sources/mise.d.ts +5 -0
- package/dist/discovery/sources/mise.js +64 -0
- package/dist/discovery/sources/mise.js.map +1 -0
- package/dist/discovery/sources/npm.d.ts +12 -0
- package/dist/discovery/sources/npm.js +34 -0
- package/dist/discovery/sources/npm.js.map +1 -0
- package/dist/discovery/sources/pipx.d.ts +4 -0
- package/dist/discovery/sources/pipx.js +82 -0
- package/dist/discovery/sources/pipx.js.map +1 -0
- package/dist/discovery/types.d.ts +73 -0
- package/dist/discovery/types.js +10 -0
- package/dist/discovery/types.js.map +1 -0
- package/dist/discovery/write.d.ts +50 -0
- package/dist/discovery/write.js +196 -0
- package/dist/discovery/write.js.map +1 -0
- package/dist/drift-command.d.ts +62 -0
- package/dist/drift-command.js +375 -0
- package/dist/drift-command.js.map +1 -0
- package/dist/drift-formats.d.ts +3 -0
- package/dist/drift-formats.js +54 -0
- package/dist/drift-formats.js.map +1 -0
- package/dist/drift.d.ts +95 -0
- package/dist/drift.js +206 -0
- package/dist/drift.js.map +1 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.js +26 -0
- package/dist/errors.js.map +1 -0
- package/dist/graph.d.ts +103 -0
- package/dist/graph.js +181 -0
- package/dist/graph.js.map +1 -0
- package/dist/ics.d.ts +18 -0
- package/dist/ics.js +103 -0
- package/dist/ics.js.map +1 -0
- package/dist/identity.d.ts +18 -0
- package/dist/identity.js +36 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/map/badges.d.ts +20 -0
- package/dist/map/badges.js +95 -0
- package/dist/map/badges.js.map +1 -0
- package/dist/map/command.d.ts +8 -0
- package/dist/map/command.js +86 -0
- package/dist/map/command.js.map +1 -0
- package/dist/map/heap.d.ts +15 -0
- package/dist/map/heap.js +57 -0
- package/dist/map/heap.js.map +1 -0
- package/dist/map/ink.d.ts +11 -0
- package/dist/map/ink.js +10 -0
- package/dist/map/ink.js.map +1 -0
- package/dist/map/labels.d.ts +43 -0
- package/dist/map/labels.js +172 -0
- package/dist/map/labels.js.map +1 -0
- package/dist/map/layout.d.ts +64 -0
- package/dist/map/layout.js +228 -0
- package/dist/map/layout.js.map +1 -0
- package/dist/map/model.d.ts +46 -0
- package/dist/map/model.js +84 -0
- package/dist/map/model.js.map +1 -0
- package/dist/map/neighbourhood.d.ts +18 -0
- package/dist/map/neighbourhood.js +137 -0
- package/dist/map/neighbourhood.js.map +1 -0
- package/dist/map/parallel.d.ts +35 -0
- package/dist/map/parallel.js +261 -0
- package/dist/map/parallel.js.map +1 -0
- package/dist/map/pieces.d.ts +12 -0
- package/dist/map/pieces.js +15 -0
- package/dist/map/pieces.js.map +1 -0
- package/dist/map/relations.d.ts +39 -0
- package/dist/map/relations.js +122 -0
- package/dist/map/relations.js.map +1 -0
- package/dist/map/route.d.ts +25 -0
- package/dist/map/route.js +165 -0
- package/dist/map/route.js.map +1 -0
- package/dist/map/strip.d.ts +29 -0
- package/dist/map/strip.js +120 -0
- package/dist/map/strip.js.map +1 -0
- package/dist/map/suggest.d.ts +21 -0
- package/dist/map/suggest.js +97 -0
- package/dist/map/suggest.js.map +1 -0
- package/dist/map/svg.d.ts +29 -0
- package/dist/map/svg.js +203 -0
- package/dist/map/svg.js.map +1 -0
- package/dist/map/themes.d.ts +64 -0
- package/dist/map/themes.js +94 -0
- package/dist/map/themes.js.map +1 -0
- package/dist/map/xml.d.ts +6 -0
- package/dist/map/xml.js +57 -0
- package/dist/map/xml.js.map +1 -0
- package/dist/map/zones.d.ts +19 -0
- package/dist/map/zones.js +46 -0
- package/dist/map/zones.js.map +1 -0
- package/dist/mcp.d.ts +2 -0
- package/dist/mcp.js +145 -0
- package/dist/mcp.js.map +1 -0
- package/dist/money.d.ts +32 -0
- package/dist/money.js +91 -0
- package/dist/money.js.map +1 -0
- package/dist/report-command.d.ts +3 -0
- package/dist/report-command.js +85 -0
- package/dist/report-command.js.map +1 -0
- package/dist/report-formats.d.ts +11 -0
- package/dist/report-formats.js +157 -0
- package/dist/report-formats.js.map +1 -0
- package/dist/reports.d.ts +105 -0
- package/dist/reports.js +247 -0
- package/dist/reports.js.map +1 -0
- package/dist/scaffold.d.ts +30 -0
- package/dist/scaffold.js +140 -0
- package/dist/scaffold.js.map +1 -0
- package/dist/schema.d.ts +345 -0
- package/dist/schema.js +120 -0
- package/dist/schema.js.map +1 -0
- package/dist/secrets.d.ts +7 -0
- package/dist/secrets.js +68 -0
- package/dist/secrets.js.map +1 -0
- package/dist/site/build.d.ts +22 -0
- package/dist/site/build.js +198 -0
- package/dist/site/build.js.map +1 -0
- package/dist/site/command.d.ts +2 -0
- package/dist/site/command.js +221 -0
- package/dist/site/command.js.map +1 -0
- package/dist/site/data.d.ts +225 -0
- package/dist/site/data.js +243 -0
- package/dist/site/data.js.map +1 -0
- package/dist/site/fs-ops.d.ts +35 -0
- package/dist/site/fs-ops.js +26 -0
- package/dist/site/fs-ops.js.map +1 -0
- package/dist/site/owners.d.ts +5 -0
- package/dist/site/owners.js +50 -0
- package/dist/site/owners.js.map +1 -0
- package/dist/site/paths.d.ts +34 -0
- package/dist/site/paths.js +48 -0
- package/dist/site/paths.js.map +1 -0
- package/dist/site/policy.d.ts +17 -0
- package/dist/site/policy.js +26 -0
- package/dist/site/policy.js.map +1 -0
- package/dist/site/publish.d.ts +14 -0
- package/dist/site/publish.js +90 -0
- package/dist/site/publish.js.map +1 -0
- package/dist/site/relative.d.ts +14 -0
- package/dist/site/relative.js +265 -0
- package/dist/site/relative.js.map +1 -0
- package/dist/site/skills-build.d.ts +22 -0
- package/dist/site/skills-build.js +126 -0
- package/dist/site/skills-build.js.map +1 -0
- package/dist/site/skills-data.d.ts +89 -0
- package/dist/site/skills-data.js +94 -0
- package/dist/site/skills-data.js.map +1 -0
- package/dist/site/staging.d.ts +19 -0
- package/dist/site/staging.js +76 -0
- package/dist/site/staging.js.map +1 -0
- package/dist/site/ui-icons.d.ts +4 -0
- package/dist/site/ui-icons.js +19 -0
- package/dist/site/ui-icons.js.map +1 -0
- package/dist/skills/command.d.ts +8 -0
- package/dist/skills/command.js +64 -0
- package/dist/skills/command.js.map +1 -0
- package/dist/skills/frontmatter.d.ts +37 -0
- package/dist/skills/frontmatter.js +219 -0
- package/dist/skills/frontmatter.js.map +1 -0
- package/dist/skills/graph.d.ts +39 -0
- package/dist/skills/graph.js +100 -0
- package/dist/skills/graph.js.map +1 -0
- package/dist/skills/ignore.d.ts +34 -0
- package/dist/skills/ignore.js +138 -0
- package/dist/skills/ignore.js.map +1 -0
- package/dist/skills/lines.d.ts +53 -0
- package/dist/skills/lines.js +221 -0
- package/dist/skills/lines.js.map +1 -0
- package/dist/skills/map-command.d.ts +28 -0
- package/dist/skills/map-command.js +533 -0
- package/dist/skills/map-command.js.map +1 -0
- package/dist/skills/mermaid.d.ts +29 -0
- package/dist/skills/mermaid.js +261 -0
- package/dist/skills/mermaid.js.map +1 -0
- package/dist/skills/metro.d.ts +8 -0
- package/dist/skills/metro.js +93 -0
- package/dist/skills/metro.js.map +1 -0
- package/dist/skills/read.d.ts +17 -0
- package/dist/skills/read.js +54 -0
- package/dist/skills/read.js.map +1 -0
- package/dist/skills/rules.d.ts +28 -0
- package/dist/skills/rules.js +57 -0
- package/dist/skills/rules.js.map +1 -0
- package/dist/skills/source.d.ts +66 -0
- package/dist/skills/source.js +281 -0
- package/dist/skills/source.js.map +1 -0
- package/dist/skills/walk.d.ts +64 -0
- package/dist/skills/walk.js +281 -0
- package/dist/skills/walk.js.map +1 -0
- package/dist/source.d.ts +40 -0
- package/dist/source.js +199 -0
- package/dist/source.js.map +1 -0
- package/dist/stdout.d.ts +2 -0
- package/dist/stdout.js +24 -0
- package/dist/stdout.js.map +1 -0
- package/dist/validate.d.ts +45 -0
- package/dist/validate.js +321 -0
- package/dist/validate.js.map +1 -0
- package/dist/views.d.ts +25 -0
- package/dist/views.js +58 -0
- package/dist/views.js.map +1 -0
- package/examples/catalogue-repository/.github/workflows/stackledger.yml +122 -0
- package/examples/catalogue-repository/README.md +96 -0
- package/examples/catalogue-repository/catalog/catalog-info.yaml +12 -0
- package/examples/hosting/Caddyfile +69 -0
- package/examples/northwind/catalog-info.yaml +680 -0
- package/examples/northwind/stackledger.yaml +16 -0
- package/examples/northwind-machine/snapshot.json +309 -0
- package/examples/northwind-skills/agents/builder.md +10 -0
- package/examples/northwind-skills/agents/reviewer.md +10 -0
- package/examples/northwind-skills/designer/SKILL.md +8 -0
- package/examples/northwind-skills/editor/SKILL.md +8 -0
- package/examples/northwind-skills/engineering/SKILL.md +12 -0
- package/examples/northwind-skills/linter/SKILL.md +8 -0
- package/examples/northwind-skills/linter/rules.md +5 -0
- package/examples/northwind-skills/publishing/SKILL.md +12 -0
- package/examples/northwind-skills/publishing/rules.md +5 -0
- package/examples/northwind-skills/spec-writer/SKILL.md +8 -0
- package/examples/northwind-skills/stackledger-skills.yaml +51 -0
- package/examples/northwind-skills/tester/SKILL.md +10 -0
- package/examples/northwind-skills/writer/SKILL.md +8 -0
- package/examples/northwind-skills/writer/rules.md +6 -0
- package/npm-shrinkwrap.json +5016 -0
- package/package.json +52 -4
- package/site/LICENSE-astroplate +21 -0
- package/site/README.md +18 -0
- package/site/package.json +6 -0
- package/site/public/brand-mark-dark.svg +7 -0
- package/site/public/favicon.svg +6 -0
- package/site/public/home-banner.svg +93 -0
- package/site/public/link-icons/email-dark.svg +7 -0
- package/site/public/link-icons/email-light.svg +6 -0
- package/site/public/link-icons/github-dark.svg +8 -0
- package/site/public/link-icons/github-light.svg +7 -0
- package/site/public/link-icons/linkedin-dark.svg +8 -0
- package/site/public/link-icons/linkedin-light.svg +7 -0
- package/site/public/link-icons/website-dark.svg +8 -0
- package/site/public/link-icons/website-light.svg +7 -0
- package/site/src/components/Footer.astro +25 -0
- package/site/src/components/Header.astro +35 -0
- package/site/src/components/Impact.astro +55 -0
- package/site/src/components/LinkOrText.astro +12 -0
- package/site/src/components/SkillItem.astro +141 -0
- package/site/src/components/SubNav.astro +40 -0
- package/site/src/components/ThemeSwitch.astro +13 -0
- package/site/src/components/Themed.astro +15 -0
- package/site/src/layouts/Base.astro +52 -0
- package/site/src/lib/site.ts +25 -0
- package/site/src/pages/[reports].astro +222 -0
- package/site/src/pages/agents/[file].astro +14 -0
- package/site/src/pages/index.astro +72 -0
- package/site/src/pages/journeys/[name].astro +50 -0
- package/site/src/pages/journeys/index.astro +37 -0
- package/site/src/pages/licences/[name].astro +56 -0
- package/site/src/pages/map/index.astro +78 -0
- package/site/src/pages/playbooks/[file].astro +14 -0
- package/site/src/pages/rules/[...rules].astro +61 -0
- package/site/src/pages/skill-map/[...map].astro +101 -0
- package/site/src/pages/skills/[...list].astro +75 -0
- package/site/src/pages/skills/[file].astro +14 -0
- package/site/src/pages/software/[name].astro +155 -0
- package/site/src/pages/software/index.astro +71 -0
- package/site/src/scripts/diagram.ts +8 -0
- package/site/src/scripts/links.ts +31 -0
- package/site/src/scripts/map.ts +133 -0
- package/site/src/scripts/software.ts +32 -0
- package/site/src/scripts/theme.ts +52 -0
- package/site/src/styles/base.css +481 -0
- package/site/src/styles/fonts.css +60 -0
- package/site/src/styles/override.css +1 -0
- package/site/src/styles/pages.css +315 -0
- package/site/src/styles/tokens.css +87 -0
- package/skills/stackledger/SKILL.md +155 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** `stackledger discover` (discover-command spec): read this Mac, read-only, and write its snapshot to
|
|
2
|
+
* ~/.stackledger/<machine>/snapshot.json. Called by src/cli.ts; run node dist/cli.js discover.
|
|
3
|
+
*
|
|
4
|
+
* The command takes no folder and no option: any argument is a usage error (exit 2, nothing run).
|
|
5
|
+
* Off macOS, or without /usr/bin/sandbox-exec, it exits 1 with one line before any program runs.
|
|
6
|
+
* Otherwise it runs discovery (src/discovery/index.ts), checks the finished snapshot with the checks
|
|
7
|
+
* drift reads it with (src/discovery/snapshot.ts checkSnapshot, on its serialised JSON; a failure is
|
|
8
|
+
* exit 1 with one fixed line and the previous snapshot is kept), writes the file (src/discovery/write.ts,
|
|
9
|
+
* the only write) and prints the snapshot path and one line per source: status, items, ignored and the
|
|
10
|
+
* fixed reason. Skipped and failed sources still exit 0. Control characters are removed from the
|
|
11
|
+
* summary; program output never reaches stdout or stderr (the runner drops it).
|
|
12
|
+
*
|
|
13
|
+
* `host` and `ops` exist for the tests (test/integration/discover-entry.mjs, test/unit); src/cli.ts
|
|
14
|
+
* passes nothing, so the shipped command always reads the real machine.
|
|
15
|
+
*/
|
|
16
|
+
import { parseArgs } from 'node:util';
|
|
17
|
+
import { InternalError } from './errors.js';
|
|
18
|
+
import { discover } from './discovery/index.js';
|
|
19
|
+
import { createHost } from './discovery/host.js';
|
|
20
|
+
import { checkSnapshot, serialise } from './discovery/snapshot.js';
|
|
21
|
+
import { NODE_WRITE_OPS, writeSnapshot } from './discovery/write.js';
|
|
22
|
+
import { writeStdout } from './stdout.js';
|
|
23
|
+
export const DISCOVER_USAGE = 'Usage: stackledger discover\n';
|
|
24
|
+
const CONTROL = /[\u0000-\u001f\u007f-\u009f]/g;
|
|
25
|
+
function checkArgs(args) {
|
|
26
|
+
const { positionals, tokens } = parseArgs({ args, strict: false, allowPositionals: true, tokens: true });
|
|
27
|
+
// The first positional is the command name itself.
|
|
28
|
+
if (positionals.length > 1)
|
|
29
|
+
throw new Error('stackledger discover takes no folder');
|
|
30
|
+
if (tokens.some(token => token.kind === 'option'))
|
|
31
|
+
throw new Error('stackledger discover takes no options');
|
|
32
|
+
}
|
|
33
|
+
/** The summary: the snapshot path, then one line per source in source order. */
|
|
34
|
+
export function summary(path, snapshot) {
|
|
35
|
+
const lines = [path.replace(CONTROL, '')];
|
|
36
|
+
for (const source of snapshot.sources) {
|
|
37
|
+
const columns = [source.source.padEnd(8), source.status.padEnd(8), `items ${source.items}`.padEnd(11), `ignored ${source.ignored}`];
|
|
38
|
+
if (source.reason)
|
|
39
|
+
columns[3] = columns[3].padEnd(11) + source.reason;
|
|
40
|
+
lines.push(columns.join(' ').trimEnd());
|
|
41
|
+
}
|
|
42
|
+
return `${lines.join('\n')}\n`;
|
|
43
|
+
}
|
|
44
|
+
export async function discoverCommand(args, host = createHost(), ops = NODE_WRITE_OPS) {
|
|
45
|
+
if (args.includes('--help')) {
|
|
46
|
+
await writeStdout(DISCOVER_USAGE, 'stackledger discover: cannot write to stdout');
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
checkArgs(args);
|
|
50
|
+
if (host.platform !== 'darwin')
|
|
51
|
+
throw new InternalError('stackledger discover: discovery runs only on macOS');
|
|
52
|
+
const snapshot = await discover(host);
|
|
53
|
+
// A snapshot drift would refuse must not replace a good one: check it as drift reads it, before writing.
|
|
54
|
+
if (!('snapshot' in checkSnapshot(JSON.parse(serialise(snapshot))))) {
|
|
55
|
+
throw new InternalError('stackledger discover: the snapshot does not pass its own checks; the previous snapshot was kept');
|
|
56
|
+
}
|
|
57
|
+
const path = writeSnapshot(snapshot, { home: host.home, root: host.snapshotRoot }, ops);
|
|
58
|
+
await writeStdout(summary(path, snapshot), 'stackledger discover: cannot write the summary to stdout');
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=discover-command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"discover-command.js","sourceRoot":"","sources":["../src/discover-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,UAAU,EAAa,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAiB,MAAM,yBAAyB,CAAC;AAClF,OAAO,EAAE,cAAc,EAAE,aAAa,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,MAAM,CAAC;QACvE,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;IAC1C,CAAC;IACD,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;AACjC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAAc,EAAE,OAAa,UAAU,EAAE,EAAE,MAAgB,cAAc;IAC7G,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAAC,MAAM,WAAW,CAAC,cAAc,EAAE,8CAA8C,CAAC,CAAC;QAAC,OAAO;IAAC,CAAC;IAC3H,SAAS,CAAC,IAAI,CAAC,CAAC;IAChB,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ;QAAE,MAAM,IAAI,aAAa,CAAC,oDAAoD,CAAC,CAAC;IAC9G,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC;IACtC,yGAAyG;IACzG,IAAI,CAAC,CAAC,UAAU,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,MAAM,IAAI,aAAa,CAAC,iGAAiG,CAAC,CAAC;IAC7H,CAAC;IACD,MAAM,IAAI,GAAG,aAAa,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,YAAY,EAAE,EAAE,GAAG,CAAC,CAAC;IACxF,MAAM,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,0DAA0D,CAAC,CAAC;AACzG,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** Discovery annotations on components: `stackledger/<source>: id, id, …` (catalogue spec).
|
|
2
|
+
*
|
|
3
|
+
* Why one module: `stackledger validate` warns about these annotations and `stackledger drift`
|
|
4
|
+
* matches snapshot items through them, so both must read keys and identifiers the same way.
|
|
5
|
+
* Pure functions, no I/O. The source names and their order are the snapshot's source order.
|
|
6
|
+
*/
|
|
7
|
+
/** Discovery sources in source order (mac-discovery spec, Sources). */
|
|
8
|
+
export declare const SOURCES: readonly ["brew", "cask", "mas", "app", "launchd", "mise", "npm", "pipx"];
|
|
9
|
+
export type SourceName = typeof SOURCES[number];
|
|
10
|
+
/** Every annotation key starting with this prefix must be one of ANNOTATION_KEYS. */
|
|
11
|
+
export declare const ANNOTATION_PREFIX = "stackledger/";
|
|
12
|
+
export declare const ANNOTATION_KEYS: readonly string[];
|
|
13
|
+
/** The source an annotation key names, or undefined for an unknown or non-discovery key. */
|
|
14
|
+
export declare function annotationSource(key: string): SourceName | undefined;
|
|
15
|
+
/** The identifiers of an annotation value: comma-separated, spaces around each ignored.
|
|
16
|
+
* `empty` is true when the list holds an empty identifier (`git,,gh`, a trailing comma, a blank value). */
|
|
17
|
+
export declare function identifiers(value: string): {
|
|
18
|
+
ids: string[];
|
|
19
|
+
empty: boolean;
|
|
20
|
+
};
|
|
21
|
+
/** The form identifiers are compared in (drift-command spec, Matching through annotations):
|
|
22
|
+
* exact, except `app` (ASCII case ignored) and `pipx` (lower case, runs of `-`, `_`, `.` read as `-`). */
|
|
23
|
+
export declare function normaliseId(source: SourceName, id: string): string;
|
|
24
|
+
export declare function sameIdentifier(source: SourceName, left: string, right: string): boolean;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/** Discovery annotations on components: `stackledger/<source>: id, id, …` (catalogue spec).
|
|
2
|
+
*
|
|
3
|
+
* Why one module: `stackledger validate` warns about these annotations and `stackledger drift`
|
|
4
|
+
* matches snapshot items through them, so both must read keys and identifiers the same way.
|
|
5
|
+
* Pure functions, no I/O. The source names and their order are the snapshot's source order.
|
|
6
|
+
*/
|
|
7
|
+
/** Discovery sources in source order (mac-discovery spec, Sources). */
|
|
8
|
+
export const SOURCES = ['brew', 'cask', 'mas', 'app', 'launchd', 'mise', 'npm', 'pipx'];
|
|
9
|
+
/** Every annotation key starting with this prefix must be one of ANNOTATION_KEYS. */
|
|
10
|
+
export const ANNOTATION_PREFIX = 'stackledger/';
|
|
11
|
+
export const ANNOTATION_KEYS = SOURCES.map(source => `${ANNOTATION_PREFIX}${source}`);
|
|
12
|
+
/** The source an annotation key names, or undefined for an unknown or non-discovery key. */
|
|
13
|
+
export function annotationSource(key) {
|
|
14
|
+
if (!key.startsWith(ANNOTATION_PREFIX))
|
|
15
|
+
return undefined;
|
|
16
|
+
const source = key.slice(ANNOTATION_PREFIX.length);
|
|
17
|
+
return SOURCES.includes(source) ? source : undefined;
|
|
18
|
+
}
|
|
19
|
+
/** The identifiers of an annotation value: comma-separated, spaces around each ignored.
|
|
20
|
+
* `empty` is true when the list holds an empty identifier (`git,,gh`, a trailing comma, a blank value). */
|
|
21
|
+
export function identifiers(value) {
|
|
22
|
+
const parts = value.split(',').map(part => part.trim());
|
|
23
|
+
return { ids: parts.filter(part => part !== ''), empty: parts.some(part => part === '') };
|
|
24
|
+
}
|
|
25
|
+
/** The form identifiers are compared in (drift-command spec, Matching through annotations):
|
|
26
|
+
* exact, except `app` (ASCII case ignored) and `pipx` (lower case, runs of `-`, `_`, `.` read as `-`). */
|
|
27
|
+
export function normaliseId(source, id) {
|
|
28
|
+
if (source === 'app')
|
|
29
|
+
return id.replace(/[A-Z]/g, letter => letter.toLowerCase());
|
|
30
|
+
if (source === 'pipx')
|
|
31
|
+
return id.toLowerCase().replace(/[-_.]+/g, '-');
|
|
32
|
+
return id;
|
|
33
|
+
}
|
|
34
|
+
export function sameIdentifier(source, left, right) {
|
|
35
|
+
return normaliseId(source, left) === normaliseId(source, right);
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=annotations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"annotations.js","sourceRoot":"","sources":["../../src/discovery/annotations.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;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AQ,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IAClF,IAAI,MAAM,KAAK,MAAM;QAAE,OAAO,EAAE,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;IACvE,OAAO,EAAE,CAAC;AACZ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,MAAkB,EAAE,IAAY,EAAE,KAAa;IAC5E,OAAO,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,KAAK,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAClE,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { type Run } from './run.js';
|
|
2
|
+
/** The part of an entry's status discovery reads (node:fs Stats has it). */
|
|
3
|
+
export interface EntryStatus {
|
|
4
|
+
isFile(): boolean;
|
|
5
|
+
isDirectory(): boolean;
|
|
6
|
+
isSymbolicLink(): boolean;
|
|
7
|
+
size: number;
|
|
8
|
+
}
|
|
9
|
+
export interface Host {
|
|
10
|
+
platform: NodeJS.Platform;
|
|
11
|
+
/** The caller's environment (read for PATH and the mise and pipx folders; never passed whole to a program). */
|
|
12
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
13
|
+
home: string;
|
|
14
|
+
/** The macOS user name (`machine.user`). */
|
|
15
|
+
user: string;
|
|
16
|
+
/** Usually `/Applications`. */
|
|
17
|
+
applications: string;
|
|
18
|
+
/** Usually `/Library` (its LaunchAgents and LaunchDaemons). */
|
|
19
|
+
library: string;
|
|
20
|
+
/** Usually `/usr/bin/sandbox-exec`. */
|
|
21
|
+
sandbox: string;
|
|
22
|
+
/** Usually `~/.stackledger`: the folder that holds one folder per machine. */
|
|
23
|
+
snapshotRoot: string;
|
|
24
|
+
run: Run;
|
|
25
|
+
readdir(path: string): Promise<string[]>;
|
|
26
|
+
lstat(path: string): Promise<EntryStatus>;
|
|
27
|
+
readFile(path: string): Promise<string>;
|
|
28
|
+
/** Whether the file can be opened for reading (it is opened and closed, nothing is read). */
|
|
29
|
+
canRead(path: string): Promise<boolean>;
|
|
30
|
+
/** Whether `path` is a file that exists (links followed): used for the sandbox program. */
|
|
31
|
+
isFile(path: string): Promise<boolean>;
|
|
32
|
+
}
|
|
33
|
+
export interface HostOptions {
|
|
34
|
+
platform?: NodeJS.Platform;
|
|
35
|
+
env?: Readonly<Record<string, string | undefined>>;
|
|
36
|
+
home?: string;
|
|
37
|
+
user?: string;
|
|
38
|
+
applications?: string;
|
|
39
|
+
library?: string;
|
|
40
|
+
sandbox?: string;
|
|
41
|
+
snapshotRoot?: string;
|
|
42
|
+
programDirs?: readonly string[];
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
maxBytes?: number;
|
|
45
|
+
}
|
|
46
|
+
/** The real machine, or one with some parts replaced (the test entry script). */
|
|
47
|
+
export declare function createHost(options?: HostOptions): Host;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** The Host of discovery (design D7): everything discovery reads from the machine, in one object.
|
|
2
|
+
*
|
|
3
|
+
* Why: each source module takes a Host instead of calling node:fs, the environment or the runner
|
|
4
|
+
* directly, so unit tests feed fictitious Northwind outputs and fake folders, and the test entry
|
|
5
|
+
* script (test/integration/discover-entry.mjs) builds a host from a JSON file with fake roots, fake
|
|
6
|
+
* programs on a temporary PATH and a temporary HOME. src/discover-command.ts uses createHost() with
|
|
7
|
+
* no options: the real machine. There is no test-only branch in the shipped code.
|
|
8
|
+
*
|
|
9
|
+
* File access is read-only and never follows a link where the spec says so: `lstat` is the entry's
|
|
10
|
+
* own status, `readdir` lists names, `canRead` opens a file for reading and closes it unread, and
|
|
11
|
+
* `readFile` reads a small text file (pipx metadata). Programs only run through `run` (src/discovery/run.ts).
|
|
12
|
+
*/
|
|
13
|
+
import { constants } from 'node:fs';
|
|
14
|
+
import { lstat, open, readdir, readFile, stat } from 'node:fs/promises';
|
|
15
|
+
import { homedir, userInfo } from 'node:os';
|
|
16
|
+
import { join } from 'node:path';
|
|
17
|
+
import { createRunner, PROGRAM_DIRS, SANDBOX } from './run.js';
|
|
18
|
+
/** The real machine, or one with some parts replaced (the test entry script). */
|
|
19
|
+
export function createHost(options = {}) {
|
|
20
|
+
const env = options.env ?? process.env;
|
|
21
|
+
const home = options.home ?? homedir();
|
|
22
|
+
const sandbox = options.sandbox ?? SANDBOX;
|
|
23
|
+
const runnerOptions = { env, sandbox, programDirs: options.programDirs ?? PROGRAM_DIRS,
|
|
24
|
+
...(options.timeoutMs === undefined ? {} : { timeoutMs: options.timeoutMs }),
|
|
25
|
+
...(options.maxBytes === undefined ? {} : { maxBytes: options.maxBytes }) };
|
|
26
|
+
return {
|
|
27
|
+
platform: options.platform ?? process.platform,
|
|
28
|
+
env,
|
|
29
|
+
home,
|
|
30
|
+
user: options.user ?? userInfo().username,
|
|
31
|
+
applications: options.applications ?? '/Applications',
|
|
32
|
+
library: options.library ?? '/Library',
|
|
33
|
+
sandbox,
|
|
34
|
+
snapshotRoot: options.snapshotRoot ?? join(home, '.stackledger'),
|
|
35
|
+
run: createRunner(runnerOptions),
|
|
36
|
+
readdir: path => readdir(path),
|
|
37
|
+
lstat: path => lstat(path),
|
|
38
|
+
readFile: path => readFile(path, 'utf8'),
|
|
39
|
+
canRead: async (path) => {
|
|
40
|
+
try {
|
|
41
|
+
await (await open(path, constants.O_RDONLY | constants.O_NOFOLLOW)).close();
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
isFile: async (path) => { try {
|
|
49
|
+
return (await stat(path)).isFile();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
} },
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/discovery/host.ts"],"names":[],"mappings":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,EAAE,OAAO,CAAC,OAAO,IAAI,UAAU;QACtC,OAAO;QACP,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC;QAChE,GAAG,EAAE,YAAY,CAAC,aAAa,CAAC;QAChC,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;QAC9B,KAAK,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC;QAC1B,QAAQ,EAAE,IAAI,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACxC,OAAO,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE;YACpB,IAAI,CAAC;gBAAC,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,UAAU,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;gBAAC,OAAO,IAAI,CAAC;YAAC,CAAC;YAAC,MAAM,CAAC;gBAAC,OAAO,KAAK,CAAC;YAAC,CAAC;QAC3H,CAAC;QACD,MAAM,EAAE,KAAK,EAAC,IAAI,EAAC,EAAE,GAAG,IAAI,CAAC;YAAC,OAAO,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAAC,CAAC;QAAC,MAAM,CAAC;YAAC,OAAO,KAAK,CAAC;QAAC,CAAC,CAAC,CAAC;KAC9F,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** discover(host): read this Mac and return its snapshot (mac-discovery spec). Writes nothing:
|
|
2
|
+
* src/discovery/write.ts is the only writer, called by src/discover-command.ts.
|
|
3
|
+
*
|
|
4
|
+
* Fail closed: without the sandbox program (`host.sandbox`, /usr/bin/sandbox-exec) no program runs and
|
|
5
|
+
* no source is read (owner question 5). Then the machine name and macOS version are read through the
|
|
6
|
+
* sandboxed `scutil` and `sw_vers`, the eight sources in order, and the snapshot is built. A secret in
|
|
7
|
+
* a machine field throws (InternalError, exit 1). No network, no telemetry, no AI.
|
|
8
|
+
*/
|
|
9
|
+
import { InternalError } from '../errors.js';
|
|
10
|
+
import type { Host } from './host.js';
|
|
11
|
+
import { type Snapshot } from './snapshot.js';
|
|
12
|
+
export declare class NoSandbox extends InternalError {
|
|
13
|
+
constructor();
|
|
14
|
+
}
|
|
15
|
+
export declare function discover(host: Host, now?: Date): Promise<Snapshot>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** discover(host): read this Mac and return its snapshot (mac-discovery spec). Writes nothing:
|
|
2
|
+
* src/discovery/write.ts is the only writer, called by src/discover-command.ts.
|
|
3
|
+
*
|
|
4
|
+
* Fail closed: without the sandbox program (`host.sandbox`, /usr/bin/sandbox-exec) no program runs and
|
|
5
|
+
* no source is read (owner question 5). Then the machine name and macOS version are read through the
|
|
6
|
+
* sandboxed `scutil` and `sw_vers`, the eight sources in order, and the snapshot is built. A secret in
|
|
7
|
+
* a machine field throws (InternalError, exit 1). No network, no telemetry, no AI.
|
|
8
|
+
*/
|
|
9
|
+
import { InternalError } from '../errors.js';
|
|
10
|
+
import { machineName } from './machine.js';
|
|
11
|
+
import { buildSnapshot } from './snapshot.js';
|
|
12
|
+
import { readSources } from './sources/index.js';
|
|
13
|
+
export class NoSandbox extends InternalError {
|
|
14
|
+
constructor() { super('stackledger discover: the macOS sandbox (/usr/bin/sandbox-exec) was not found; nothing was run'); }
|
|
15
|
+
}
|
|
16
|
+
/** The macOS version from sandboxed `sw_vers -productVersion`; null when it cannot be read. */
|
|
17
|
+
async function macosVersion(host) {
|
|
18
|
+
const result = await host.run('sw_vers', ['-productVersion']);
|
|
19
|
+
const version = result.kind === 'exited' && result.code === 0 ? result.stdout.trim() : '';
|
|
20
|
+
return version === '' ? null : version;
|
|
21
|
+
}
|
|
22
|
+
export async function discover(host, now = new Date()) {
|
|
23
|
+
if (!(await host.isFile(host.sandbox)))
|
|
24
|
+
throw new NoSandbox();
|
|
25
|
+
const name = await machineName(host.run);
|
|
26
|
+
const macos = await macosVersion(host);
|
|
27
|
+
const results = await readSources(host);
|
|
28
|
+
return buildSnapshot({ now, machine: { name, user: host.user, macos }, results });
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/discovery/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,aAAa,EAAiB,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,gBAAgB,KAAK,CAAC,gGAAgG,CAAC,CAAC,CAAC,CAAC;CAC3H;AAED,+FAA+F;AAC/F,KAAK,UAAU,YAAY,CAAC,IAAU;IACpC,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC9D,MAAM,OAAO,GAAG,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1F,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC;AACzC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,IAAU,EAAE,MAAY,IAAI,IAAI,EAAE;IAC/D,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAAE,MAAM,IAAI,SAAS,EAAE,CAAC;IAC9D,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,MAAM,WAAW,CAAC,IAAI,CAAC,CAAC;IACxC,OAAO,aAAa,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** The machine name (design D5, mac-discovery spec, Machine name).
|
|
2
|
+
*
|
|
3
|
+
* Why folded: the name becomes a folder under ~/.stackledger, so it must be one safe, readable path
|
|
4
|
+
* segment (`username - MacBook Air` → `username-macbook-air`). `fold` is also used by
|
|
5
|
+
* `stackledger drift --scaffold` to make catalogue names. `machineName` asks the sandboxed `scutil` for
|
|
6
|
+
* ComputerName, then LocalHostName, and falls back to `mac`; a failed or stopped run counts as empty.
|
|
7
|
+
*/
|
|
8
|
+
import type { Run } from './run.js';
|
|
9
|
+
export declare const MAX_NAME_LENGTH = 63;
|
|
10
|
+
export declare const FALLBACK_NAME = "mac";
|
|
11
|
+
/** NFKD, combining marks removed, lower case, each run of other than a–z and 0–9 as one `-`,
|
|
12
|
+
* `-` trimmed, cut to 63 characters and trimmed again. May return ''. */
|
|
13
|
+
export declare function fold(text: string): string;
|
|
14
|
+
export declare function machineName(run: Run): Promise<string>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const MAX_NAME_LENGTH = 63;
|
|
2
|
+
export const FALLBACK_NAME = 'mac';
|
|
3
|
+
/** NFKD, combining marks removed, lower case, each run of other than a–z and 0–9 as one `-`,
|
|
4
|
+
* `-` trimmed, cut to 63 characters and trimmed again. May return ''. */
|
|
5
|
+
export function fold(text) {
|
|
6
|
+
const trim = (value) => value.replace(/^-+|-+$/g, '');
|
|
7
|
+
const folded = trim(text.normalize('NFKD').replace(/\p{M}/gu, '').toLowerCase().replace(/[^a-z0-9]+/g, '-'));
|
|
8
|
+
return trim(folded.slice(0, MAX_NAME_LENGTH));
|
|
9
|
+
}
|
|
10
|
+
async function scutilName(run, key) {
|
|
11
|
+
const result = await run('scutil', ['--get', key]);
|
|
12
|
+
return result.kind === 'exited' && result.code === 0 ? fold(result.stdout) : '';
|
|
13
|
+
}
|
|
14
|
+
export async function machineName(run) {
|
|
15
|
+
return (await scutilName(run, 'ComputerName')) || (await scutilName(run, 'LocalHostName')) || FALLBACK_NAME;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=machine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"machine.js","sourceRoot":"","sources":["../../src/discovery/machine.ts"],"names":[],"mappings":"AASA,MAAM,CAAC,MAAM,eAAe,GAAG,EAAE,CAAC;AAClC,MAAM,CAAC,MAAM,aAAa,GAAG,KAAK,CAAC;AAEnC;yEACyE;AACzE,MAAM,UAAU,IAAI,CAAC,IAAY;IAC/B,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC;IAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,OAAO,CAAC,aAAa,EAAE,GAAG,CAAC,CAAC,CAAC;IAC7G,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,eAAe,CAAC,CAAC,CAAC;AAChD,CAAC;AAED,KAAK,UAAU,UAAU,CAAC,GAAQ,EAAE,GAAW;IAC7C,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,QAAQ,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;IACnD,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAClF,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,WAAW,CAAC,GAAQ;IACxC,OAAO,CAAC,MAAM,UAAU,CAAC,GAAG,EAAE,cAAc,CAAC,CAAC,IAAI,CAAC,MAAM,UAAU,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,IAAI,aAAa,CAAC;AAC9G,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export declare const PROFILE = "(version 1)\n(allow default)\n(deny network*)\n(deny file-write* (require-not (literal \"/dev/null\")))\n";
|
|
2
|
+
export declare const SANDBOX = "/usr/bin/sandbox-exec";
|
|
3
|
+
/** Folders searched after PATH (mac-discovery spec, Programs found). */
|
|
4
|
+
export declare const PROGRAM_DIRS: string[];
|
|
5
|
+
export declare const TIME_LIMIT_MS = 60000;
|
|
6
|
+
export declare const OUTPUT_LIMIT_BYTES: number;
|
|
7
|
+
export type RunResult = {
|
|
8
|
+
kind: 'exited';
|
|
9
|
+
code: number;
|
|
10
|
+
stdout: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: 'not found';
|
|
13
|
+
} | {
|
|
14
|
+
kind: 'time limit';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'output limit';
|
|
17
|
+
};
|
|
18
|
+
export type Run = (program: string, args: string[]) => Promise<RunResult>;
|
|
19
|
+
/** The fixed reasons a source may record (mac-discovery spec, Source reasons and counts). */
|
|
20
|
+
export type Reason = 'not found' | `exited with code ${number}` | 'time limit' | 'output limit' | 'unreadable output' | 'cannot be read';
|
|
21
|
+
/** The reason for a run that did not end with exit code 0; null for a successful run. */
|
|
22
|
+
export declare function failureReason(result: RunResult): Reason | null;
|
|
23
|
+
export interface RunnerOptions {
|
|
24
|
+
/** The caller's environment: only PATH, HOME, USER and TMPDIR are passed on. */
|
|
25
|
+
env: Readonly<Record<string, string | undefined>>;
|
|
26
|
+
sandbox?: string;
|
|
27
|
+
programDirs?: readonly string[];
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
maxBytes?: number;
|
|
30
|
+
}
|
|
31
|
+
/** The environment a program gets. */
|
|
32
|
+
export declare function programEnv(env: RunnerOptions['env']): Record<string, string>;
|
|
33
|
+
/** The first executable regular file (or link to one) named `name` on PATH, then in `programDirs`.
|
|
34
|
+
* Empty and relative PATH entries are skipped: resolved against the current folder, they would let
|
|
35
|
+
* whatever folder the user happens to be in choose which `brew` or `npm` runs (mac-discovery spec,
|
|
36
|
+
* Programs found, scenario Relative PATH entry). */
|
|
37
|
+
export declare function findProgram(name: string, path: string | undefined, programDirs: readonly string[]): string | undefined;
|
|
38
|
+
/** A Run: look the program up, then run it in the sandbox with the fixed environment and limits. */
|
|
39
|
+
export declare function createRunner(options: RunnerOptions): Run;
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** The sandboxed program runner of discovery (design D1, mac-discovery spec).
|
|
2
|
+
*
|
|
3
|
+
* Every program discovery starts goes through here: it is looked up on PATH, then in the Homebrew
|
|
4
|
+
* folders, and run as `<sandbox> -p <PROFILE> <program> <args…>` without a shell. The profile denies
|
|
5
|
+
* every network access and every file write except to /dev/null, so read-only is enforced by macOS,
|
|
6
|
+
* not only intended: the 2026-10-21 spike showed plain npm and pipx runs write logs.
|
|
7
|
+
*
|
|
8
|
+
* The program gets a fixed environment (PATH, HOME, USER, TMPDIR from the caller plus settings that
|
|
9
|
+
* turn off Homebrew's update, analytics and hints, npm's update check and colour); nothing else of the
|
|
10
|
+
* caller's environment, such as a token, reaches it. A run is stopped after the time limit or once its
|
|
11
|
+
* stdout passes the output limit; stderr is read and dropped, so no program text ever reaches a
|
|
12
|
+
* reason, the snapshot or the terminal. The result says only how the run ended.
|
|
13
|
+
*
|
|
14
|
+
* What can go wrong: a missing program is `not found`; a stopped run is `time limit` or `output limit`.
|
|
15
|
+
* The runner itself never throws for a program's behaviour.
|
|
16
|
+
*/
|
|
17
|
+
import { spawn } from 'node:child_process';
|
|
18
|
+
import { accessSync, constants, statSync } from 'node:fs';
|
|
19
|
+
import { constants as osConstants } from 'node:os';
|
|
20
|
+
import { isAbsolute, join } from 'node:path';
|
|
21
|
+
export const PROFILE = '(version 1)\n(allow default)\n(deny network*)\n(deny file-write* (require-not (literal "/dev/null")))\n';
|
|
22
|
+
export const SANDBOX = '/usr/bin/sandbox-exec';
|
|
23
|
+
/** Folders searched after PATH (mac-discovery spec, Programs found). */
|
|
24
|
+
export const PROGRAM_DIRS = ['/opt/homebrew/bin', '/usr/local/bin'];
|
|
25
|
+
export const TIME_LIMIT_MS = 60_000;
|
|
26
|
+
export const OUTPUT_LIMIT_BYTES = 64 * 1024 * 1024;
|
|
27
|
+
const CALLER_KEYS = ['PATH', 'HOME', 'USER', 'TMPDIR'];
|
|
28
|
+
const FIXED_ENV = {
|
|
29
|
+
HOMEBREW_NO_AUTO_UPDATE: '1', HOMEBREW_NO_ANALYTICS: '1', HOMEBREW_NO_ENV_HINTS: '1', HOMEBREW_NO_INSTALL_CLEANUP: '1',
|
|
30
|
+
npm_config_update_notifier: 'false', NO_COLOR: '1', LC_ALL: 'C',
|
|
31
|
+
};
|
|
32
|
+
/** Shell convention for a program that was found but could not be started. */
|
|
33
|
+
const CANNOT_START = 126;
|
|
34
|
+
const SIGNAL_BASE = 128;
|
|
35
|
+
/** The reason for a run that did not end with exit code 0; null for a successful run. */
|
|
36
|
+
export function failureReason(result) {
|
|
37
|
+
if (result.kind !== 'exited')
|
|
38
|
+
return result.kind;
|
|
39
|
+
return result.code === 0 ? null : `exited with code ${result.code}`;
|
|
40
|
+
}
|
|
41
|
+
/** The environment a program gets. */
|
|
42
|
+
export function programEnv(env) {
|
|
43
|
+
const result = {};
|
|
44
|
+
for (const key of CALLER_KEYS) {
|
|
45
|
+
const value = env[key];
|
|
46
|
+
if (value !== undefined)
|
|
47
|
+
result[key] = value;
|
|
48
|
+
}
|
|
49
|
+
return { ...result, ...FIXED_ENV };
|
|
50
|
+
}
|
|
51
|
+
function executable(path) {
|
|
52
|
+
try {
|
|
53
|
+
if (!statSync(path).isFile())
|
|
54
|
+
return false;
|
|
55
|
+
accessSync(path, constants.X_OK);
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** The first executable regular file (or link to one) named `name` on PATH, then in `programDirs`.
|
|
63
|
+
* Empty and relative PATH entries are skipped: resolved against the current folder, they would let
|
|
64
|
+
* whatever folder the user happens to be in choose which `brew` or `npm` runs (mac-discovery spec,
|
|
65
|
+
* Programs found, scenario Relative PATH entry). */
|
|
66
|
+
export function findProgram(name, path, programDirs) {
|
|
67
|
+
const dirs = [...(path ?? '').split(':'), ...programDirs].filter(dir => dir !== '' && isAbsolute(dir));
|
|
68
|
+
for (const dir of dirs) {
|
|
69
|
+
const candidate = join(dir, name);
|
|
70
|
+
if (executable(candidate))
|
|
71
|
+
return candidate;
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
/** Run one already-found program inside the sandbox. */
|
|
76
|
+
function runSandboxed(sandbox, program, args, env, timeoutMs, maxBytes) {
|
|
77
|
+
return new Promise(resolve => {
|
|
78
|
+
// Own process group, so stopping the run also stops anything the program started.
|
|
79
|
+
const child = spawn(sandbox, ['-p', PROFILE, program, ...args], { env, stdio: ['ignore', 'pipe', 'pipe'], detached: true });
|
|
80
|
+
const chunks = [];
|
|
81
|
+
let bytes = 0, stopped;
|
|
82
|
+
const stop = (why) => {
|
|
83
|
+
if (stopped)
|
|
84
|
+
return;
|
|
85
|
+
stopped = why;
|
|
86
|
+
try {
|
|
87
|
+
process.kill(-child.pid, 'SIGKILL');
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
child.kill('SIGKILL');
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const timer = setTimeout(() => stop('time limit'), timeoutMs);
|
|
94
|
+
child.stdout.on('data', (chunk) => {
|
|
95
|
+
bytes += chunk.length;
|
|
96
|
+
if (bytes > maxBytes)
|
|
97
|
+
stop('output limit');
|
|
98
|
+
else
|
|
99
|
+
chunks.push(chunk);
|
|
100
|
+
});
|
|
101
|
+
// stderr is drained and dropped: it never reaches a reason or the terminal.
|
|
102
|
+
child.stderr.resume();
|
|
103
|
+
child.on('error', () => { clearTimeout(timer); resolve({ kind: 'exited', code: CANNOT_START, stdout: '' }); });
|
|
104
|
+
child.on('close', (code, signal) => {
|
|
105
|
+
clearTimeout(timer);
|
|
106
|
+
if (stopped) {
|
|
107
|
+
resolve({ kind: stopped });
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
// A program killed by a signal reports 128 + the signal number, as a shell does.
|
|
111
|
+
const exit = code ?? SIGNAL_BASE + (signal ? osConstants.signals[signal] : 0);
|
|
112
|
+
resolve({ kind: 'exited', code: exit, stdout: Buffer.concat(chunks).toString('utf8') });
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
/** A Run: look the program up, then run it in the sandbox with the fixed environment and limits. */
|
|
117
|
+
export function createRunner(options) {
|
|
118
|
+
const sandbox = options.sandbox ?? SANDBOX;
|
|
119
|
+
const programDirs = options.programDirs ?? PROGRAM_DIRS;
|
|
120
|
+
const env = programEnv(options.env);
|
|
121
|
+
const timeoutMs = options.timeoutMs ?? TIME_LIMIT_MS;
|
|
122
|
+
const maxBytes = options.maxBytes ?? OUTPUT_LIMIT_BYTES;
|
|
123
|
+
return async (name, args) => {
|
|
124
|
+
const program = findProgram(name, options.env.PATH, programDirs);
|
|
125
|
+
if (!program)
|
|
126
|
+
return { kind: 'not found' };
|
|
127
|
+
return runSandboxed(sandbox, program, args, env, timeoutMs, maxBytes);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
//# sourceMappingURL=run.js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AAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,kBAAkB,CAAC;IACxD,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAC1B,MAAM,OAAO,GAAG,WAAW,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QACjE,IAAI,CAAC,OAAO;YAAE,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC;QAC3C,OAAO,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;IACxE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** The snapshot model `stackledger-snapshot/v1` (design D3, mac-discovery spec).
|
|
2
|
+
*
|
|
3
|
+
* One module for everything about the file's content, so `discover` writes and `drift` reads the same
|
|
4
|
+
* rules: the zod schema (strict objects: an unknown field is a shape error), the consistency checks,
|
|
5
|
+
* the secret guard, merging, sorting and the serialiser.
|
|
6
|
+
*
|
|
7
|
+
* - buildSnapshot turns the raw source results into a snapshot: an item holding private-key material
|
|
8
|
+
* or a card number (src/secrets.ts, the catalogue's rule) is left out and counted as ignored; items of
|
|
9
|
+
* one source without a path and with the same id are merged; every list is sorted without repeats and
|
|
10
|
+
* items are sorted by source order, id, path (Unicode code points). A secret in a `machine` field
|
|
11
|
+
* throws: discovery then fails and writes nothing. E-mail addresses are not checked (spec).
|
|
12
|
+
* - checkSnapshot validates parsed JSON and names only the kind of problem, never a value.
|
|
13
|
+
* - serialise writes JSON with two-space indentation, U+007F–U+009F as \u escapes, and a final line feed.
|
|
14
|
+
*/
|
|
15
|
+
import { z } from 'zod';
|
|
16
|
+
import { type SourceName } from './annotations.js';
|
|
17
|
+
import type { Reason } from './run.js';
|
|
18
|
+
import type { Item, SourceResult, Status } from './types.js';
|
|
19
|
+
export declare const SNAPSHOT_FORMAT = "stackledger-snapshot/v1";
|
|
20
|
+
export interface Machine {
|
|
21
|
+
name: string;
|
|
22
|
+
user: string;
|
|
23
|
+
macos: string | null;
|
|
24
|
+
}
|
|
25
|
+
export interface SnapshotSource {
|
|
26
|
+
source: SourceName;
|
|
27
|
+
status: Status;
|
|
28
|
+
reason: Reason | null;
|
|
29
|
+
items: number;
|
|
30
|
+
ignored: number;
|
|
31
|
+
}
|
|
32
|
+
export interface Snapshot {
|
|
33
|
+
format: typeof SNAPSHOT_FORMAT;
|
|
34
|
+
takenAt: string;
|
|
35
|
+
machine: Machine;
|
|
36
|
+
sources: SnapshotSource[];
|
|
37
|
+
items: Item[];
|
|
38
|
+
}
|
|
39
|
+
export declare const snapshotSchema: z.ZodType<Snapshot>;
|
|
40
|
+
export declare function compareItems(left: Item, right: Item): number;
|
|
41
|
+
/** `new Date().toISOString()` cut to seconds. */
|
|
42
|
+
export declare function takenAt(now: Date): string;
|
|
43
|
+
/** The snapshot of the given source results; throws when a machine field breaks a secret rule. */
|
|
44
|
+
export declare function buildSnapshot(input: {
|
|
45
|
+
now: Date;
|
|
46
|
+
machine: Machine;
|
|
47
|
+
results: SourceResult[];
|
|
48
|
+
}): Snapshot;
|
|
49
|
+
export type SnapshotCheck = {
|
|
50
|
+
snapshot: Snapshot;
|
|
51
|
+
} | {
|
|
52
|
+
problem: 'format' | 'shape' | 'consistency';
|
|
53
|
+
} | {
|
|
54
|
+
problem: 'secret';
|
|
55
|
+
rule: string;
|
|
56
|
+
};
|
|
57
|
+
/** Check parsed JSON as a `stackledger-snapshot/v1` snapshot; the result names a problem, never a value. */
|
|
58
|
+
export declare function checkSnapshot(value: unknown): SnapshotCheck;
|
|
59
|
+
/** The file's text: deterministic for the same snapshot. */
|
|
60
|
+
export declare function serialise(snapshot: Snapshot): string;
|