@egawilldoit/factory 0.0.0-stage → 1.0.1

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 (38) hide show
  1. package/README.md +121 -2
  2. package/bin/factory.js +6 -0
  3. package/bundle/bundle.json +105 -0
  4. package/bundle/files/docs/authorization-and-completion-scenarios.md +21 -0
  5. package/bundle/files/docs/v4-acceptance-status.md +11 -0
  6. package/bundle/files/references/improvement-and-metrics.md +59 -0
  7. package/bundle/files/references/planning.md +83 -0
  8. package/bundle/files/references/pr-workflows.md +105 -0
  9. package/bundle/files/references/risk-and-delivery.md +67 -0
  10. package/bundle/files/references/skill-compatibility.md +11 -0
  11. package/bundle/files/references/synchronization.md +99 -0
  12. package/bundle/files/references/takeover-and-modernize.md +68 -0
  13. package/bundle/files/references/task-summary.md +36 -0
  14. package/bundle/files/references/verification-and-review.md +74 -0
  15. package/bundle/files/references/web-guidance.md +88 -0
  16. package/bundle/files/references/workflow.md +10 -0
  17. package/bundle/files/skills/factory/SKILL.md +96 -0
  18. package/bundle/files/skills/factory-improve/SKILL.md +54 -0
  19. package/bundle/files/skills/factory-plan/SKILL.md +47 -0
  20. package/bundle/files/skills/factory-verify/SKILL.md +73 -0
  21. package/bundle/files/templates/task-summary.yaml +21 -0
  22. package/lib/boundary.js +77 -0
  23. package/lib/bundle.js +104 -0
  24. package/lib/cli.js +173 -0
  25. package/lib/constants.js +49 -0
  26. package/lib/doctor.js +72 -0
  27. package/lib/errors.js +30 -0
  28. package/lib/fs-util.js +177 -0
  29. package/lib/install.js +84 -0
  30. package/lib/manifest.js +45 -0
  31. package/lib/ops-util.js +92 -0
  32. package/lib/paths.js +94 -0
  33. package/lib/recovery.js +247 -0
  34. package/lib/references.js +51 -0
  35. package/lib/rollback.js +78 -0
  36. package/lib/uninstall.js +57 -0
  37. package/lib/update.js +75 -0
  38. package/package.json +27 -4
@@ -0,0 +1,73 @@
1
+ ---
2
+ name: factory-verify
3
+ description: "Establish evidence for a change: essential checks, behavior verification, and a separate final review with honest independence. Use before delivery or when verification is requested."
4
+ ---
5
+
6
+ # Factory Verify
7
+
8
+ Define and record evidence for the final scoped change. Verification produces an evidence table; review is a separate pass. Same-agent review is never independent.
9
+
10
+ ## Interface
11
+
12
+ Input: final diff/scope, base/ref, working-tree state, risk tier, environment, and requested readiness boundary.
13
+
14
+ Output evidence table with, for each essential criterion:
15
+ - Status: `passed`, `failed`, or `not checked`.
16
+ - Evidence: observed command, output, artifact, or reason.
17
+ - Environment and scoped revision/worktree state.
18
+ - Readiness impact.
19
+
20
+ Also output:
21
+ - Behavior verification notes (real user flow when feasible).
22
+ - Review findings and independence disclosure (`same-agent` when the same agent performs both).
23
+ - Missing evidence and whether it blocks readiness.
24
+
25
+ ## Essential checks
26
+
27
+ Choose checks proportional to the change and risk tier. Every essential criterion must have a status; do not leave blank.
28
+
29
+ | Area | What to check | When relevant |
30
+ |------|--------------|---------------|
31
+ | Logic | Focused meaningful tests; type/lint/build checks | Any code or skill change |
32
+ | UI | Real user flow; keyboard, focus, responsive behavior, accessible names, reduced motion | Web/UI/accessibility change |
33
+ | APIs | Representative endpoint and failure behavior | API-facing change |
34
+ | Data/auth | Invariants, permissions, migration behavior in an authorized environment | Data/auth/migration change |
35
+ | Performance | Comparable baseline and after measurements in same environment | Performance-sensitive change |
36
+ | Docs | Links and examples appropriate to the change | Doc/user-facing change |
37
+
38
+ Per criterion, record one of:
39
+ - `passed`: observed evidence, command or artifact, target environment, scoped revision.
40
+ - `failed`: observed failure and impact.
41
+ - `not checked`: exact reason and impact on delivery/readiness.
42
+
43
+ ## Rules
44
+
45
+ - Build/CI alone is not proof of user behavior.
46
+ - Evidence must correspond to the final scoped diff, including uncommitted (dirty) state.
47
+ - After meaningful review fixes, rebase/conflict resolution, or other invalidating changes, repeat affected checks.
48
+ - Same-agent review is not independent; label it `same-agent`.
49
+ - If an essential check is unavailable, mark it `not checked` with exact reason and readiness impact.
50
+ - Do not claim full verification when mandatory evidence is missing.
51
+ - If `factory-verify` is unavailable, `factory` performs a minimal evidence pass and labels it `verification: fallback-inline`.
52
+
53
+ ## Completion
54
+
55
+ Once scoped checks and final review pass, proceed to the authorized delivery boundary. Additional tests or reviews need a concrete finding, changed requirement or invalidated evidence. Distinguish required checks and concrete technical blockers from optional improvements; focus on resolving the actual blocker. See `../../references/verification-and-review.md` for completion and blocker handling.
56
+
57
+ ## Review
58
+
59
+ Separately assess: requested behavior, omitted requirements, unintended changes, error handling, security, architecture, maintainability, and test coverage. Report limitations honestly. Disclose whether the reviewer is independent of the implementer. Green checks do not authorize production operations or make destructive actions reversible.
60
+
61
+ Keep independent review optional and bounded: one reviewer, at most two reviewer runs per task. Reuse the user's model choice; otherwise ask once and suggest GPT-6.1 Sol at low effort. Confirm availability and never silently substitute. Record findings with evidence, severity and disposition; make scoped fixes, rerun affected checks, and stop at optional nits. Follow `../../references/verification-and-review.md` for review inputs, limits and unresolved findings.
62
+
63
+ ## Scenario verification (T06)
64
+
65
+ When verifying this skill itself:
66
+
67
+ 1. **Invalidated check:** Make a temporary edit to a checked file, confirm a previously `passed` check no longer passes, revert, and rerun to confirm it passes again. Record both observations.
68
+ 2. **Unavailable browser:** If a UI/browser check cannot run, mark it `not checked` with reason (no browser / no network / host lacks display) and readiness impact; do not substitute a static scan.
69
+ 3. Inspect actual outputs, not only the agent's narrative.
70
+
71
+ ## Fallback
72
+
73
+ When this skill cannot be invoked, `factory` performs an inline evidence pass: record repo/branch/HEAD/dirty state, list essential criteria as `not checked` with reason "factory-verify unavailable", and label `verification: fallback-inline`.
@@ -0,0 +1,21 @@
1
+ # EGA Software Factory — opt-in local task summary (schema_version 1)
2
+ # Copy to the summary directory and fill in real values, one file per task:
3
+ # ${XDG_DATA_HOME:-$HOME/.local/share}/ega-factory/summaries/<date>-<short-task>.yaml
4
+ # Write only when the user explicitly opts in. See references/task-summary.md.
5
+ # Rules: unknown -> null or "unknown", never zero or an estimate.
6
+ # no credentials, full prompts, private diffs, or transcripts.
7
+
8
+ schema_version: 1
9
+ factory_version: "REPLACE_factory_version"
10
+ project: "REPLACE_project"
11
+ task: "REPLACE_task"
12
+ base: "REPLACE_base"
13
+ final_revision: "REPLACE_final_revision"
14
+ worktree_state: "REPLACE_worktree_state"
15
+ environment: "REPLACE_environment"
16
+ outcome: "REPLACE_outcome"
17
+ verification: "REPLACE_verification"
18
+ review: "REPLACE_review"
19
+ duration: null
20
+ cost: null
21
+ lesson: "REPLACE_lesson_or_remove"
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const { installedPath } = require('./paths');
6
+ const { refuse } = require('./errors');
7
+
8
+ // Symlinks in a parent of the destination (for example a symlinked HOME) are
9
+ // acceptable: resolveDestination canonicalises the destination once. Everything
10
+ // at or below the destination that this installer writes must be real files and
11
+ // directories, otherwise a managed path could escape the installation root.
12
+ function symlinkWithin(root, target) {
13
+ const rel = path.relative(root, target);
14
+ if (rel === '') return null;
15
+ if (rel.startsWith('..') || path.isAbsolute(rel)) return target;
16
+ let current = root;
17
+ for (const part of rel.split(path.sep)) {
18
+ current = path.join(current, part);
19
+ try {
20
+ if (fs.lstatSync(current).isSymbolicLink()) return current;
21
+ } catch (err) {
22
+ if (err.code !== 'ENOENT') throw err;
23
+ }
24
+ }
25
+ return null;
26
+ }
27
+
28
+ function assertBoundary(root, targets, context) {
29
+ const bad = [];
30
+ for (const target of targets) {
31
+ const link = symlinkWithin(root, target);
32
+ if (link) bad.push(link);
33
+ }
34
+ if (bad.length) {
35
+ throw refuse(
36
+ 'Refusing to write through a symbolic link inside the destination.',
37
+ (context ? context + '\n' : '') +
38
+ 'Symlinked path(s):\n ' + bad.join('\n ') +
39
+ '\nReplace these links with real files/directories or use a different --destination.'
40
+ );
41
+ }
42
+ }
43
+
44
+ function metaTargets(paths) {
45
+ return [
46
+ paths.metaDir,
47
+ paths.manifestPath,
48
+ paths.lockFile,
49
+ paths.stagingDir,
50
+ paths.pendingManifest,
51
+ paths.previousDir,
52
+ paths.preservedDir,
53
+ ];
54
+ }
55
+
56
+ function assertMetadataBoundary(paths) {
57
+ assertBoundary(paths.dest, metaTargets(paths), 'Installation metadata boundary check failed.');
58
+ }
59
+
60
+ function assertManagedBoundary(paths, manifest) {
61
+ if (!manifest) return;
62
+ assertBoundary(paths.dest, Object.keys(manifest.files).map((rel) => installedPath(paths, rel)), 'Managed content boundary check failed.');
63
+ }
64
+
65
+ function assertInstallationBoundary(paths, rels) {
66
+ assertMetadataBoundary(paths);
67
+ assertBoundary(paths.dest, rels.map((rel) => installedPath(paths, rel)), 'Managed content boundary check failed.');
68
+ }
69
+
70
+ module.exports = {
71
+ symlinkWithin,
72
+ assertBoundary,
73
+ metaTargets,
74
+ assertMetadataBoundary,
75
+ assertManagedBoundary,
76
+ assertInstallationBoundary,
77
+ };
package/lib/bundle.js ADDED
@@ -0,0 +1,104 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+ const fs = require('fs');
5
+ const fsu = require('./fs-util');
6
+ const { recovery } = require('./errors');
7
+
8
+ const BUNDLE_DIR = 'bundle';
9
+ const DESCRIPTOR = 'bundle.json';
10
+ const FILES_DIR = 'files';
11
+
12
+ // The descriptor is the shared content index used by the local installer and
13
+ // (later) the read-only MCP channel. Format is coordinated with release
14
+ // wiring; see docs/handoff or the implementation report for the exact shape.
15
+ function loadBundle(packageRoot) {
16
+ const dir = path.join(packageRoot, BUNDLE_DIR);
17
+ const descriptorPath = path.join(dir, DESCRIPTOR);
18
+ const filesRoot = path.join(dir, FILES_DIR);
19
+
20
+ if (!fsu.isFile(descriptorPath) || !fsu.isDirectory(filesRoot)) {
21
+ throw recovery(
22
+ 'Bundled workflow content is missing from this package.',
23
+ `Expected ${descriptorPath} and ${filesRoot}. Reinstall @egawilldoit/factory; do not run the installer from a source checkout without building the bundle.`
24
+ );
25
+ }
26
+
27
+ let descriptor;
28
+ try {
29
+ descriptor = JSON.parse(fs.readFileSync(descriptorPath, 'utf8'));
30
+ } catch (err) {
31
+ throw recovery('Bundled descriptor is not valid JSON.', String(err));
32
+ }
33
+
34
+ if (!descriptor || descriptor.schemaVersion !== 1 ||
35
+ typeof descriptor.version !== 'string' ||
36
+ !Array.isArray(descriptor.files) || descriptor.files.length === 0) {
37
+ throw recovery('Bundled descriptor has an unsupported or malformed schema.', descriptorPath);
38
+ }
39
+
40
+ const fileMap = new Map();
41
+ for (const entry of descriptor.files) {
42
+ if (!entry || typeof entry.path !== 'string' || typeof entry.sha256 !== 'string') {
43
+ throw recovery('Bundled descriptor contains a malformed file entry.', descriptorPath);
44
+ }
45
+ const rel = entry.path;
46
+ if (!/^[A-Za-z0-9._/-]+$/.test(rel) || rel.includes('..') ||
47
+ path.isAbsolute(rel) || rel.startsWith('/') || /^[A-Za-z]:/.test(rel) || rel.includes('\\')) {
48
+ throw recovery('Bundled descriptor contains an unsafe file path.', rel);
49
+ }
50
+ if (fileMap.has(rel)) {
51
+ throw recovery('Bundled descriptor contains a duplicate file path.', rel);
52
+ }
53
+ fileMap.set(rel, entry);
54
+ }
55
+
56
+ let pkg;
57
+ try {
58
+ pkg = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
59
+ } catch (_) {
60
+ pkg = {};
61
+ }
62
+ if (pkg.version && pkg.version !== descriptor.version) {
63
+ throw recovery(
64
+ 'Package version and bundled descriptor version disagree.',
65
+ `package.json=${pkg.version}, bundle version=${descriptor.version}. Rebuild the bundle before packing.`
66
+ );
67
+ }
68
+
69
+ return {
70
+ descriptor,
71
+ filesRoot,
72
+ version: descriptor.version,
73
+ sourceCommit: descriptor.sourceCommit || 'unknown',
74
+ fileMap,
75
+ };
76
+ }
77
+
78
+ function verifyBundle(bundle) {
79
+ const issues = [];
80
+ for (const entry of bundle.descriptor.files) {
81
+ const p = path.join(bundle.filesRoot, entry.path);
82
+ if (!fsu.isFile(p)) {
83
+ issues.push({ path: entry.path, kind: 'missing' });
84
+ continue;
85
+ }
86
+ const actual = fsu.sha256File(p);
87
+ if (actual !== entry.sha256) {
88
+ issues.push({ path: entry.path, kind: 'hash', expected: entry.sha256, actual });
89
+ }
90
+ }
91
+ return issues;
92
+ }
93
+
94
+ function assertBundle(bundle) {
95
+ const issues = verifyBundle(bundle);
96
+ if (issues.length) {
97
+ throw recovery(
98
+ 'Bundled workflow content failed its own integrity check.',
99
+ JSON.stringify(issues.slice(0, 10), null, 2)
100
+ );
101
+ }
102
+ }
103
+
104
+ module.exports = { loadBundle, verifyBundle, assertBundle, BUNDLE_DIR, DESCRIPTOR, FILES_DIR };
package/lib/cli.js ADDED
@@ -0,0 +1,173 @@
1
+ 'use strict';
2
+
3
+ const pkg = require('../package.json');
4
+ const { HOSTS, EXIT, packageRoot } = require('./constants');
5
+ const { usage } = require('./errors');
6
+ const { loadBundle, assertBundle } = require('./bundle');
7
+ const { resolveDestination, makePaths, hostHint } = require('./paths');
8
+ const { install } = require('./install');
9
+ const { update } = require('./update');
10
+ const { diagnose } = require('./doctor');
11
+ const { rollback } = require('./rollback');
12
+ const { uninstall } = require('./uninstall');
13
+
14
+ const COMMANDS = ['install', 'update', 'doctor', 'rollback', 'uninstall'];
15
+
16
+ function parse(argv) {
17
+ const opts = { destination: null, host: null, json: false, help: false, version: false };
18
+ const positional = [];
19
+ for (let i = 0; i < argv.length; i++) {
20
+ const arg = argv[i];
21
+ if (arg === '--json') opts.json = true;
22
+ else if (arg === '--help' || arg === '-h') opts.help = true;
23
+ else if (arg === '--version' || arg === '-V') opts.version = true;
24
+ else if (arg === '--destination' || arg === '--host') {
25
+ const value = argv[++i];
26
+ if (!value) throw usage(`${arg} requires a value.`);
27
+ opts[arg.slice(2)] = value;
28
+ } else if (arg.startsWith('--destination=')) opts.destination = arg.slice('--destination='.length);
29
+ else if (arg.startsWith('--host=')) opts.host = arg.slice('--host='.length);
30
+ else if (arg.startsWith('-')) throw usage(`Unknown option: ${arg}`);
31
+ else positional.push(arg);
32
+ }
33
+ const command = positional.shift() || null;
34
+ if (opts.host && !HOSTS.includes(opts.host)) {
35
+ throw usage(`Unsupported --host ${opts.host}. Use one of: ${HOSTS.join(', ')}.`);
36
+ }
37
+ return { command, extra: positional, opts };
38
+ }
39
+
40
+ function helpText() {
41
+ return [
42
+ `@egawilldoit/factory ${pkg.version}`,
43
+ '',
44
+ 'Usage: factory <command> [options]',
45
+ '',
46
+ 'Commands:',
47
+ ' install Install the bundled skills into the shared Agent Skills directory',
48
+ ' update Update an owned installation using this package\'s bundle',
49
+ ' doctor Report registration, integrity and reference resolution',
50
+ ' rollback Restore the single previous working bundle',
51
+ ' uninstall Remove only files owned by this installation',
52
+ '',
53
+ 'Options:',
54
+ ' --destination <path> Bundle root (default: ~/.agents; skills go to <root>/skills)',
55
+ ' --host <codex|opencode> Advisory host label recorded in the manifest',
56
+ ' --json Emit a machine-readable JSON report',
57
+ ' -V, --version Print the package version',
58
+ ' -h, --help Show this help',
59
+ ].join('\n');
60
+ }
61
+
62
+ function formatText(report, command, opts) {
63
+ const lines = [];
64
+ lines.push(`@egawilldoit/factory ${pkg.version} - ${command || 'no command'}`);
65
+ lines.push('');
66
+ if (report.error) {
67
+ lines.push('FAILED: ' + report.error);
68
+ if (report.detail) lines.push('', String(report.detail));
69
+ lines.push('', `Exit code: ${report.code}`);
70
+ return lines.join('\n');
71
+ }
72
+ if (report.destination) lines.push('Destination: ' + report.destination);
73
+ if (report.version) lines.push('Version: ' + report.version);
74
+ if (report.installed) lines.push('Installed: ' + report.installed);
75
+ if (report.requested) lines.push('Requested: ' + report.requested);
76
+ if (report.from) lines.push(`Rollback: ${report.from} -> ${report.to}`);
77
+ if (report.removedVersion) lines.push('Removed version: ' + report.removedVersion);
78
+ if (report.sourceCommit) lines.push('Source commit: ' + report.sourceCommit);
79
+ if (report.recovery && report.recovery.recovered) {
80
+ lines.push('', 'Recovery: ' + report.recovery.message);
81
+ }
82
+ if (report.notes && report.notes.length) {
83
+ lines.push('');
84
+ for (const note of report.notes) lines.push('- ' + note);
85
+ }
86
+ if (command === 'doctor' && report.registration) {
87
+ lines.push('', 'Registration: ' + (report.registration.ok ? 'OK' : 'FAILED'));
88
+ if (report.registration.missing.length) {
89
+ lines.push(' Missing: ' + report.registration.missing.join(', '));
90
+ }
91
+ lines.push('Content integrity: ' + (report.integrity.ok ? 'OK' : `FAILED (${report.integrity.issues.length} issue(s))`));
92
+ lines.push('Reference resolution: ' + (report.references.ok ? 'OK' : `FAILED (${report.references.issues.length} issue(s))`));
93
+ lines.push('Path boundary: ' + (report.boundary.ok ? 'OK' : `UNSAFE (${report.boundary.issues.length} issue(s))`));
94
+ for (const issue of report.boundary.issues) {
95
+ lines.push(` ${issue.path}: ${issue.kind}`);
96
+ }
97
+ for (const issue of report.references.issues) {
98
+ lines.push(` ${issue.file}: ${issue.link} -> ${issue.kind}${issue.target ? ' (' + issue.target + ')' : ''}`);
99
+ }
100
+ for (const issue of report.integrity.issues) {
101
+ lines.push(` ${issue.path}: ${issue.kind}`);
102
+ }
103
+ if (report.recovery.hasStaging || report.recovery.lock || report.recovery.hasPending) {
104
+ const lockPid = report.recovery.lock ? report.recovery.lock.pid : 'unknown';
105
+ lines.push(`Stale-state markers present (lock pid ${lockPid}, staging ${report.recovery.hasStaging}, pending ${report.recovery.hasPending}).`);
106
+ }
107
+ }
108
+ lines.push('', report.ok ? 'OK' : 'FAILED');
109
+ return lines.join('\n');
110
+ }
111
+
112
+ function main(argv) {
113
+ let opts = {};
114
+ let command = null;
115
+ let report;
116
+ let exitCode = EXIT.OK;
117
+
118
+ try {
119
+ const parsed = parse(argv);
120
+ opts = parsed.opts;
121
+ command = parsed.command;
122
+
123
+ if (opts.help) {
124
+ report = { ok: true, output: helpText() };
125
+ } else if (opts.version) {
126
+ report = { ok: true, version: pkg.version };
127
+ } else if (!command || !COMMANDS.includes(command)) {
128
+ throw usage(`Command required. Use one of: ${COMMANDS.join(', ')}.`);
129
+ } else if (parsed.extra.length) {
130
+ throw usage(`Unexpected argument: ${parsed.extra[0]}`);
131
+ } else {
132
+ const bundle = loadBundle(packageRoot());
133
+ assertBundle(bundle);
134
+ const dest = resolveDestination(opts);
135
+ const paths = makePaths(dest);
136
+
137
+ if (command === 'install') report = install({ paths, bundle, opts });
138
+ else if (command === 'update') report = update({ paths, bundle, opts });
139
+ else if (command === 'rollback') report = rollback({ paths });
140
+ else if (command === 'uninstall') report = uninstall({ paths });
141
+ else report = diagnose(paths);
142
+
143
+ if (command !== 'doctor' && paths.dest) {
144
+ report.notes = report.notes || [];
145
+ report.notes.push(hostHint(opts.host, paths.skillsRoot, paths.dest));
146
+ }
147
+ report.destination = paths.dest;
148
+ exitCode = report.exitCode || (report.ok ? EXIT.OK : EXIT.INTEGRITY);
149
+ }
150
+ } catch (err) {
151
+ exitCode = Number.isInteger(err.code) ? err.code : EXIT.IO;
152
+ report = {
153
+ ok: false,
154
+ error: err.message,
155
+ detail: err.detail || null,
156
+ code: exitCode,
157
+ };
158
+ }
159
+
160
+ if (opts.json) {
161
+ process.stdout.write(JSON.stringify({ command, ok: report.ok, ...report }, null, 2) + '\n');
162
+ } else if (report.output) {
163
+ process.stdout.write(report.output + '\n');
164
+ } else if (report.version && command === null) {
165
+ process.stdout.write(report.version + '\n');
166
+ } else {
167
+ process.stdout.write(formatText(report, command, opts) + '\n');
168
+ }
169
+
170
+ process.exitCode = exitCode;
171
+ }
172
+
173
+ module.exports = { main, parse, helpText };
@@ -0,0 +1,49 @@
1
+ 'use strict';
2
+
3
+ const path = require('path');
4
+
5
+ // Bundle-root relative layout. These names are part of the published contract:
6
+ // skills/<name>/SKILL.md uses ../../references, ../../docs and ../../templates,
7
+ // so skills, references, docs and templates must stay siblings under the root.
8
+ const SKILL_NAMES = [
9
+ 'factory',
10
+ 'factory-plan',
11
+ 'factory-verify',
12
+ 'factory-improve',
13
+ ];
14
+
15
+ const META_DIR = '.ega-factory';
16
+ const PRESERVED_DIR = '.factory-preserved';
17
+ const HOSTS = ['codex', 'opencode'];
18
+
19
+ const EXIT = {
20
+ OK: 0,
21
+ USAGE: 1,
22
+ REFUSED: 2,
23
+ INTEGRITY: 3,
24
+ RECOVERY: 4,
25
+ IO: 5,
26
+ };
27
+
28
+ function packageRoot() {
29
+ // lib/ sits directly under the package root in the packed artifact.
30
+ return path.resolve(__dirname, '..');
31
+ }
32
+
33
+ function defaultDestination() {
34
+ // The bundle root lives at ~/.agents; the shared Agent Skills directory is
35
+ // <destination>/skills (i.e. ~/.agents/skills by default).
36
+ const home = process.env.HOME || process.env.USERPROFILE;
37
+ if (!home) return null;
38
+ return path.join(home, '.agents');
39
+ }
40
+
41
+ module.exports = {
42
+ SKILL_NAMES,
43
+ META_DIR,
44
+ PRESERVED_DIR,
45
+ HOSTS,
46
+ EXIT,
47
+ packageRoot,
48
+ defaultDestination,
49
+ };
package/lib/doctor.js ADDED
@@ -0,0 +1,72 @@
1
+ 'use strict';
2
+
3
+ const fsu = require('./fs-util');
4
+ const { readManifest } = require('./manifest');
5
+ const { checkInstalledIntegrity, inspectRecoveryState } = require('./recovery');
6
+ const { checkReferences } = require('./references');
7
+ const path = require('path');
8
+ const { installedPath, hostHint } = require('./paths');
9
+ const { symlinkWithin, metaTargets } = require('./boundary');
10
+
11
+ function diagnose(paths) {
12
+ const manifest = readManifest(paths);
13
+ const recoveryState = inspectRecoveryState(paths);
14
+ if (!manifest) {
15
+ return {
16
+ installed: false,
17
+ ok: false,
18
+ destination: paths.dest,
19
+ notes: [
20
+ 'No installation manifest found at ' + paths.manifestPath + '.',
21
+ 'Run install first. Host discovery and UI invocation are not checked by doctor.',
22
+ ],
23
+ recovery: recoveryState,
24
+ };
25
+ }
26
+
27
+ const missing = [];
28
+ for (const rel of Object.keys(manifest.files)) {
29
+ if (!fsu.isFile(installedPath(paths, rel))) missing.push(rel);
30
+ }
31
+ const registrationOk = missing.length === 0 && fsu.isDirectory(paths.skillsRoot);
32
+
33
+ const integrity = checkInstalledIntegrity(paths, manifest);
34
+ const referenceIssues = checkReferences(paths.dest, Object.keys(manifest.files));
35
+
36
+ // Doctor is read-only: report unsafe symlinks instead of refusing outright.
37
+ const boundaryIssues = [];
38
+ for (const target of metaTargets(paths)) {
39
+ const link = symlinkWithin(paths.dest, target);
40
+ if (link) boundaryIssues.push({ path: path.relative(paths.dest, link), kind: 'metadata symlink' });
41
+ }
42
+ for (const rel of Object.keys(manifest.files)) {
43
+ const link = symlinkWithin(paths.dest, installedPath(paths, rel));
44
+ if (link) boundaryIssues.push({ path: rel, kind: 'managed symlink' });
45
+ }
46
+
47
+ return {
48
+ installed: true,
49
+ ok: registrationOk && integrity.ok && referenceIssues.length === 0 && boundaryIssues.length === 0,
50
+ destination: paths.dest,
51
+ version: manifest.version,
52
+ sourceCommit: manifest.sourceCommit,
53
+ host: manifest.host,
54
+ skillsRoot: paths.skillsRoot,
55
+ registration: {
56
+ ok: registrationOk,
57
+ missing,
58
+ skillsRootPresent: fsu.isDirectory(paths.skillsRoot),
59
+ },
60
+ integrity,
61
+ references: { ok: referenceIssues.length === 0, issues: referenceIssues },
62
+ boundary: { ok: boundaryIssues.length === 0, issues: boundaryIssues },
63
+ recovery: recoveryState,
64
+ notes: [
65
+ 'Filesystem registration, content integrity and reference resolution are reported separately.',
66
+ hostHint(manifest.host, paths.skillsRoot, paths.dest),
67
+ 'Actual host discovery and UI invocation are NOT verified here; check them in a fresh host session.',
68
+ ],
69
+ };
70
+ }
71
+
72
+ module.exports = { diagnose };
package/lib/errors.js ADDED
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ const { EXIT } = require('./constants');
4
+
5
+ class FactoryError extends Error {
6
+ constructor(message, code, detail) {
7
+ super(message);
8
+ this.name = 'FactoryError';
9
+ this.code = code || EXIT.IO;
10
+ this.detail = detail || null;
11
+ }
12
+ }
13
+
14
+ function refuse(message, detail) {
15
+ return new FactoryError(message, EXIT.REFUSED, detail);
16
+ }
17
+
18
+ function integrity(message, detail) {
19
+ return new FactoryError(message, EXIT.INTEGRITY, detail);
20
+ }
21
+
22
+ function recovery(message, detail) {
23
+ return new FactoryError(message, EXIT.RECOVERY, detail);
24
+ }
25
+
26
+ function usage(message, detail) {
27
+ return new FactoryError(message, EXIT.USAGE, detail);
28
+ }
29
+
30
+ module.exports = { FactoryError, refuse, integrity, recovery, usage };