@h1v35/hivex 0.2.0 → 0.2.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.
@@ -1,17 +1,12 @@
1
1
  # Optional Markdown convention
2
2
 
3
- Use the project's existing Markdown as it is. Hivex must not require this convention, frontmatter,
4
- numbered ADRs or a particular directory structure. Recommend these practices when adopting Hivex or
5
- writing documentation, without repeatedly proposing a migration of an established project.
3
+ Use the project's existing Markdown as it is. Hivex must not require this convention, frontmatter, numbered ADRs or a particular directory structure. Recommend these practices when adopting Hivex or writing documentation, without repeatedly proposing a migration of an established project.
6
4
 
7
- These practices draw on Compi's authority map and documentation layout and the domain-modeling
8
- skill. They preserve the useful documentation discipline, not Compi's retired machinery.
5
+ These practices draw on established authority-map and documentation-layout patterns and the domain-modeling skill. They preserve useful documentation discipline without prescribing retired machinery from any one project.
9
6
 
10
7
  ## Give knowledge one authoritative home
11
8
 
12
- Keep shared decisions at project or monorepo level. Package-specific or module-specific knowledge
13
- can stay with that package or module. Link shared rules instead of copying them into each area.
14
- Folders and files appear only when there is useful content to put in them.
9
+ Keep shared decisions at project or monorepo level. Package-specific or module-specific knowledge can stay with that package or module. Link shared rules instead of copying them into each area. Folders and files appear only when there is useful content to put in them.
15
10
 
16
11
  A useful catalogue distinguishes:
17
12
 
@@ -23,57 +18,32 @@ A useful catalogue distinguishes:
23
18
  - Procedures for concrete operational or recovery tasks.
24
19
  - Research and evidence identified as dated support, not automatically current decisions.
25
20
 
26
- For example, a project may use `docs/README.md`, `docs/CONTEXT.md`, `docs/adr/`,
27
- `docs/guidelines/`, `docs/process/`, `docs/procedures/` and `docs/research/`. These are examples,
28
- not required paths. Multiple bounded contexts may have their own glossary and decisions with a
29
- small context map linking them; a monorepo need not duplicate one shared product glossary.
21
+ For example, a project may use `docs/README.md`, `docs/CONTEXT.md`, `docs/adr/`, `docs/guidelines/`, `docs/process/`, `docs/procedures/` and `docs/research/`. These are examples, not required paths. Multiple bounded contexts may have their own glossary and decisions with a small context map linking them; a monorepo need not duplicate one shared product glossary.
30
22
 
31
23
  ## Write decisions for the next reader
32
24
 
33
- State what was decided and why. Include the scope, conditions and exceptions that change how the
34
- rule is applied. Link the source or decision it depends on or replaces. A short paragraph can be
35
- enough; optional sections should carry information rather than serve as boxes to fill in.
25
+ State what was decided and why. Include the scope, conditions and exceptions that change how the rule is applied. Link the source or decision it depends on or replaces. A short paragraph can be enough; optional sections should carry information rather than serve as boxes to fill in.
36
26
 
37
27
  For a consequential architectural trade-off, an ADR might be:
38
28
 
39
29
  ```markdown
40
30
  # Remove private cached data when access is revoked
41
31
 
42
- Cached private data is removed immediately when access is revoked. The normal cache lifetime
43
- still applies while access remains valid. This prevents stale local access after a permission
44
- change. See the cache policy for the general retention rule.
32
+ Cached private data is removed immediately when access is revoked. The normal cache lifetime still applies while access remains valid. This prevents stale local access after a permission change. See the cache policy for the general retention rule.
45
33
  ```
46
34
 
47
- A title, truthful status and decision date can improve cataloguing. Tags are optional. If a rule is
48
- replaced, identify the replacement and whether the change is partial. Keep the historical reasoning
49
- readable; do not silently rewrite the past. A missing status means uncertainty to resolve from the
50
- content, not permission to assume acceptance.
35
+ A title, truthful status and decision date can improve cataloguing. Tags are optional. If a rule is replaced, identify the replacement and whether the change is partial. Keep the historical reasoning readable; do not silently rewrite the past. A missing status means uncertainty to resolve from the content, not permission to assume acceptance.
51
36
 
52
- Use an ADR when the choice is consequential, reflects a real trade-off and would be surprising
53
- without its rationale. Do not create one for every routine edit or dependency. Sequential names
54
- such as `0001-short-decision.md` are convenient if the project adopts that convention.
37
+ Use an ADR when the choice is consequential, reflects a real trade-off and would be surprising without its rationale. Do not create one for every routine edit or dependency. Sequential names such as `0001-short-decision.md` are convenient if the project adopts that convention.
55
38
 
56
39
  ## Compact an ADR without losing its history
57
40
 
58
- When replaced text obscures a decision's current meaning, preserve that history in a clearly marked
59
- Markdown archive and keep the active document focused on applicable rules, reasons, dependencies
60
- and exceptions. A wholly superseded ADR can remain as a short pointer to its replacement and archive.
61
- Preserve referenced anchors or update their links. Do not archive a live exception merely because it
62
- is old, or change what an earlier decision meant while shortening its current presentation.
41
+ When replaced text obscures a decision's current meaning, preserve that history in a clearly marked Markdown archive and keep the active document focused on applicable rules, reasons, dependencies and exceptions. A wholly superseded ADR can remain as a short pointer to its replacement and archive. Preserve referenced anchors or update their links. Do not archive a live exception merely because it is old, or change what an earlier decision meant while shortening its current presentation.
63
42
 
64
- Compi uses `docs/archive/adr/` for this purpose; other layouts remain valid. Historical evidence should
65
- be available for focused consultation without being loaded into every model context. Declare its
66
- relative globs in `hivex.json` under `history`, then use the installed CLI's `--source` selection or
67
- a known relationship for bounded retrieval. Compaction must not silently make necessary evidence
68
- inaccessible. The human or implementing agent maintains these documents; Hivex does not rewrite or
69
- move the sources.
43
+ A project may use `docs/archive/adr/` for this purpose; other layouts remain valid. Historical evidence should be available for focused consultation without being loaded into every model context. Declare its relative globs in `hivex.json` under `history`, then use the installed CLI's `--source` selection or a known relationship for bounded retrieval. Compaction must not silently make necessary evidence inaccessible. The human or implementing agent maintains these documents; Hivex does not rewrite or move the sources.
70
44
 
71
45
  ## Keep the glossary focused
72
46
 
73
- Define each project-specific concept briefly and use that term consistently. A glossary explains
74
- what a concept is; it is not an implementation manual, task plan or collection of general programming
75
- terms. Group related concepts when it helps and link context-specific definitions instead of copying.
47
+ Define each project-specific concept briefly and use that term consistently. A glossary explains what a concept is; it is not an implementation manual, task plan or collection of general programming terms. Group related concepts when it helps and link context-specific definitions instead of copying.
76
48
 
77
- Code and executable contracts explain mechanics. Markdown preserves the intent, constraints,
78
- decisions and reasons that code cannot explain. Update that knowledge alongside the change rather
79
- than leaving the only explanation in a conversation or private agent memory.
49
+ Code and executable contracts explain mechanics. Markdown preserves the intent, constraints, decisions and reasons that code cannot explain. Update that knowledge alongside the change rather than leaving the only explanation in a conversation or private agent memory.
@@ -1,26 +1,36 @@
1
1
  import { HivexError } from '../errors.ts';
2
2
 
3
- function bounded(text: string) {
3
+ const bounded = (text: string) => {
4
4
  let result = '';
5
5
  for (const char of text) {
6
- if (Buffer.byteLength(JSON.stringify(result + char)) > 256) break;
6
+ if (Buffer.byteLength(JSON.stringify(result + char)) > 256) {
7
+ break;
8
+ }
7
9
  result += char;
8
10
  }
9
11
  return result;
10
- }
11
-
12
- export function diagnostic(error: unknown) {
12
+ };
13
+ export const diagnostic = (error: unknown) => {
13
14
  let failure = new HivexError({
14
15
  code: 'READ_FAILED',
15
16
  message: 'Unable to read project knowledge',
16
17
  });
17
- if (error instanceof HivexError) failure = error;
18
- else if (error instanceof Error)
18
+ if (error instanceof HivexError) {
19
+ failure = error;
20
+ } else if (Error.isError(error)) {
19
21
  failure = new HivexError({ code: 'READ_FAILED', message: error.message });
20
- let details = failure.details;
21
- if (details && Buffer.byteLength(JSON.stringify(details)) > 384) details = { omitted: true };
22
+ }
23
+ let { details } = failure;
24
+ if (details && Buffer.byteLength(JSON.stringify(details)) > 384) {
25
+ details = { omitted: true };
26
+ }
22
27
  const message = bounded(failure.message);
23
28
  return {
24
- error: { code: failure.code, message, messageTruncated: message !== failure.message, details },
29
+ error: {
30
+ code: failure.code,
31
+ details,
32
+ message,
33
+ messageTruncated: message !== failure.message,
34
+ },
25
35
  };
26
- }
36
+ };
package/src/cli.ts CHANGED
@@ -6,95 +6,105 @@ import { knowledgeCommand } from './knowledge.ts';
6
6
  import { snapshotCommand } from './snapshot-command.ts';
7
7
  import { diagnostic } from './cli/diagnostic.ts';
8
8
 
9
- async function main(args: string[]) {
10
- if (!args.length || args.includes('--help'))
9
+ const main = async (input: string[]) => {
10
+ if (!input.length || input.includes('--help')) {
11
11
  return {
12
12
  application: 'hivex',
13
- purpose: 'Project decisions, dependencies and exceptions for the responsible agent.',
14
13
  commands: [
15
14
  {
15
+ modelCalls: 0,
16
16
  name: 'sources',
17
17
  usage:
18
18
  'sources [--root <project>] [--limit <count>] [--cursor <continuation>] [--max-bytes <bytes>]',
19
- modelCalls: 0,
20
19
  },
21
20
  {
21
+ modelCalls: 0,
22
22
  name: 'read',
23
23
  usage:
24
24
  'read <document> [--root <project>] [--from <line>] [--to <line>] [--max-bytes <bytes>]',
25
- modelCalls: 0,
26
25
  },
27
26
  {
27
+ modelCalls:
28
+ 'One extraction and one check per batch; retained work resumes within the same budget.',
28
29
  name: 'update',
29
30
  usage:
30
31
  'update [--root <project>] [--max-calls <total>] [--max-input-bytes <total>] [--repair <document> --reason <correction>]',
31
- modelCalls:
32
- 'One extraction and one check per batch; retained work resumes within the same budget.',
33
32
  },
34
33
  {
34
+ modelCalls: 0,
35
35
  name: 'search',
36
36
  usage: 'search <query> [--root <project>] [--limit <count>]',
37
- modelCalls: 0,
38
37
  },
39
38
  {
39
+ modelCalls: 0,
40
40
  name: 'neighbors',
41
41
  usage: 'neighbors <decision-id> [--root <project>] [--limit <count>]',
42
- modelCalls: 0,
43
42
  },
44
43
  {
44
+ modelCalls:
45
+ 'One bounded automatic update/check batch and Luna/max assistance share a total budget; identical retained answers are reused.',
45
46
  name: 'ask',
46
47
  usage:
47
48
  'ask <task> [--root <project>] [--source <document>] [--max-calls <total>] [--max-input-bytes <total>] [--max-context-bytes <bytes>]',
48
- modelCalls:
49
- 'One bounded automatic update/check batch and Luna/max assistance share a total budget; identical retained answers are reused.',
50
49
  },
51
50
  {
51
+ modelCalls:
52
+ 'One automatic update/check batch and a review share one budget. Checking saved versions needs no model.',
52
53
  name: 'review',
53
54
  usage:
54
55
  'review <task> --base <git-ref> [--root <project>] [--source <document>] [--max-calls <total>] [--max-context-bytes <bytes>] | review --check <saved-report.json> [--root <project>]',
55
- modelCalls:
56
- 'One automatic update/check batch and a review share one budget. Checking saved versions needs no model.',
57
56
  },
58
57
  {
58
+ modelCalls: 0,
59
59
  name: 'recover',
60
60
  usage: 'recover [--root <project>] [--acknowledge-uncertain]',
61
- modelCalls: 0,
62
61
  },
63
62
  {
63
+ modelCalls: 0,
64
64
  name: 'prune',
65
65
  usage: 'prune [--root <project>] [--keep-completed <count>] [--keep-caches <count>]',
66
- modelCalls: 0,
67
66
  },
68
67
  {
68
+ modelCalls: 0,
69
69
  name: 'snapshot',
70
70
  usage: 'snapshot export | import [--root <project>]',
71
- modelCalls: 0,
72
71
  },
73
- { name: 'status', usage: 'status [--root <project>]', modelCalls: 0 },
72
+ { modelCalls: 0, name: 'status', usage: 'status [--root <project>]' },
74
73
  ],
75
- modelOptions: '--codex <native-binary> --deadline-ms <100..1800000> --retry-failed',
76
74
  configuration:
77
75
  'Optional hivex.json with include/exclude/history relative Markdown globs; history sources are focused evidence.',
76
+ modelOptions: '--codex <native-binary> --deadline-ms <100..1800000> --retry-failed',
77
+ purpose: 'Project decisions, dependencies and exceptions for the responsible agent.',
78
78
  stage: 'Incremental project knowledge and task/diff assistance for the principal agent.',
79
79
  };
80
- if (args[0] === 'review' && args.includes('--check')) return checkReview(args);
81
- if (args[0] === 'sources' || args[0] === 'read') return documentCommand(args);
82
- if (args[0] === 'snapshot') return snapshotCommand(args);
83
- if (args[0] === 'recover' || args[0] === 'prune') return knowledgeMaintenance(args);
84
- return knowledgeCommand(args);
85
- }
86
-
87
- try {
88
- const result = await main(process.argv.slice(2));
89
- process.stdout.write(JSON.stringify(result) + '\n');
90
- if (
91
- result &&
92
- typeof result === 'object' &&
93
- 'status' in result &&
94
- (result.status === 'failed' || result.status === 'blocked')
95
- )
80
+ }
81
+ if (input[0] === 'review' && input.includes('--check')) {
82
+ return checkReview(input);
83
+ }
84
+ if (input[0] === 'sources' || input[0] === 'read') {
85
+ return documentCommand(input);
86
+ }
87
+ if (input[0] === 'snapshot') {
88
+ return snapshotCommand(input);
89
+ }
90
+ if (input[0] === 'recover' || input[0] === 'prune') {
91
+ return knowledgeMaintenance(input);
92
+ }
93
+ return await knowledgeCommand(input);
94
+ };
95
+ const printResult = async () => {
96
+ const result: unknown = await main(process.argv.slice(2));
97
+ process.stdout.write(`${JSON.stringify(result)}\n`);
98
+ if (result === null || typeof result !== 'object' || !('status' in result)) {
99
+ return;
100
+ }
101
+ if (result.status === 'failed' || result.status === 'blocked') {
96
102
  process.exitCode = 1;
103
+ }
104
+ };
105
+ try {
106
+ await printResult();
97
107
  } catch (error) {
98
- process.stderr.write(JSON.stringify(diagnostic(error)) + '\n');
108
+ process.stderr.write(`${JSON.stringify(diagnostic(error))}\n`);
99
109
  process.exitCode = 1;
100
110
  }