egehan 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 (85) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +79 -2
  3. package/assets/dictionary/narratives.en.json +660 -0
  4. package/assets/dictionary/narratives.tr.json +660 -0
  5. package/assets/schema/egehan-report.schema.json +354 -0
  6. package/assets/spec/rules.json +272 -0
  7. package/assets/templates/egehan-book.html +2027 -0
  8. package/assets/templates/hook.sh +41 -0
  9. package/dist/artifacts.d.ts +21 -0
  10. package/dist/artifacts.js +32 -0
  11. package/dist/capsule/capsule.d.ts +35 -0
  12. package/dist/capsule/capsule.js +123 -0
  13. package/dist/capsule/storage.d.ts +15 -0
  14. package/dist/capsule/storage.js +52 -0
  15. package/dist/cli/commands/capsule.d.ts +20 -0
  16. package/dist/cli/commands/capsule.js +94 -0
  17. package/dist/cli/commands/generate.d.ts +23 -0
  18. package/dist/cli/commands/generate.js +47 -0
  19. package/dist/cli/commands/hook.d.ts +14 -0
  20. package/dist/cli/commands/hook.js +120 -0
  21. package/dist/cli/commands/init.d.ts +16 -0
  22. package/dist/cli/commands/init.js +92 -0
  23. package/dist/cli/commands/stats.d.ts +14 -0
  24. package/dist/cli/commands/stats.js +112 -0
  25. package/dist/cli/main.d.ts +3 -0
  26. package/dist/cli/main.js +167 -0
  27. package/dist/cli/output.d.ts +26 -0
  28. package/dist/cli/output.js +87 -0
  29. package/dist/cli/prompt.d.ts +21 -0
  30. package/dist/cli/prompt.js +63 -0
  31. package/dist/config/config.d.ts +51 -0
  32. package/dist/config/config.js +160 -0
  33. package/dist/detect/projectType.d.ts +34 -0
  34. package/dist/detect/projectType.js +95 -0
  35. package/dist/engine/buildReport.d.ts +32 -0
  36. package/dist/engine/buildReport.js +188 -0
  37. package/dist/engine/chapters.d.ts +20 -0
  38. package/dist/engine/chapters.js +33 -0
  39. package/dist/engine/classifier.d.ts +21 -0
  40. package/dist/engine/classifier.js +119 -0
  41. package/dist/engine/conventional.d.ts +15 -0
  42. package/dist/engine/conventional.js +137 -0
  43. package/dist/engine/datetime.d.ts +47 -0
  44. package/dist/engine/datetime.js +100 -0
  45. package/dist/engine/milestones.d.ts +6 -0
  46. package/dist/engine/milestones.js +109 -0
  47. package/dist/engine/narrator.d.ts +71 -0
  48. package/dist/engine/narrator.js +189 -0
  49. package/dist/engine/prepare.d.ts +36 -0
  50. package/dist/engine/prepare.js +46 -0
  51. package/dist/engine/privacy.d.ts +45 -0
  52. package/dist/engine/privacy.js +110 -0
  53. package/dist/engine/pulse.d.ts +17 -0
  54. package/dist/engine/pulse.js +205 -0
  55. package/dist/engine/templating.d.ts +40 -0
  56. package/dist/engine/templating.js +64 -0
  57. package/dist/engine/types.d.ts +205 -0
  58. package/dist/engine/types.js +9 -0
  59. package/dist/git/logReader.d.ts +37 -0
  60. package/dist/git/logReader.js +133 -0
  61. package/dist/git/repository.d.ts +14 -0
  62. package/dist/git/repository.js +61 -0
  63. package/dist/git/runGit.d.ts +21 -0
  64. package/dist/git/runGit.js +74 -0
  65. package/dist/hooks/block.d.ts +27 -0
  66. package/dist/hooks/block.js +62 -0
  67. package/dist/hooks/manager.d.ts +47 -0
  68. package/dist/hooks/manager.js +153 -0
  69. package/dist/index.d.ts +34 -0
  70. package/dist/index.js +26 -0
  71. package/dist/pipeline.d.ts +35 -0
  72. package/dist/pipeline.js +80 -0
  73. package/dist/renderers/html.d.ts +6 -0
  74. package/dist/renderers/html.js +117 -0
  75. package/dist/renderers/markdown.d.ts +4 -0
  76. package/dist/renderers/markdown.js +168 -0
  77. package/dist/spec/assets.d.ts +14 -0
  78. package/dist/spec/assets.js +98 -0
  79. package/dist/spec/dictionary.d.ts +100 -0
  80. package/dist/spec/dictionary.js +39 -0
  81. package/dist/spec/rules.d.ts +191 -0
  82. package/dist/spec/rules.js +15 -0
  83. package/dist/version.d.ts +2 -0
  84. package/dist/version.js +20 -0
  85. package/package.json +55 -4
@@ -0,0 +1,41 @@
1
+ # >>> egehan >>>
2
+ # Added by Egehan {version} — `egehan hook install`. Everything between these markers is
3
+ # rewritten on the next install and removed by `egehan hook uninstall`, so edit outside them.
4
+ #
5
+ # This block never writes to the repository: no `git add`, no `git commit`, no `git stash`.
6
+ # It regenerates the chronicle in the background and returns, so `git {verb}` never waits for it.
7
+ egehan_chronicle() {
8
+ # Guard against recursion and give people a documented way to switch it off for one command.
9
+ if [ -n "$EGEHAN_HOOK" ] || [ -n "$EGEHAN_SKIP_HOOK" ]; then
10
+ return 0
11
+ fi
12
+
13
+ egehan_git_dir=$(git rev-parse --git-dir 2>/dev/null) || return 0
14
+
15
+ # Mid-operation states: a rebase replays many commits, and each one would fire this hook.
16
+ for egehan_state in rebase-merge rebase-apply MERGE_HEAD CHERRY_PICK_HEAD REVERT_HEAD BISECT_LOG; do
17
+ if [ -e "$egehan_git_dir/$egehan_state" ]; then
18
+ return 0
19
+ fi
20
+ done
21
+
22
+ egehan_root=$(git rev-parse --show-toplevel 2>/dev/null) || return 0
23
+
24
+ if [ -x "$egehan_root/node_modules/.bin/egehan" ]; then
25
+ egehan_bin="$egehan_root/node_modules/.bin/egehan"
26
+ elif command -v egehan >/dev/null 2>&1; then
27
+ egehan_bin=egehan
28
+ else
29
+ # Not installed on this machine: stay silent rather than nag on every commit.
30
+ return 0
31
+ fi
32
+
33
+ (
34
+ EGEHAN_HOOK=1 "$egehan_bin" generate --quiet >/dev/null 2>&1 </dev/null &
35
+ ) >/dev/null 2>&1
36
+
37
+ return 0
38
+ }
39
+
40
+ egehan_chronicle
41
+ # <<< egehan <<<
@@ -0,0 +1,21 @@
1
+ import type { Dictionary } from './spec/dictionary.js';
2
+ import type { EgehanRules } from './spec/rules.js';
3
+ import type { EgehanReport } from './engine/types.js';
4
+ /**
5
+ * Writing the chronicle to disk.
6
+ *
7
+ * Shared by the CLI and by the IDE extensions on purpose. The whole project rests on the file a
8
+ * git hook writes and the file an editor command writes being the same file; two copies of this
9
+ * function would be two chances for them to stop being so.
10
+ */
11
+ export type ArtifactFormat = 'md' | 'html' | 'json' | 'both' | 'all';
12
+ export interface WriteArtifactsOptions {
13
+ readonly report: EgehanReport;
14
+ readonly dictionary: Dictionary;
15
+ readonly rules: EgehanRules;
16
+ readonly outputDirectory: string;
17
+ readonly format: ArtifactFormat;
18
+ }
19
+ /** Returns the absolute paths written, in a stable order. */
20
+ export declare function writeArtifacts(options: WriteArtifactsOptions): string[];
21
+ //# sourceMappingURL=artifacts.d.ts.map
@@ -0,0 +1,32 @@
1
+ import { mkdirSync, writeFileSync } from 'node:fs';
2
+ import { isAbsolute, join, resolve } from 'node:path';
3
+ import { renderHtml } from './renderers/html.js';
4
+ import { renderMarkdown } from './renderers/markdown.js';
5
+ /** Returns the absolute paths written, in a stable order. */
6
+ export function writeArtifacts(options) {
7
+ const { report, dictionary, rules, format } = options;
8
+ const directory = isAbsolute(options.outputDirectory)
9
+ ? options.outputDirectory
10
+ : resolve(options.outputDirectory);
11
+ mkdirSync(directory, { recursive: true });
12
+ // `both` is the pair a project keeps; the JSON report is the machine format and stays opt-in.
13
+ const wants = (candidate) => format === candidate || format === 'all' || (format === 'both' && candidate !== 'json');
14
+ const written = [];
15
+ if (wants('md')) {
16
+ const path = join(directory, rules.output.markdownFileName);
17
+ writeFileSync(path, renderMarkdown(report, dictionary), 'utf8');
18
+ written.push(path);
19
+ }
20
+ if (wants('html')) {
21
+ const path = join(directory, rules.output.htmlFileName);
22
+ writeFileSync(path, renderHtml(report, dictionary, rules), 'utf8');
23
+ written.push(path);
24
+ }
25
+ if (wants('json')) {
26
+ const path = join(directory, rules.output.reportFileName);
27
+ writeFileSync(path, `${JSON.stringify(report, null, 2)}\n`, 'utf8');
28
+ written.push(path);
29
+ }
30
+ return written;
31
+ }
32
+ //# sourceMappingURL=artifacts.js.map
@@ -0,0 +1,35 @@
1
+ import type { EgehanRules } from '../spec/rules.js';
2
+ import type { SealedCapsule } from '../engine/types.js';
3
+ /**
4
+ * The sealed time capsule.
5
+ *
6
+ * One mode exists, and the reason is worth stating plainly: the ciphertext is embedded in an HTML
7
+ * file people publish. Anything that file can decrypt on its own, every reader can decrypt too, so
8
+ * a "no passphrase, just a date" capsule would advertise encryption while providing none. The
9
+ * countdown in the timeline is a ritual; the passphrase is the lock (docs/ARCHITECTURE.md, ADR-005).
10
+ *
11
+ * PBKDF2 is not the strongest KDF available in Node — scrypt and Argon2 both resist hardware
12
+ * better. It is chosen because the capsule must also open in a browser, from the generated file,
13
+ * with no dependencies, and Web Crypto offers PBKDF2 and neither of the others. The iteration
14
+ * count in `rules.json` compensates within that constraint.
15
+ *
16
+ * Every parameter comes from the rules file so the .NET engine produces capsules this engine — and
17
+ * the page — can open.
18
+ */
19
+ export declare class CapsuleError extends Error {
20
+ constructor(message: string);
21
+ }
22
+ export interface SealInput {
23
+ readonly message: string;
24
+ /** `YYYY-MM-DD`. Presentational: it drives the countdown, never the decryption. */
25
+ readonly unlockDate: string;
26
+ readonly passphrase: string;
27
+ readonly authorLabel: string | null;
28
+ readonly hint: string | null;
29
+ readonly createdAt: string;
30
+ }
31
+ export declare function sealCapsule(input: SealInput, rules: EgehanRules): SealedCapsule;
32
+ export declare function openCapsule(capsule: SealedCapsule, passphrase: string, rules: EgehanRules): string;
33
+ /** Constant-time comparison for the confirmation prompt, so a typo check leaks no timing. */
34
+ export declare function passphrasesMatch(first: string, second: string): boolean;
35
+ //# sourceMappingURL=capsule.d.ts.map
@@ -0,0 +1,123 @@
1
+ import { createCipheriv, createDecipheriv, pbkdf2Sync, randomBytes, timingSafeEqual } from 'node:crypto';
2
+ /**
3
+ * The sealed time capsule.
4
+ *
5
+ * One mode exists, and the reason is worth stating plainly: the ciphertext is embedded in an HTML
6
+ * file people publish. Anything that file can decrypt on its own, every reader can decrypt too, so
7
+ * a "no passphrase, just a date" capsule would advertise encryption while providing none. The
8
+ * countdown in the timeline is a ritual; the passphrase is the lock (docs/ARCHITECTURE.md, ADR-005).
9
+ *
10
+ * PBKDF2 is not the strongest KDF available in Node — scrypt and Argon2 both resist hardware
11
+ * better. It is chosen because the capsule must also open in a browser, from the generated file,
12
+ * with no dependencies, and Web Crypto offers PBKDF2 and neither of the others. The iteration
13
+ * count in `rules.json` compensates within that constraint.
14
+ *
15
+ * Every parameter comes from the rules file so the .NET engine produces capsules this engine — and
16
+ * the page — can open.
17
+ */
18
+ export class CapsuleError extends Error {
19
+ constructor(message) {
20
+ super(message);
21
+ this.name = 'CapsuleError';
22
+ }
23
+ }
24
+ const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}$/;
25
+ export function sealCapsule(input, rules) {
26
+ const spec = rules.capsule;
27
+ validateUnlockDate(input.unlockDate);
28
+ validatePassphrase(input.passphrase, spec.minPassphraseLength);
29
+ if (input.message.trim() === '') {
30
+ throw new CapsuleError('There is no message to seal.');
31
+ }
32
+ const salt = randomBytes(spec.saltBytes);
33
+ const iv = randomBytes(spec.ivBytes);
34
+ const key = deriveKey(input.passphrase, salt, rules);
35
+ const cipher = createCipheriv('aes-256-gcm', key, iv, { authTagLength: spec.authTagBits / 8 });
36
+ cipher.setAAD(Buffer.from(additionalData(input.unlockDate, rules), 'utf8'));
37
+ const body = Buffer.concat([cipher.update(input.message, 'utf8'), cipher.final()]);
38
+ // Web Crypto expects the authentication tag appended to the ciphertext; Node hands it over
39
+ // separately. Concatenating here is what makes the browser able to open what Node sealed.
40
+ const ciphertext = Buffer.concat([body, cipher.getAuthTag()]);
41
+ return {
42
+ mode: 'sealed',
43
+ unlockDate: input.unlockDate,
44
+ authorLabel: emptyToNull(input.authorLabel),
45
+ hint: emptyToNull(input.hint),
46
+ algorithm: {
47
+ kdf: 'PBKDF2',
48
+ kdfHash: 'SHA-256',
49
+ iterations: spec.iterations,
50
+ cipher: 'AES-256-GCM',
51
+ },
52
+ salt: salt.toString('base64'),
53
+ iv: iv.toString('base64'),
54
+ ciphertext: ciphertext.toString('base64'),
55
+ createdAt: input.createdAt,
56
+ };
57
+ }
58
+ export function openCapsule(capsule, passphrase, rules) {
59
+ const tagBytes = rules.capsule.authTagBits / 8;
60
+ const raw = Buffer.from(capsule.ciphertext, 'base64');
61
+ if (raw.length <= tagBytes) {
62
+ throw new CapsuleError('This capsule is truncated; there is nothing to decrypt.');
63
+ }
64
+ const key = deriveKey(passphrase, Buffer.from(capsule.salt, 'base64'), rules, capsule.algorithm.iterations);
65
+ const decipher = createDecipheriv('aes-256-gcm', key, Buffer.from(capsule.iv, 'base64'), {
66
+ authTagLength: tagBytes,
67
+ });
68
+ decipher.setAAD(Buffer.from(additionalData(capsule.unlockDate, rules), 'utf8'));
69
+ decipher.setAuthTag(raw.subarray(raw.length - tagBytes));
70
+ try {
71
+ return Buffer.concat([
72
+ decipher.update(raw.subarray(0, raw.length - tagBytes)),
73
+ decipher.final(),
74
+ ]).toString('utf8');
75
+ }
76
+ catch {
77
+ // A wrong passphrase and a tampered file fail identically here, and saying only "the
78
+ // passphrase is not correct" is both true and the one thing worth telling the reader.
79
+ throw new CapsuleError('That passphrase does not open this capsule.');
80
+ }
81
+ }
82
+ function deriveKey(passphrase, salt, rules, iterations) {
83
+ return pbkdf2Sync(passphrase.normalize('NFC'), salt, iterations ?? rules.capsule.iterations, rules.capsule.derivedKeyBits / 8, 'sha256');
84
+ }
85
+ /**
86
+ * The unlock date is bound into the ciphertext as additional authenticated data.
87
+ *
88
+ * It does not make the date a security control — nothing can, on a file the reader holds. What it
89
+ * does is make the date *tamper-evident*: editing the countdown in a published chronicle makes the
90
+ * capsule stop opening, so an altered file announces itself instead of passing as the original.
91
+ */
92
+ function additionalData(unlockDate, rules) {
93
+ return rules.capsule.additionalDataFormat.replace('{unlockDate}', unlockDate);
94
+ }
95
+ function validateUnlockDate(value) {
96
+ if (!DATE_PATTERN.test(value)) {
97
+ throw new CapsuleError(`The unlock date must look like YYYY-MM-DD, not "${value}".`);
98
+ }
99
+ const [year, month, day] = value.split('-').map(Number);
100
+ const date = new Date(Date.UTC(year, month - 1, day));
101
+ if (date.getUTCFullYear() !== year || date.getUTCMonth() !== month - 1 || date.getUTCDate() !== day) {
102
+ throw new CapsuleError(`"${value}" is not a date that exists.`);
103
+ }
104
+ }
105
+ function validatePassphrase(passphrase, minimum) {
106
+ if ([...passphrase].length < minimum) {
107
+ throw new CapsuleError(`The passphrase must be at least ${minimum} characters. This is the only thing standing ` +
108
+ 'between the message and anyone who opens the file, and it cannot be reset or recovered.');
109
+ }
110
+ }
111
+ /** Constant-time comparison for the confirmation prompt, so a typo check leaks no timing. */
112
+ export function passphrasesMatch(first, second) {
113
+ const a = Buffer.from(first.normalize('NFC'), 'utf8');
114
+ const b = Buffer.from(second.normalize('NFC'), 'utf8');
115
+ if (a.length !== b.length)
116
+ return false;
117
+ return timingSafeEqual(a, b);
118
+ }
119
+ function emptyToNull(value) {
120
+ const trimmed = value?.trim() ?? '';
121
+ return trimmed === '' ? null : trimmed;
122
+ }
123
+ //# sourceMappingURL=capsule.js.map
@@ -0,0 +1,15 @@
1
+ import type { SealedCapsule } from '../engine/types.js';
2
+ import type { EgehanRules } from '../spec/rules.js';
3
+ /**
4
+ * Where a capsule lives on disk.
5
+ *
6
+ * Separate from the CLI command so the pipeline can pick a capsule up without importing anything
7
+ * from the command layer — `generate` embeds whatever capsule the repository has, and an IDE
8
+ * extension calling `produceReport` must get the same chronicle the CLI would write.
9
+ */
10
+ export declare function capsulePath(root: string, override: string | null, rules: EgehanRules): string;
11
+ export declare function saveCapsule(path: string, capsule: SealedCapsule): void;
12
+ export declare function readCapsuleFile(path: string, rules: EgehanRules): SealedCapsule;
13
+ /** The repository's own capsule, when it has one. */
14
+ export declare function loadCapsule(root: string, rules: EgehanRules): SealedCapsule | null;
15
+ //# sourceMappingURL=storage.d.ts.map
@@ -0,0 +1,52 @@
1
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
2
+ import { isAbsolute, join, resolve } from 'node:path';
3
+ import { CapsuleError } from './capsule.js';
4
+ /**
5
+ * Where a capsule lives on disk.
6
+ *
7
+ * Separate from the CLI command so the pipeline can pick a capsule up without importing anything
8
+ * from the command layer — `generate` embeds whatever capsule the repository has, and an IDE
9
+ * extension calling `produceReport` must get the same chronicle the CLI would write.
10
+ */
11
+ export function capsulePath(root, override, rules) {
12
+ if (override === null || override === '')
13
+ return join(root, rules.output.capsuleFileName);
14
+ return isAbsolute(override) ? override : resolve(root, override);
15
+ }
16
+ export function saveCapsule(path, capsule) {
17
+ writeFileSync(path, `${JSON.stringify(capsule, null, 2)}\n`, 'utf8');
18
+ }
19
+ export function readCapsuleFile(path, rules) {
20
+ let parsed;
21
+ try {
22
+ parsed = JSON.parse(readFileSync(path, 'utf8'));
23
+ }
24
+ catch (error) {
25
+ const reason = error instanceof Error ? error.message : String(error);
26
+ throw new CapsuleError(`The capsule at ${path} could not be read: ${reason}`);
27
+ }
28
+ const capsule = parsed;
29
+ if (capsule.mode !== 'sealed') {
30
+ throw new CapsuleError(`The capsule at ${path} declares mode "${String(capsule.mode)}". Only sealed capsules exist.`);
31
+ }
32
+ if (typeof capsule.ciphertext !== 'string' ||
33
+ typeof capsule.salt !== 'string' ||
34
+ typeof capsule.iv !== 'string') {
35
+ throw new CapsuleError(`The capsule at ${path} is missing its ciphertext.`);
36
+ }
37
+ if (capsule.algorithm?.iterations === undefined || capsule.algorithm.iterations < 1) {
38
+ throw new CapsuleError(`The capsule at ${path} does not say how it was derived.`);
39
+ }
40
+ // Refuse a capsule weakened below the floor rather than opening it and implying it was fine.
41
+ if (capsule.algorithm.iterations < rules.capsule.iterations / 10) {
42
+ throw new CapsuleError(`The capsule at ${path} was derived with ${capsule.algorithm.iterations} iterations, far ` +
43
+ `below the ${rules.capsule.iterations} this version requires. Re-create it.`);
44
+ }
45
+ return capsule;
46
+ }
47
+ /** The repository's own capsule, when it has one. */
48
+ export function loadCapsule(root, rules) {
49
+ const path = capsulePath(root, null, rules);
50
+ return existsSync(path) ? readCapsuleFile(path, rules) : null;
51
+ }
52
+ //# sourceMappingURL=storage.js.map
@@ -0,0 +1,20 @@
1
+ /**
2
+ * `egehan capsule` — seal a message, or open one.
3
+ *
4
+ * The command spends as much effort on warning the user as on the cryptography, and that is the
5
+ * right balance: the algorithm is not the part people get wrong. Losing the passphrase is, and
6
+ * committing the capsule to a public repository without understanding what that means is.
7
+ */
8
+ export interface CapsuleOptions {
9
+ readonly cwd: string;
10
+ readonly message: string | null;
11
+ readonly messageFile: string | null;
12
+ readonly unlockDate: string | null;
13
+ readonly author: string | null;
14
+ readonly hint: string | null;
15
+ readonly file: string | null;
16
+ readonly open: boolean;
17
+ readonly force: boolean;
18
+ }
19
+ export declare function runCapsule(options: CapsuleOptions): Promise<void>;
20
+ //# sourceMappingURL=capsule.d.ts.map
@@ -0,0 +1,94 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { relative, resolve } from 'node:path';
3
+ import { nowIso } from '../../engine/datetime.js';
4
+ import { openCapsule, passphrasesMatch, sealCapsule, CapsuleError } from '../../capsule/capsule.js';
5
+ import { capsulePath, readCapsuleFile, saveCapsule } from '../../capsule/storage.js';
6
+ import { isGitRepository, readRepositoryInfo } from '../../git/repository.js';
7
+ import { loadRules } from '../../spec/rules.js';
8
+ import { info, success, theme, warn } from '../output.js';
9
+ import { passphraseFromEnvironment, promptSecret, PASSPHRASE_ENV } from '../prompt.js';
10
+ export async function runCapsule(options) {
11
+ const rules = loadRules();
12
+ const root = repositoryRoot(options.cwd);
13
+ const path = capsulePath(root, options.file, rules);
14
+ if (options.open) {
15
+ await openExisting(path, options.cwd);
16
+ return;
17
+ }
18
+ if (existsSync(path) && !options.force) {
19
+ warn(`${relative(options.cwd, path) || path} already exists. Pass --force to replace it — the ` +
20
+ 'message inside the current one cannot be recovered afterwards.');
21
+ return;
22
+ }
23
+ const message = readMessage(options);
24
+ const unlockDate = options.unlockDate;
25
+ if (unlockDate === null) {
26
+ throw new CapsuleError('An unlock date is required: --unlock-date YYYY-MM-DD.');
27
+ }
28
+ const passphrase = await collectPassphrase(rules.capsule.minPassphraseLength);
29
+ const capsule = sealCapsule({
30
+ message,
31
+ unlockDate,
32
+ passphrase,
33
+ authorLabel: options.author,
34
+ hint: options.hint,
35
+ createdAt: nowIso(),
36
+ }, rules);
37
+ saveCapsule(path, capsule);
38
+ success(`${relative(options.cwd, path) || path}`);
39
+ info('');
40
+ info(theme.muted(' The capsule is embedded in the chronicle the next time you run `egehan generate`.'));
41
+ info(theme.muted(' Nothing but the passphrase can open it, and nothing can reset the passphrase.'));
42
+ if (options.hint !== null && options.hint !== '') {
43
+ info(theme.warn(' The hint is stored in clear text and travels with the file.'));
44
+ }
45
+ info(theme.muted(` Capsule files are not tracked by git by default — keep a copy somewhere safe.`));
46
+ info('');
47
+ }
48
+ async function openExisting(path, cwd) {
49
+ if (!existsSync(path)) {
50
+ throw new CapsuleError(`There is no capsule at ${relative(cwd, path) || path}.`);
51
+ }
52
+ const rules = loadRules();
53
+ const capsule = readCapsuleFile(path, rules);
54
+ if (capsule.hint !== null && capsule.hint !== undefined && capsule.hint !== '') {
55
+ info(theme.muted(`Hint: ${capsule.hint}`));
56
+ }
57
+ const passphrase = passphraseFromEnvironment() ?? (await promptSecret('Passphrase: '));
58
+ const message = openCapsule(capsule, passphrase, rules);
59
+ info('');
60
+ info(message);
61
+ info('');
62
+ }
63
+ async function collectPassphrase(minimum) {
64
+ const fromEnvironment = passphraseFromEnvironment();
65
+ if (fromEnvironment !== null) {
66
+ warn(`Using the passphrase from ${PASSPHRASE_ENV}. Every child process inherits that variable.`);
67
+ return fromEnvironment;
68
+ }
69
+ info('');
70
+ info(theme.muted(` At least ${minimum} characters. There is no way to recover or reset it.`));
71
+ const first = await promptSecret(' Passphrase: ');
72
+ const second = await promptSecret(' Again: ');
73
+ if (!passphrasesMatch(first, second)) {
74
+ throw new CapsuleError('The two passphrases are not the same. Nothing was written.');
75
+ }
76
+ return first;
77
+ }
78
+ function readMessage(options) {
79
+ if (options.messageFile !== null) {
80
+ const path = resolve(options.cwd, options.messageFile);
81
+ if (!existsSync(path)) {
82
+ throw new CapsuleError(`There is no file at ${options.messageFile}.`);
83
+ }
84
+ return readFileSync(path, 'utf8');
85
+ }
86
+ if (options.message !== null)
87
+ return options.message;
88
+ throw new CapsuleError('There is no message: pass --message "…" or --message-file <path>.');
89
+ }
90
+ function repositoryRoot(cwd) {
91
+ const context = { cwd, rules: loadRules() };
92
+ return isGitRepository(context) ? readRepositoryInfo(context).root : resolve(cwd);
93
+ }
94
+ //# sourceMappingURL=capsule.js.map
@@ -0,0 +1,23 @@
1
+ import type { OutputFormat } from '../../config/config.js';
2
+ /**
3
+ * `egehan generate` — writes the chronicle.
4
+ *
5
+ * Output is written atomically-ish and idempotently: because narration is deterministic, running
6
+ * this twice on an unchanged repository produces byte-identical files. That is what makes it safe
7
+ * for a git hook to run it after every commit without filling the project's diff with noise.
8
+ */
9
+ export interface GenerateOptions {
10
+ readonly cwd: string;
11
+ readonly since: string | null;
12
+ readonly until: string | null;
13
+ readonly output: string | null;
14
+ readonly format: OutputFormat | null;
15
+ readonly overrides: Record<string, unknown>;
16
+ readonly quiet: boolean;
17
+ }
18
+ export interface GenerateResult {
19
+ readonly writtenFiles: readonly string[];
20
+ readonly commits: number;
21
+ }
22
+ export declare function runGenerate(options: GenerateOptions): GenerateResult;
23
+ //# sourceMappingURL=generate.d.ts.map
@@ -0,0 +1,47 @@
1
+ import { isAbsolute, relative, resolve } from 'node:path';
2
+ import { writeArtifacts } from '../../artifacts.js';
3
+ import { loadDictionary } from '../../spec/dictionary.js';
4
+ import { loadRules } from '../../spec/rules.js';
5
+ import { produceReport } from '../../pipeline.js';
6
+ import { info, success, theme, warn } from '../output.js';
7
+ export function runGenerate(options) {
8
+ const rules = loadRules();
9
+ const { report, config, repositoryRoot } = produceReport({
10
+ cwd: options.cwd,
11
+ since: options.since,
12
+ until: options.until,
13
+ overrides: options.overrides,
14
+ });
15
+ const format = options.format ?? config.format;
16
+ const outputDir = resolveOutputDir(repositoryRoot, options.output ?? config.output);
17
+ const written = writeArtifacts({
18
+ report,
19
+ dictionary: loadDictionary(report.config.language),
20
+ rules,
21
+ outputDirectory: outputDir,
22
+ format,
23
+ });
24
+ if (!options.quiet) {
25
+ if (report.range.truncated) {
26
+ warn(`Only the most recent ${rules.limits.maxCommitsPerRun} commits were read. ` +
27
+ 'Narrow the range with --since to cover a specific period.');
28
+ }
29
+ if (report.totals.commits >= rules.limits.warnAboveCommits) {
30
+ warn(`${report.totals.commits} commits is a lot of story. Consider --since for a focused chapter.`);
31
+ }
32
+ info('');
33
+ info(`${theme.heading(report.project.name)} ${theme.muted('·')} ` +
34
+ `${theme.value(String(report.totals.commits))} commits ${theme.muted('·')} ` +
35
+ `${theme.value(String(report.range.days))} days ${theme.muted('·')} ` +
36
+ `${theme.value(String(report.chapters.length))} chapters`);
37
+ for (const path of written) {
38
+ success(relative(options.cwd, path) || path);
39
+ }
40
+ info('');
41
+ }
42
+ return { writtenFiles: written, commits: report.totals.commits };
43
+ }
44
+ function resolveOutputDir(repositoryRoot, output) {
45
+ return isAbsolute(output) ? output : resolve(repositoryRoot, output);
46
+ }
47
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * `egehan hook <install|uninstall|status>`.
3
+ *
4
+ * The command talks more than it acts, on purpose. Installing a git hook changes what happens
5
+ * every time somebody commits, and the person doing it deserves to be told exactly which file was
6
+ * touched, what the hook will and will not do, and how to undo it.
7
+ */
8
+ export type HookAction = 'install' | 'uninstall' | 'status';
9
+ export interface HookOptions {
10
+ readonly cwd: string;
11
+ readonly action: HookAction;
12
+ }
13
+ export declare function runHook(options: HookOptions): void;
14
+ //# sourceMappingURL=hook.d.ts.map
@@ -0,0 +1,120 @@
1
+ import { relative } from 'node:path';
2
+ import { installHooks, lefthookSnippet, readHookStatus, resolveHookTarget, uninstallHooks, } from '../../hooks/manager.js';
3
+ import { isGitRepository, readRepositoryInfo } from '../../git/repository.js';
4
+ import { loadRules } from '../../spec/rules.js';
5
+ import { NotARepositoryError } from '../../pipeline.js';
6
+ import { packageVersion } from '../../version.js';
7
+ import { info, success, theme, warn } from '../output.js';
8
+ export function runHook(options) {
9
+ const rules = loadRules();
10
+ const context = { cwd: options.cwd, rules };
11
+ if (!isGitRepository(context))
12
+ throw new NotARepositoryError(options.cwd);
13
+ const root = readRepositoryInfo(context).root;
14
+ const target = resolveHookTarget(context, root);
15
+ switch (options.action) {
16
+ case 'install':
17
+ install(target, options.cwd);
18
+ return;
19
+ case 'uninstall':
20
+ uninstall(target, options.cwd);
21
+ return;
22
+ case 'status':
23
+ status(target, options.cwd);
24
+ return;
25
+ default: {
26
+ const unreachable = options.action;
27
+ throw new Error(`Unknown hook action: ${String(unreachable)}`);
28
+ }
29
+ }
30
+ }
31
+ function install(target, cwd) {
32
+ info('');
33
+ if (target.owner === 'lefthook') {
34
+ warn(target.explanation);
35
+ info('');
36
+ info(' Anything written into the hook files would disappear on the next `lefthook install`.');
37
+ info(' Add this to your lefthook configuration instead:');
38
+ info('');
39
+ for (const line of lefthookSnippet().split('\n'))
40
+ info(theme.accent(` ${line}`));
41
+ info('');
42
+ return;
43
+ }
44
+ const results = installHooks(target, packageVersion());
45
+ info(theme.muted(` ${target.explanation}`));
46
+ report(results, cwd);
47
+ info('');
48
+ info(' From now on the chronicle updates itself after every commit and merge.');
49
+ info(theme.muted(' · It runs in the background, so committing never waits for it.'));
50
+ info(theme.muted(' · It never stages or commits anything — the files are yours to commit.'));
51
+ info(theme.muted(' · It stays out of the way during rebase, merge, cherry-pick and bisect.'));
52
+ info(theme.muted(' · EGEHAN_SKIP_HOOK=1 switches it off for one command.'));
53
+ info(theme.muted(' · `egehan hook uninstall` removes it and leaves your other hooks alone.'));
54
+ info('');
55
+ }
56
+ function uninstall(target, cwd) {
57
+ info('');
58
+ if (target.owner === 'lefthook') {
59
+ warn('Lefthook manages this repository; remove the egehan entries from its configuration.');
60
+ info('');
61
+ return;
62
+ }
63
+ const results = uninstallHooks(target);
64
+ if (results.every((result) => result.action === 'absent')) {
65
+ info(theme.muted(' Nothing to remove — the hooks were not installed here.'));
66
+ info('');
67
+ return;
68
+ }
69
+ report(results, cwd);
70
+ info('');
71
+ }
72
+ function status(target, cwd) {
73
+ info('');
74
+ info(theme.muted(` ${target.explanation}`));
75
+ if (target.owner === 'lefthook') {
76
+ info('');
77
+ info(' Add this to your lefthook configuration to keep the chronicle updating:');
78
+ info('');
79
+ for (const line of lefthookSnippet().split('\n'))
80
+ info(theme.accent(` ${line}`));
81
+ info('');
82
+ return;
83
+ }
84
+ info('');
85
+ for (const entry of readHookStatus(target)) {
86
+ const where = relative(cwd, entry.path) || entry.path;
87
+ const mark = entry.installed ? theme.accent('✔') : theme.muted('·');
88
+ const state = entry.installed
89
+ ? entry.sharedWithOtherHooks
90
+ ? 'installed, alongside other hooks'
91
+ : 'installed'
92
+ : entry.exists
93
+ ? 'not installed (the file exists and belongs to something else)'
94
+ : 'not installed';
95
+ info(` ${mark} ${entry.hook.padEnd(12)} ${theme.muted(state)}`);
96
+ info(` ${theme.muted(where)}`);
97
+ }
98
+ info('');
99
+ }
100
+ function report(results, cwd) {
101
+ const words = {
102
+ created: 'installed',
103
+ updated: 'updated',
104
+ unchanged: 'already up to date',
105
+ removed: 'removed',
106
+ absent: 'was not installed',
107
+ skipped: 'skipped',
108
+ };
109
+ info('');
110
+ for (const result of results) {
111
+ const where = result.path === '' ? result.hook : relative(cwd, result.path) || result.path;
112
+ if (result.action === 'absent') {
113
+ info(` ${theme.muted('·')} ${where} ${theme.muted(words[result.action])}`);
114
+ }
115
+ else {
116
+ success(`${where} ${theme.muted(`— ${words[result.action]}`)}`);
117
+ }
118
+ }
119
+ }
120
+ //# sourceMappingURL=hook.js.map
@@ -0,0 +1,16 @@
1
+ /**
2
+ * `egehan init` — the setup wizard.
3
+ *
4
+ * Two behaviours worth noting. It never overwrites an existing `.egehanrc.json` without `--force`,
5
+ * because a config file is something a team agreed on and a wizard is not entitled to overrule it.
6
+ * And the dedication prompt makes clear that whatever is typed there will be committed to the
7
+ * repository, since the whole point of the field is that it ends up at the top of a file people
8
+ * share.
9
+ */
10
+ export interface InitOptions {
11
+ readonly cwd: string;
12
+ readonly yes: boolean;
13
+ readonly force: boolean;
14
+ }
15
+ export declare function runInit(options: InitOptions): Promise<void>;
16
+ //# sourceMappingURL=init.d.ts.map