farna-bootstrapper 0.0.0-stage → 0.1.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 (80) hide show
  1. package/CHANGELOG.md +91 -0
  2. package/LICENSE +30 -0
  3. package/NOTICE +42 -0
  4. package/README.md +1079 -2
  5. package/SECURITY.md +65 -0
  6. package/dist/cli/commands/check.d.ts +58 -0
  7. package/dist/cli/commands/check.js +198 -0
  8. package/dist/cli/commands/generate.d.ts +75 -0
  9. package/dist/cli/commands/generate.js +218 -0
  10. package/dist/cli/commands/init.d.ts +52 -0
  11. package/dist/cli/commands/init.js +271 -0
  12. package/dist/cli/main.d.ts +2 -0
  13. package/dist/cli/main.js +51 -0
  14. package/dist/cli/program.d.ts +23 -0
  15. package/dist/cli/program.js +183 -0
  16. package/dist/compose/resolve.d.ts +154 -0
  17. package/dist/compose/resolve.js +545 -0
  18. package/dist/config/load.d.ts +4 -0
  19. package/dist/config/load.js +45 -0
  20. package/dist/config/schema.d.ts +22 -0
  21. package/dist/config/schema.js +46 -0
  22. package/dist/core/constants.d.ts +268 -0
  23. package/dist/core/constants.js +336 -0
  24. package/dist/core/errors.d.ts +44 -0
  25. package/dist/core/errors.js +75 -0
  26. package/dist/core/fs.d.ts +31 -0
  27. package/dist/core/fs.js +169 -0
  28. package/dist/core/json.d.ts +22 -0
  29. package/dist/core/json.js +174 -0
  30. package/dist/core/paths.d.ts +45 -0
  31. package/dist/core/paths.js +110 -0
  32. package/dist/core/text.d.ts +10 -0
  33. package/dist/core/text.js +27 -0
  34. package/dist/index.d.ts +10 -0
  35. package/dist/index.js +1 -0
  36. package/dist/lock/lockfile.d.ts +229 -0
  37. package/dist/lock/lockfile.js +333 -0
  38. package/dist/materialise/source-tree.d.ts +77 -0
  39. package/dist/materialise/source-tree.js +264 -0
  40. package/dist/permissions/permissions.d.ts +128 -0
  41. package/dist/permissions/permissions.js +452 -0
  42. package/dist/render/commit.d.ts +59 -0
  43. package/dist/render/commit.js +279 -0
  44. package/dist/render/generate-lock.d.ts +9 -0
  45. package/dist/render/generate-lock.js +203 -0
  46. package/dist/render/identity.d.ts +23 -0
  47. package/dist/render/identity.js +396 -0
  48. package/dist/render/orphans.d.ts +59 -0
  49. package/dist/render/orphans.js +234 -0
  50. package/dist/render/port.d.ts +96 -0
  51. package/dist/render/port.js +1 -0
  52. package/dist/render/prepare.d.ts +33 -0
  53. package/dist/render/prepare.js +139 -0
  54. package/dist/render/root-cleanliness.d.ts +28 -0
  55. package/dist/render/root-cleanliness.js +76 -0
  56. package/dist/render/stage.d.ts +36 -0
  57. package/dist/render/stage.js +92 -0
  58. package/dist/render/staging.d.ts +16 -0
  59. package/dist/render/staging.js +94 -0
  60. package/dist/render/structured.d.ts +35 -0
  61. package/dist/render/structured.js +258 -0
  62. package/dist/render/upstream.d.ts +41 -0
  63. package/dist/render/upstream.js +179 -0
  64. package/dist/report/format.d.ts +7 -0
  65. package/dist/report/format.js +97 -0
  66. package/dist/report/warnings.d.ts +21 -0
  67. package/dist/report/warnings.js +24 -0
  68. package/dist/source/digest.d.ts +18 -0
  69. package/dist/source/digest.js +77 -0
  70. package/dist/source/frontmatter.d.ts +12 -0
  71. package/dist/source/frontmatter.js +29 -0
  72. package/dist/source/load.d.ts +103 -0
  73. package/dist/source/load.js +676 -0
  74. package/dist/source/schema.d.ts +149 -0
  75. package/dist/source/schema.js +283 -0
  76. package/dist/source/yaml.d.ts +10 -0
  77. package/dist/source/yaml.js +49 -0
  78. package/dist/verify/containment.d.ts +22 -0
  79. package/dist/verify/containment.js +753 -0
  80. package/package.json +79 -4
@@ -0,0 +1,77 @@
1
+ import { readdir } from 'node:fs/promises';
2
+ import { join } from 'node:path';
3
+ import { CONFIG_PATH, isOsMetadataName, MANAGED_FILE_MAX_BYTES, PERSONAS_DIR, RESOURCES_DIR, ROOT_DIR, } from '../core/constants.js';
4
+ import { pathUnsafe } from '../core/errors.js';
5
+ import { readBoundedBytes } from '../core/fs.js';
6
+ import { canonicalJson, compareCodepoints, sha256Hex } from '../core/json.js';
7
+ const SOURCE_DIRECTORIES = [`${ROOT_DIR}/${PERSONAS_DIR}`, `${ROOT_DIR}/${RESOURCES_DIR}`];
8
+ async function listSourceFiles(repoRoot, directory, collected) {
9
+ let entries;
10
+ try {
11
+ entries = await readdir(join(repoRoot, directory), { withFileTypes: true });
12
+ }
13
+ catch (error) {
14
+ if (error instanceof Error && 'code' in error && error.code === 'ENOENT') {
15
+ return;
16
+ }
17
+ throw pathUnsafe(`cannot read ${directory}`, {
18
+ subject: directory,
19
+ action: 'make the source directory readable and re-run',
20
+ cause: error,
21
+ });
22
+ }
23
+ for (const entry of entries.sort((a, b) => compareCodepoints(a.name, b.name))) {
24
+ if (isOsMetadataName(entry.name)) {
25
+ continue;
26
+ }
27
+ const path = `${directory}/${entry.name}`;
28
+ if (entry.isSymbolicLink()) {
29
+ throw pathUnsafe(`symlink not allowed: ${path}`, {
30
+ subject: path,
31
+ action: 'replace the symbolic link with a real file or directory',
32
+ });
33
+ }
34
+ if (entry.isDirectory()) {
35
+ await listSourceFiles(repoRoot, path, collected);
36
+ continue;
37
+ }
38
+ if (entry.isFile()) {
39
+ collected.push(path);
40
+ }
41
+ }
42
+ }
43
+ /**
44
+ * A digest over the **raw** config bytes, the parsed config and **every**
45
+ * persona and resource file, including the ones that are not live in the
46
+ * current mode.
47
+ *
48
+ * Without it `check` could not see a change to a non-live persona's
49
+ * declaration: profile mode resolves every persona but renders only the active
50
+ * one, so editing the inactive persona's rule changed no managed byte. The
51
+ * digest makes that edit visible as drift, which is what "every declaration is
52
+ * validated" already promised.
53
+ *
54
+ * The raw config bytes are hashed as well as the parsed value: a comment or
55
+ * whitespace edit in `config.jsonc` changes the committed source but not the
56
+ * parsed object. Hashing the raw bytes makes it drift, exactly like a comment
57
+ * edit in a persona file (whose whole bytes are hashed below).
58
+ */
59
+ export async function sourceConfigDigest(repoRoot, config) {
60
+ const configBytes = await readBoundedBytes(join(repoRoot, CONFIG_PATH), CONFIG_PATH, {
61
+ action: 'make the config readable and re-run',
62
+ maxBytes: MANAGED_FILE_MAX_BYTES,
63
+ });
64
+ const files = [];
65
+ for (const directory of SOURCE_DIRECTORIES) {
66
+ await listSourceFiles(repoRoot, directory, files);
67
+ }
68
+ const entries = [];
69
+ for (const path of files.sort(compareCodepoints)) {
70
+ const bytes = await readBoundedBytes(join(repoRoot, path), path, {
71
+ action: 'make the source file readable and re-run',
72
+ maxBytes: MANAGED_FILE_MAX_BYTES,
73
+ });
74
+ entries.push({ path, sha256: sha256Hex(bytes) });
75
+ }
76
+ return sha256Hex(canonicalJson({ configRawSha256: sha256Hex(configBytes), config, files: entries }));
77
+ }
@@ -0,0 +1,12 @@
1
+ export type Frontmatter = {
2
+ /** The raw frontmatter text between the delimiters. */
3
+ text: string;
4
+ /** Everything after the closing delimiter line, byte for byte (LF-normalised). */
5
+ body: string;
6
+ };
7
+ /**
8
+ * Split a markdown file with YAML frontmatter. The frontmatter block must be
9
+ * the first bytes of the file; CRLF is normalised before parsing. The body is
10
+ * never trimmed.
11
+ */
12
+ export declare function splitFrontmatter(source: string, subject: string): Frontmatter;
@@ -0,0 +1,29 @@
1
+ import { invalidConfig } from '../core/errors.js';
2
+ const OPEN = '---\n';
3
+ const CLOSE = /^---[ \t]*$/m;
4
+ /**
5
+ * Split a markdown file with YAML frontmatter. The frontmatter block must be
6
+ * the first bytes of the file; CRLF is normalised before parsing. The body is
7
+ * never trimmed.
8
+ */
9
+ export function splitFrontmatter(source, subject) {
10
+ const text = source.replace(/\r\n/g, '\n');
11
+ if (!text.startsWith(OPEN)) {
12
+ throw invalidConfig('file must start with a "---" frontmatter block', {
13
+ subject,
14
+ action: 'put the YAML frontmatter on the first line, with no leading blank line',
15
+ });
16
+ }
17
+ const rest = text.slice(OPEN.length);
18
+ const match = CLOSE.exec(rest);
19
+ if (match === null || match.index === undefined) {
20
+ throw invalidConfig('frontmatter block is not closed', {
21
+ subject,
22
+ action: 'add a closing "---" line',
23
+ });
24
+ }
25
+ const frontmatterText = rest.slice(0, match.index);
26
+ const afterClose = rest.indexOf('\n', match.index);
27
+ const body = afterClose === -1 ? '' : rest.slice(afterClose + 1);
28
+ return { text: frontmatterText, body };
29
+ }
@@ -0,0 +1,103 @@
1
+ import type { WarningCode } from '../core/constants.js';
2
+ import { type HookDeclaration, type McpServerDeclaration, type PermissionDeclaration, type PersonaDeclaration } from './schema.js';
3
+ export type RuleResource = {
4
+ kind: 'rule';
5
+ id: string;
6
+ displayName: string;
7
+ body: string;
8
+ /** Repository-relative path, for messages. */
9
+ path: string;
10
+ };
11
+ export type PermissionResource = PermissionDeclaration & {
12
+ /** True when the resource opts its persona into Claude Code's `tools` allow-list. */
13
+ allowlist: boolean;
14
+ /** Repository-relative path, for messages. */
15
+ path: string;
16
+ };
17
+ /**
18
+ * One extra file carried inside a skill directory. Content is strict UTF-8
19
+ * text: the managed-output pipeline compares and writes text, and decoding then
20
+ * re-encoding a valid UTF-8 file is byte-identical. A non-UTF-8 asset is refused
21
+ * (F001) rather than silently corrupted.
22
+ */
23
+ export type SkillFile = {
24
+ /** Path relative to the skill directory, POSIX-spelled. */
25
+ path: string;
26
+ text: string;
27
+ };
28
+ export type CommandResource = {
29
+ kind: 'command';
30
+ id: string;
31
+ description: string;
32
+ body: string;
33
+ /** Repository-relative path, for messages. */
34
+ path: string;
35
+ /** Content digest, for duplicate-id detection. */
36
+ sha256: string;
37
+ };
38
+ export type SkillResource = {
39
+ kind: 'skill';
40
+ id: string;
41
+ description: string;
42
+ body: string;
43
+ /** `SKILL.md` plus every other file, sorted by path. */
44
+ files: SkillFile[];
45
+ /** Repository-relative path of `SKILL.md`, for messages. */
46
+ path: string;
47
+ /** Content digest, for duplicate-id detection. */
48
+ sha256: string;
49
+ };
50
+ export type McpResource = {
51
+ kind: 'mcp';
52
+ id: string;
53
+ server: McpServerDeclaration;
54
+ /** Repository-relative path, for messages. */
55
+ path: string;
56
+ /** Content digest, for duplicate-id detection. */
57
+ sha256: string;
58
+ };
59
+ export type HookResource = {
60
+ kind: 'hook';
61
+ id: string;
62
+ phase: HookDeclaration['phase'];
63
+ matcher?: string;
64
+ command: string;
65
+ /** Repository-relative path, for messages. */
66
+ path: string;
67
+ /** Content digest, for duplicate-id detection. */
68
+ sha256: string;
69
+ };
70
+ export type LoadedPersona = PersonaDeclaration & {
71
+ /** Repository-relative path, for messages. */
72
+ path: string;
73
+ };
74
+ /**
75
+ * A warning derived while reading a source file, before a persona or target is
76
+ * known. `resolveSource` stamps it with the standard source subject and the
77
+ * configured target, so a lockfile record is still shaped like every other
78
+ * warning. The only member today is W115, declared on an MCP URL.
79
+ */
80
+ export type SourceWarning = {
81
+ code: WarningCode;
82
+ capability?: 'mcp';
83
+ message: string;
84
+ };
85
+ export type SourceTree = {
86
+ warnings: SourceWarning[];
87
+ personas: LoadedPersona[];
88
+ rules: RuleResource[];
89
+ permissions: PermissionResource[];
90
+ mcp: McpResource[];
91
+ skills: SkillResource[];
92
+ commands: CommandResource[];
93
+ hooks: HookResource[];
94
+ };
95
+ /**
96
+ * Whether a literal argument looks like a credential rather than a flag or a
97
+ * path. Deliberately conservative in the "looks like" direction: a false
98
+ * positive costs a warning the author can silence by using a reference, while a
99
+ * false negative writes a secret into a committed file.
100
+ */
101
+ export declare function looksSecretShaped(value: string): boolean;
102
+ /** Enumerate and parse the whole source tree. A file that is present but unparsed is an error. */
103
+ export declare function loadSource(repoRoot: string): Promise<SourceTree>;