djournal 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 (38) hide show
  1. package/.agents/adapters/contract.md +48 -0
  2. package/.agents/adapters/shared/journal-hook.js +120 -0
  3. package/.agents/rules/AUTOMATION.md +84 -0
  4. package/.agents/rules/FEAT.md +83 -0
  5. package/.agents/rules/JOURNAL.md +127 -0
  6. package/.agents/rules/LINKS.md +96 -0
  7. package/.agents/rules/METADATA.md +179 -0
  8. package/.agents/rules/SAFETY.md +92 -0
  9. package/.agents/rules/STATE.md +31 -0
  10. package/.agents/skills/audit/SKILL.md +89 -0
  11. package/.agents/skills/audit/agents/openai.yaml +4 -0
  12. package/.agents/skills/decision/SKILL.md +74 -0
  13. package/.agents/skills/decision/agents/openai.yaml +4 -0
  14. package/.agents/skills/document/SKILL.md +68 -0
  15. package/.agents/skills/init-work/SKILL.md +62 -0
  16. package/.agents/skills/journal/SKILL.md +97 -0
  17. package/.agents/skills/journal-workflow/SKILL.md +45 -0
  18. package/.agents/skills/journal-workflow/agents/openai.yaml +4 -0
  19. package/.agents/skills/plan/SKILL.md +98 -0
  20. package/.agents/skills/recall/SKILL.md +67 -0
  21. package/.agents/skills/reconcile/SKILL.md +93 -0
  22. package/.agents/skills/reconcile/agents/openai.yaml +4 -0
  23. package/.agents/skills/research-codebase/SKILL.md +72 -0
  24. package/.agents/skills/research-web/SKILL.md +72 -0
  25. package/.agents/skills/resume/SKILL.md +68 -0
  26. package/.agents/skills/switch/SKILL.md +31 -0
  27. package/.claude/settings.json +41 -0
  28. package/.codex/hooks.json +40 -0
  29. package/AGENTS.md +23 -0
  30. package/CLAUDE.md +1 -0
  31. package/LICENSE +202 -0
  32. package/README.md +158 -0
  33. package/bin/journal.js +118 -0
  34. package/install.sh +35 -0
  35. package/lib/installer/index.js +538 -0
  36. package/lib/installer/merge.js +125 -0
  37. package/package.json +55 -0
  38. package/spec.md +297 -0
@@ -0,0 +1,41 @@
1
+ {
2
+ "hooks": {
3
+ "SessionStart": [
4
+ {
5
+ "matcher": "startup|resume|clear|compact",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "node",
10
+ "args": ["${CLAUDE_PROJECT_DIR}/.agents/adapters/shared/journal-hook.js", "--harness", "claude-code"],
11
+ "timeout": 10
12
+ }
13
+ ]
14
+ }
15
+ ],
16
+ "UserPromptSubmit": [
17
+ {
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "node",
22
+ "args": ["${CLAUDE_PROJECT_DIR}/.agents/adapters/shared/journal-hook.js", "--harness", "claude-code"],
23
+ "timeout": 10
24
+ }
25
+ ]
26
+ }
27
+ ],
28
+ "Stop": [
29
+ {
30
+ "hooks": [
31
+ {
32
+ "type": "command",
33
+ "command": "node",
34
+ "args": ["${CLAUDE_PROJECT_DIR}/.agents/adapters/shared/journal-hook.js", "--harness", "claude-code"],
35
+ "timeout": 10
36
+ }
37
+ ]
38
+ }
39
+ ]
40
+ }
41
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "hooks": {
3
+ "SessionStart": [
4
+ {
5
+ "matcher": "startup|resume|clear|compact",
6
+ "hooks": [
7
+ {
8
+ "type": "command",
9
+ "command": "sh -c 'd=\"$PWD\"; while [ \"$d\" != / ] && [ ! -f \"$d/.agents/adapters/shared/journal-hook.js\" ]; do d=\"$(dirname \"$d\")\"; done; [ -f \"$d/.agents/adapters/shared/journal-hook.js\" ] || exit 0; exec node \"$d/.agents/adapters/shared/journal-hook.js\" --harness codex'",
10
+ "timeout": 10,
11
+ "statusMessage": "Loading journal workflow"
12
+ }
13
+ ]
14
+ }
15
+ ],
16
+ "UserPromptSubmit": [
17
+ {
18
+ "hooks": [
19
+ {
20
+ "type": "command",
21
+ "command": "sh -c 'd=\"$PWD\"; while [ \"$d\" != / ] && [ ! -f \"$d/.agents/adapters/shared/journal-hook.js\" ]; do d=\"$(dirname \"$d\")\"; done; [ -f \"$d/.agents/adapters/shared/journal-hook.js\" ] || exit 0; exec node \"$d/.agents/adapters/shared/journal-hook.js\" --harness codex'",
22
+ "timeout": 10
23
+ }
24
+ ]
25
+ }
26
+ ],
27
+ "Stop": [
28
+ {
29
+ "hooks": [
30
+ {
31
+ "type": "command",
32
+ "command": "sh -c 'd=\"$PWD\"; while [ \"$d\" != / ] && [ ! -f \"$d/.agents/adapters/shared/journal-hook.js\" ]; do d=\"$(dirname \"$d\")\"; done; [ -f \"$d/.agents/adapters/shared/journal-hook.js\" ] || exit 0; exec node \"$d/.agents/adapters/shared/journal-hook.js\" --harness codex'",
33
+ "timeout": 10,
34
+ "statusMessage": "Checking journal closure"
35
+ }
36
+ ]
37
+ }
38
+ ]
39
+ }
40
+ }
package/AGENTS.md ADDED
@@ -0,0 +1,23 @@
1
+ # djournal Workflow
2
+
3
+ This repository uses `.journal/` as durable project memory and `.agents/` as
4
+ the journal's rules and skills. Markdown is the source of truth.
5
+
6
+ For every request:
7
+
8
+ 1. Honor an explicit `journal: off` instruction for that request.
9
+ 2. Classify the work using `.agents/rules/AUTOMATION.md`.
10
+ 3. Use `.agents/skills/journal-workflow/SKILL.md` for meaningful mutations,
11
+ durable research, decisions, documentation, or material status changes.
12
+ 4. Do not force a plan or journal entry for read-only or trivial work.
13
+ 5. Before the final response, close meaningful changed state through the
14
+ existing journal skills. Hooks never write entries.
15
+
16
+ End every final response with exactly one hidden status marker:
17
+
18
+ - `<!-- journal-status: closed <relative-entry-path> -->`
19
+ - `<!-- journal-status: not-needed -->`
20
+ - `<!-- journal-status: off -->`
21
+
22
+ Use `closed` only after verifying that the referenced spine entry exists. Keep
23
+ the marker as the final line so optional harness hooks can validate closure.
package/CLAUDE.md ADDED
@@ -0,0 +1 @@
1
+ @AGENTS.md
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,158 @@
1
+ # djournal
2
+
3
+ Durable project memory for coding agents, readable by humans.
4
+
5
+ djournal records the path of the work—plans, research, decisions, changes, and
6
+ next steps—as linked Markdown inside your project. Codex and Claude Code can use
7
+ that memory automatically across sessions without a database, account, or
8
+ proprietary service.
9
+
10
+ > **Files are memory. Indexes are projections.**
11
+
12
+ ## Why djournal exists
13
+
14
+ Code preserves what a system does. It rarely preserves why it became that way,
15
+ what was tried, which evidence mattered, or what should happen next.
16
+
17
+ Chat transcripts preserve too much. Conventional documentation is usually
18
+ written too late. Retrieval systems can find fragments, but they cannot recover
19
+ reasoning that was never recorded.
20
+
21
+ djournal makes project memory part of doing the work. Skills capture durable
22
+ context when work becomes meaningful; optional hooks make the workflow
23
+ default-on without writing entries behind the agent's back.
24
+
25
+ ## Manifesto
26
+
27
+ 1. **Memory should be authored, not inferred.** Decisions and evidence deserve
28
+ explicit records.
29
+ 2. **The source should be readable.** Humans and agents should consume the same
30
+ artifacts without a translation layer.
31
+ 3. **History is knowledge.** Diffs, attribution, chronology, and supersession
32
+ explain how the current state came to exist.
33
+ 4. **Structure should be sufficient, not maximal.** YAML carries stable
34
+ metadata; Markdown carries meaning; links carry relationships.
35
+ 5. **Tools should remain replaceable.** Memory must survive changes in models,
36
+ agent harnesses, databases, and vendors.
37
+ 6. **The workflow should carry the burden.** Maintaining memory should be a
38
+ consequence of meaningful work, not another ritual to remember.
39
+
40
+ ## Why plain Markdown
41
+
42
+ Markdown is immediately useful. It can be read before an ingestion pipeline
43
+ runs, searched with ordinary tools, loaded selectively, reviewed line by line,
44
+ and versioned with Git. Frontmatter makes important fields deterministic while
45
+ links turn the directory into an explicit graph.
46
+
47
+ Google Cloud's draft [Open Knowledge Format](https://cloud.google.com/blog/products/data-analytics/how-the-open-knowledge-format-can-improve-data-sharing/)
48
+ formalizes the same broad pattern: knowledge as linked Markdown with YAML
49
+ frontmatter, portable through Git and independent of the tools that produce or
50
+ consume it. djournal is conceptually aligned with that direction, but uses a
51
+ domain-specific schema for project history and is not currently
52
+ [OKF v0.1](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md)
53
+ conformant.
54
+
55
+ ## Why not only RAG or a knowledge graph?
56
+
57
+ RAG, embeddings, full-text indexes, and graph views are useful retrieval tools.
58
+ They are not ideal as the only durable copy of project memory.
59
+
60
+ | Layer | What it provides |
61
+ | --- | --- |
62
+ | djournal Markdown | Canonical meaning, provenance, chronology, and links |
63
+ | Git | Review, attribution, history, and team exchange |
64
+ | Embeddings / RAG | Semantic retrieval over larger corpora |
65
+ | Graph projection | Traversal, visualization, and multi-hop retrieval |
66
+
67
+ Vector and graph indexes are derived representations: they require ingestion,
68
+ can become stale, and may change with the model or extraction pipeline. djournal
69
+ keeps the authored source inspectable and lets those indexes be rebuilt when
70
+ needed. It complements retrieval infrastructure rather than replacing it.
71
+
72
+ ## What djournal records
73
+
74
+ ```text
75
+ .journal/
76
+ state.json
77
+ work/<work-item>/
78
+ work.md
79
+ journal/ # plans, implementation, and status
80
+ decisions/ # accepted choices and rationale
81
+ docs/ # durable synthesized references
82
+ _research/ # codebase and web evidence
83
+ ```
84
+
85
+ Entries carry structured frontmatter, stable identities, summaries, timestamps,
86
+ and typed links. Markdown remains the source of truth.
87
+
88
+ ## How it works
89
+
90
+ ```mermaid
91
+ flowchart LR
92
+ R[Request] --> A[Coding agent]
93
+ A --> W[djournal workflow]
94
+ W --> M[Read project memory]
95
+ W --> X[Plan / research / decide]
96
+ W --> C[Complete meaningful work]
97
+ C --> J[Write or update memory]
98
+ J --> M
99
+ ```
100
+
101
+ - `AGENTS.md` supplies portable workflow instructions.
102
+ - Skills handle planning, research, decisions, documentation, recall, audit,
103
+ reconciliation, and session closure.
104
+ - Codex and Claude Code hooks provide reminders and closure validation.
105
+ - Hooks never create or modify semantic journal entries.
106
+ - Read-only and trivial requests do not generate unnecessary ceremony.
107
+
108
+ ## Install
109
+
110
+ Requires Node.js 18 or newer. Run this from the project you want to equip:
111
+
112
+ ```bash
113
+ npx djournal install
114
+ ```
115
+
116
+ The installer targets the current directory and detects Codex or Claude Code.
117
+ Select explicitly when needed:
118
+
119
+ ```bash
120
+ npx djournal install --harness codex
121
+ npx djournal install --harness claude-code
122
+ npx djournal install --all
123
+ ```
124
+
125
+ Then use your coding agent normally.
126
+
127
+ ## Lifecycle
128
+
129
+ ```bash
130
+ npx djournal status
131
+ npx djournal doctor
132
+ npx djournal upgrade
133
+ npx djournal uninstall
134
+ ```
135
+
136
+ Installation preserves existing agent configuration. Uninstallation removes
137
+ djournal's tooling while retaining `.journal/` so the project memory can be
138
+ revived later.
139
+
140
+ Existing `AGENTS.md` and `CLAUDE.md` files are never replaced. djournal adds an
141
+ owned block, updates only that block, and removes only that block during
142
+ uninstall; surrounding project instructions remain untouched.
143
+
144
+ See [spec.md](spec.md) for the complete data model and workflow contracts.
145
+
146
+ ## Status
147
+
148
+ Codex and Claude Code are supported. OpenCode, Pi, and Zed adapters are planned.
149
+
150
+ ## Contributing and releases
151
+
152
+ Pull request titles use Conventional Commit form, such as
153
+ `feat(installer): support zed` or `fix: preserve existing hooks`. Merges to
154
+ `main` are released automatically after the initial npm/OIDC bootstrap. Before
155
+ 1.0, breaking changes increment the minor version; from 1.0 onward they
156
+ increment the major version.
157
+
158
+ djournal is licensed under the [Apache License 2.0](LICENSE).
package/bin/journal.js ADDED
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/env node
2
+
3
+ "use strict";
4
+
5
+ const path = require("node:path");
6
+ const {
7
+ InstallerError,
8
+ doctor,
9
+ install,
10
+ status,
11
+ uninstall,
12
+ upgrade,
13
+ } = require("../lib/installer/index.js");
14
+
15
+ const sourceRoot = path.resolve(__dirname, "..");
16
+
17
+ function usage() {
18
+ return `Usage:
19
+ journal install [--target DIR] [--harness LIST | --all | --instructions-only]
20
+ journal upgrade [--target DIR]
21
+ journal uninstall [--target DIR] [--harness LIST | --all]
22
+ journal status [--target DIR] [--json]
23
+ journal doctor [--target DIR] [--json]
24
+
25
+ Options:
26
+ --dry-run Show the planned operation without writing
27
+ --yes Disable interactive harness selection
28
+ --json Emit JSON
29
+ --harness LIST Comma-separated codex,claude-code selection
30
+ --all Select or remove every supported harness
31
+ --instructions-only Install core instructions without harness hooks
32
+ `;
33
+ }
34
+
35
+ function parseArgs(argv) {
36
+ const args = [...argv];
37
+ const command = args.shift();
38
+ if (!command || !["install", "upgrade", "uninstall", "status", "doctor"].includes(command)) {
39
+ throw new InstallerError(usage(), "USAGE");
40
+ }
41
+ const options = { command, harnesses: [] };
42
+ while (args.length) {
43
+ const arg = args.shift();
44
+ if (arg === "--target") {
45
+ if (!args.length) throw new InstallerError("--target requires a value", "USAGE");
46
+ options.target = args.shift();
47
+ } else if (arg.startsWith("--target=")) options.target = arg.slice(9);
48
+ else if (arg === "--harness") {
49
+ if (!args.length) throw new InstallerError("--harness requires a value", "USAGE");
50
+ options.harnesses.push(...args.shift().split(",").filter(Boolean));
51
+ } else if (arg.startsWith("--harness=")) options.harnesses.push(...arg.slice(10).split(",").filter(Boolean));
52
+ else if (arg === "--all") options.all = true;
53
+ else if (arg === "--instructions-only") options.instructionsOnly = true;
54
+ else if (arg === "--dry-run") options.dryRun = true;
55
+ else if (arg === "--yes") options.yes = true;
56
+ else if (arg === "--json") options.json = true;
57
+ else if (arg === "--help" || arg === "-h") throw new InstallerError(usage(), "HELP");
58
+ else throw new InstallerError(`unknown option: ${arg}`, "USAGE");
59
+ }
60
+ if (options.all && options.harnesses.length) throw new InstallerError("use either --all or --harness", "USAGE");
61
+ if (options.instructionsOnly && (options.all || options.harnesses.length)) {
62
+ throw new InstallerError("--instructions-only cannot be combined with harness selection", "USAGE");
63
+ }
64
+ options.target = path.resolve(options.target || process.cwd());
65
+ options.sourceRoot = sourceRoot;
66
+ options.interactive = !options.yes && process.stdin.isTTY && process.stdout.isTTY;
67
+ return options;
68
+ }
69
+
70
+ function print(value, json) {
71
+ if (json) {
72
+ process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
73
+ return;
74
+ }
75
+ if (value.action) process.stdout.write(`${value.action}: ${value.target}\n`);
76
+ else if (typeof value.installed === "boolean") process.stdout.write(value.installed ? `installed: ${value.target}\n` : `not installed: ${value.target}\n`);
77
+ else process.stdout.write(`${value.ok ? "ok" : "failed"}: ${value.target}\n`);
78
+ if (value.harnesses) process.stdout.write(`harnesses: ${value.harnesses.join(", ") || "instructions-only"}\n`);
79
+ if (value.conflicts?.length) process.stdout.write(`conflicts: ${value.conflicts.join(", ")}\n`);
80
+ if (value.files) {
81
+ for (const file of value.files) process.stdout.write(`${file.status.padEnd(8)} ${file.path}\n`);
82
+ }
83
+ if (value.checks) {
84
+ for (const check of value.checks) process.stdout.write(`${check.ok ? "ok" : "fail"} ${check.name}: ${check.detail}\n`);
85
+ }
86
+ }
87
+
88
+ function exitCodeFor(code) {
89
+ if (["USAGE", "HELP"].includes(code)) return code === "HELP" ? 0 : 1;
90
+ if (["ASSET_CONFLICT", "HARNESS_SELECTION_REQUIRED"].includes(code)) return 2;
91
+ if (["DOCTOR_FAILED", "INVALID_JSON", "INVALID_TARGET", "UNSAFE_PATH", "UNSUPPORTED_MANIFEST"].includes(code)) return 3;
92
+ if (code === "NOT_INSTALLED") return 4;
93
+ return 1;
94
+ }
95
+
96
+ async function main() {
97
+ try {
98
+ const options = parseArgs(process.argv.slice(2));
99
+ let result;
100
+ if (options.command === "install") result = await install(options);
101
+ else if (options.command === "upgrade") result = await upgrade(options);
102
+ else if (options.command === "uninstall") result = uninstall(options);
103
+ else if (options.command === "status") result = status(options);
104
+ else result = doctor(options);
105
+ print(result, options.json);
106
+ if (result.ok === false || result.installed === false || result.clean === false || result.conflicts?.length) process.exitCode = 2;
107
+ } catch (error) {
108
+ const code = error instanceof InstallerError ? error.code : "UNEXPECTED";
109
+ if (process.argv.includes("--json")) {
110
+ process.stderr.write(`${JSON.stringify({ ok: false, code, message: error.message }, null, 2)}\n`);
111
+ } else process.stderr.write(`${code}: ${error.message}\n`);
112
+ process.exitCode = exitCodeFor(code);
113
+ }
114
+ }
115
+
116
+ if (require.main === module) main();
117
+
118
+ module.exports = { parseArgs };
package/install.sh ADDED
@@ -0,0 +1,35 @@
1
+ #!/bin/sh
2
+
3
+ set -eu
4
+
5
+ if ! command -v node >/dev/null 2>&1; then
6
+ echo "djournal requires Node 18 or newer" >&2
7
+ exit 1
8
+ fi
9
+
10
+ major=$(node -p 'process.versions.node.split(".")[0]')
11
+ if [ "$major" -lt 18 ]; then
12
+ echo "djournal requires Node 18 or newer" >&2
13
+ exit 1
14
+ fi
15
+
16
+ if [ -n "${JOURNAL_SOURCE_DIR:-}" ]; then
17
+ source_dir=$JOURNAL_SOURCE_DIR
18
+ else
19
+ source_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
20
+ fi
21
+
22
+ if [ ! -f "$source_dir/bin/journal.js" ]; then
23
+ echo "djournal source not found; set JOURNAL_SOURCE_DIR to an unpacked release or source checkout" >&2
24
+ exit 1
25
+ fi
26
+
27
+ command=install
28
+ case "${1:-}" in
29
+ install|upgrade|uninstall|status|doctor)
30
+ command=$1
31
+ shift
32
+ ;;
33
+ esac
34
+
35
+ exec node "$source_dir/bin/journal.js" "$command" "$@"