@the-librarian/cli 1.0.0-rc.3 → 1.0.0-rc.30
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.
- package/LICENSE +201 -0
- package/dist/bin.js +0 -0
- package/dist/commands/install.d.ts +6 -0
- package/dist/commands/install.d.ts.map +1 -1
- package/dist/commands/install.js +54 -2
- package/dist/commands/install.js.map +1 -1
- package/dist/harnesses/codex.d.ts +13 -0
- package/dist/harnesses/codex.d.ts.map +1 -1
- package/dist/harnesses/codex.js +217 -26
- package/dist/harnesses/codex.js.map +1 -1
- package/dist/harnesses/hermes.d.ts +1 -1
- package/dist/harnesses/hermes.d.ts.map +1 -1
- package/dist/harnesses/hermes.js +7 -3
- package/dist/harnesses/hermes.js.map +1 -1
- package/dist/harnesses/opencode.d.ts +12 -0
- package/dist/harnesses/opencode.d.ts.map +1 -1
- package/dist/harnesses/opencode.js +125 -4
- package/dist/harnesses/opencode.js.map +1 -1
- package/dist/paths.d.ts +16 -0
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +22 -0
- package/dist/paths.js.map +1 -1
- package/dist/prompt.d.ts +7 -0
- package/dist/prompt.d.ts.map +1 -1
- package/dist/prompt.js +79 -29
- package/dist/prompt.js.map +1 -1
- package/dist/runtime.d.ts +20 -0
- package/dist/runtime.d.ts.map +1 -1
- package/dist/runtime.js +252 -7
- package/dist/runtime.js.map +1 -1
- package/dist/server/admin.d.ts +31 -0
- package/dist/server/admin.d.ts.map +1 -0
- package/dist/server/admin.js +131 -0
- package/dist/server/admin.js.map +1 -0
- package/dist/server/autoupdate.d.ts +184 -0
- package/dist/server/autoupdate.d.ts.map +1 -0
- package/dist/server/autoupdate.js +794 -0
- package/dist/server/autoupdate.js.map +1 -0
- package/dist/server/boot.d.ts +51 -0
- package/dist/server/boot.d.ts.map +1 -0
- package/dist/server/boot.js +233 -0
- package/dist/server/boot.js.map +1 -0
- package/dist/server/deploy-state.d.ts +33 -0
- package/dist/server/deploy-state.d.ts.map +1 -0
- package/dist/server/deploy-state.js +79 -0
- package/dist/server/deploy-state.js.map +1 -0
- package/dist/server/docker.d.ts +53 -0
- package/dist/server/docker.d.ts.map +1 -0
- package/dist/server/docker.js +166 -0
- package/dist/server/docker.js.map +1 -0
- package/dist/server/down.d.ts +19 -0
- package/dist/server/down.d.ts.map +1 -0
- package/dist/server/down.js +62 -0
- package/dist/server/down.js.map +1 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +50 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/logs.d.ts +50 -0
- package/dist/server/logs.d.ts.map +1 -0
- package/dist/server/logs.js +162 -0
- package/dist/server/logs.js.map +1 -0
- package/dist/server/preflight.d.ts +24 -0
- package/dist/server/preflight.d.ts.map +1 -0
- package/dist/server/preflight.js +58 -0
- package/dist/server/preflight.js.map +1 -0
- package/dist/server/redact.d.ts +2 -0
- package/dist/server/redact.d.ts.map +1 -0
- package/dist/server/redact.js +26 -0
- package/dist/server/redact.js.map +1 -0
- package/dist/server/status.d.ts +20 -0
- package/dist/server/status.d.ts.map +1 -0
- package/dist/server/status.js +103 -0
- package/dist/server/status.js.map +1 -0
- package/dist/server/up.d.ts +226 -0
- package/dist/server/up.d.ts.map +1 -0
- package/dist/server/up.js +723 -0
- package/dist/server/up.js.map +1 -0
- package/dist/server/update.d.ts +35 -0
- package/dist/server/update.d.ts.map +1 -0
- package/dist/server/update.js +308 -0
- package/dist/server/update.js.map +1 -0
- package/package.json +10 -11
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/dist/bin.js
CHANGED
|
File without changes
|
|
@@ -4,6 +4,12 @@ export interface InstallDeps {
|
|
|
4
4
|
home?: string | undefined;
|
|
5
5
|
shell?: Shell | undefined;
|
|
6
6
|
prompter: Prompter;
|
|
7
|
+
/**
|
|
8
|
+
* The process environment to read existing `LIBRARIAN_*` vars from (BUG 2).
|
|
9
|
+
* Injectable so tests never read the real `process.env`. Defaults to
|
|
10
|
+
* `process.env`. The token value is never logged.
|
|
11
|
+
*/
|
|
12
|
+
env?: NodeJS.ProcessEnv | undefined;
|
|
7
13
|
}
|
|
8
14
|
export interface InstallOutcome {
|
|
9
15
|
installed: string[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/commands/install.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAIvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC1B,QAAQ,EAAE,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/commands/install.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAIvC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAG7C,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,KAAK,GAAG,SAAS,CAAC;IAC1B,QAAQ,EAAE,QAAQ,CAAC;IACnB;;;;OAIG;IACH,GAAG,CAAC,EAAE,MAAM,CAAC,UAAU,GAAG,SAAS,CAAC;CACrC;AAED,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,MAAM,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IACzC,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,+EAA+E;AAC/E,wBAAsB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CA2D5F"}
|
package/dist/commands/install.js
CHANGED
|
@@ -79,21 +79,73 @@ export async function runInstall(named, deps) {
|
|
|
79
79
|
* Returns the in-memory config and whether it differs from what's persisted
|
|
80
80
|
* (so the caller can defer the actual `setConfig` write until a harness
|
|
81
81
|
* install has succeeded — S1). Does NOT touch the filesystem.
|
|
82
|
+
*
|
|
83
|
+
* Source precedence (BUG 2 — reuse existing `LIBRARIAN_*`):
|
|
84
|
+
* 1. `~/.librarian/env` already has BOTH values → use them, no prompts.
|
|
85
|
+
* 2. Otherwise, consult `process.env` (injected as `deps.env`):
|
|
86
|
+
* - BOTH `LIBRARIAN_MCP_URL` + `LIBRARIAN_AGENT_TOKEN` present → offer
|
|
87
|
+
* to reuse them (URL shown in full, token redacted to
|
|
88
|
+
* `LIBRARIAN_AGENT_TOKEN=set` — the value is NEVER displayed). Accept
|
|
89
|
+
* → use them; decline → prompt for fresh values.
|
|
90
|
+
* - Only ONE present → prefill it as that prompt's default so the user
|
|
91
|
+
* can accept with enter; prompt for the other.
|
|
92
|
+
* - Neither → prompt for both (unchanged behaviour).
|
|
93
|
+
* The token value is never logged.
|
|
82
94
|
*/
|
|
83
95
|
async function resolveConfig(deps) {
|
|
84
96
|
const existing = readConfig(deps.home);
|
|
97
|
+
const env = deps.env ?? process.env;
|
|
98
|
+
const envUrl = (env.LIBRARIAN_MCP_URL ?? "").trim();
|
|
99
|
+
const envToken = (env.LIBRARIAN_AGENT_TOKEN ?? "").trim();
|
|
85
100
|
let mcpUrl = existing?.mcpUrl ?? "";
|
|
86
101
|
let token = existing?.token ?? "";
|
|
102
|
+
// When both env vars are present we offer to reuse them as a pair; if the
|
|
103
|
+
// user DECLINES we prompt for fresh values WITHOUT prefilling the rejected
|
|
104
|
+
// env defaults. A single env var, by contrast, prefills its prompt's default.
|
|
105
|
+
let declinedEnvPair = false;
|
|
106
|
+
// (2) Only consult the environment when the persisted config is incomplete.
|
|
107
|
+
if ((!mcpUrl || !token) && envUrl && envToken) {
|
|
108
|
+
// Both present → offer to reuse them, showing the URL but redacting the
|
|
109
|
+
// token (only that it's set, never its value).
|
|
110
|
+
const question = [
|
|
111
|
+
"Found these in your environment:",
|
|
112
|
+
` LIBRARIAN_MCP_URL=${envUrl}`,
|
|
113
|
+
" LIBRARIAN_AGENT_TOKEN=set",
|
|
114
|
+
"Use the LIBRARIAN_MCP_URL and LIBRARIAN_AGENT_TOKEN from your environment? [Y/n]",
|
|
115
|
+
].join("\n");
|
|
116
|
+
const answer = await deps.prompter.promptText(question, { default: "y" });
|
|
117
|
+
if (isYes(answer)) {
|
|
118
|
+
if (!mcpUrl)
|
|
119
|
+
mcpUrl = envUrl;
|
|
120
|
+
if (!token)
|
|
121
|
+
token = envToken;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
declinedEnvPair = true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Prompt for anything still missing. When exactly one env var is present (and
|
|
128
|
+
// we didn't just decline the both-present pair), prefill it as the prompt's
|
|
129
|
+
// default so the user can accept it with a bare enter.
|
|
87
130
|
if (!mcpUrl) {
|
|
88
|
-
|
|
131
|
+
const opts = envUrl && !declinedEnvPair ? { default: envUrl } : undefined;
|
|
132
|
+
mcpUrl = await deps.prompter.promptText("MCP URL", opts);
|
|
89
133
|
}
|
|
90
134
|
if (!token) {
|
|
91
|
-
|
|
135
|
+
// A secret prompt never echoes a default, but a present env token can still
|
|
136
|
+
// back an empty reply — so pass it as the default invisibly.
|
|
137
|
+
const opts = envToken && !declinedEnvPair ? { default: envToken, secret: true } : { secret: true };
|
|
138
|
+
token = await deps.prompter.promptText("Agent token", opts);
|
|
92
139
|
}
|
|
93
140
|
const changed = mcpUrl !== existing?.mcpUrl || token !== existing?.token;
|
|
94
141
|
const cfg = { mcpUrl, token, serverUrl: deriveServerUrl(mcpUrl) };
|
|
95
142
|
return { cfg, changed };
|
|
96
143
|
}
|
|
144
|
+
/** A yes/no answer parser — empty (bare enter) counts as yes given a "y" default. */
|
|
145
|
+
function isYes(answer) {
|
|
146
|
+
const a = answer.trim().toLowerCase();
|
|
147
|
+
return a === "" || a === "y" || a === "yes";
|
|
148
|
+
}
|
|
97
149
|
/**
|
|
98
150
|
* Resolve the harness set to install into:
|
|
99
151
|
* - explicit args (validated) win;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/commands/install.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,EAAE;AACF,QAAQ;AACR,yEAAyE;AACzE,8EAA8E;AAC9E,4EAA4E;AAC5E,qEAAqE;AACrE,+EAA+E;AAC/E,+EAA+E;AAC/E,+DAA+D;AAC/D,uEAAuE;AACvE,2EAA2E;AAC3E,4DAA4D;AAC5D,wEAAwE;AAExE,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,SAAS,EAAwB,MAAM,cAAc,CAAC;AAE5F,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAsB,MAAM,uBAAuB,CAAC;AAEtF,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/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KAAK,CAAC,IAAI,CAAC,uBAAuB,CAAC,CAAC;IACtC,CAAC;IACD,KAAK,CAAC,IAAI,CACR,EAAE,EACF,kFAAkF,CACnF,CAAC;AACJ,CAAC;AAED,8EAA8E;AAC9E,SAAS,aAAa,CAAC,OAAe;IACpC,OAAO,oBAAoB,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -1,3 +1,16 @@
|
|
|
1
1
|
import type { HarnessModule } from "./types.js";
|
|
2
|
+
export declare const CODEX_CAPTURE_PINNED_REF: string;
|
|
3
|
+
/**
|
|
4
|
+
* Fetches the Codex capture integration for a pinned ref and returns the absolute
|
|
5
|
+
* path to a directory whose contents ARE the integration (the equivalent of
|
|
6
|
+
* `integrations/codex/`, i.e. holding `scripts/**` and `hooks/codex-hooks.json`).
|
|
7
|
+
* The caller copies from there. Injectable so tests substitute a local fixture
|
|
8
|
+
* instead of the network.
|
|
9
|
+
*/
|
|
10
|
+
export type CaptureFetcher = (ref: string) => Promise<string>;
|
|
11
|
+
/** Override the capture-adapter fetcher (tests inject a local-fixture fetcher). */
|
|
12
|
+
export declare function setCodexCaptureFetcher(next: CaptureFetcher): void;
|
|
13
|
+
/** Restore the default (network) capture-adapter fetcher (tests). */
|
|
14
|
+
export declare function resetCodexCaptureFetcher(): void;
|
|
2
15
|
export declare const codex: HarnessModule;
|
|
3
16
|
//# sourceMappingURL=codex.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/harnesses/codex.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"codex.d.ts","sourceRoot":"","sources":["../../src/harnesses/codex.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,YAAY,CAAC;AA0C/D,eAAO,MAAM,wBAAwB,QAAqB,CAAC;AAsF3D;;;;;;GAMG;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AAmC9D,mFAAmF;AACnF,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,cAAc,GAAG,IAAI,CAEjE;AAED,qEAAqE;AACrE,wBAAgB,wBAAwB,IAAI,IAAI,CAE/C;AA4HD,eAAO,MAAM,KAAK,EAAE,aAiDnB,CAAC"}
|
package/dist/harnesses/codex.js
CHANGED
|
@@ -16,9 +16,11 @@
|
|
|
16
16
|
// it resolves the value at request time. We pass `cfg.mcpUrl` (not the
|
|
17
17
|
// token) on the CLI, so nothing secret is ever logged.
|
|
18
18
|
import fs from "node:fs";
|
|
19
|
+
import os from "node:os";
|
|
19
20
|
import path from "node:path";
|
|
20
21
|
import { run, which } from "../exec.js";
|
|
21
|
-
import { codexConfigPath } from "../paths.js";
|
|
22
|
+
import { codexCaptureDir, codexConfigPath, codexHooksPath } from "../paths.js";
|
|
23
|
+
import { cliVersion } from "../version.js";
|
|
22
24
|
const CLI = "codex";
|
|
23
25
|
const SERVER_ID = "librarian";
|
|
24
26
|
const TOKEN_ENV_VAR = "LIBRARIAN_AGENT_TOKEN";
|
|
@@ -27,6 +29,37 @@ const TABLE_HEADER = "[mcp_servers.librarian]";
|
|
|
27
29
|
// though TOML carries no native version for an MCP entry.
|
|
28
30
|
const CONFIG_VERSION = "1";
|
|
29
31
|
const VERSION_MARKER = "# librarian-config-version =";
|
|
32
|
+
// ── Auto-capture hooks wiring (spec 2026-06-16-harness-auto-capture, Phase 2A) ─
|
|
33
|
+
//
|
|
34
|
+
// Codex fires the same command-hook events as Claude (UserPromptSubmit / Stop /
|
|
35
|
+
// SessionEnd). Codex discovers lifecycle hooks ONLY at ~/.codex/hooks.json (no
|
|
36
|
+
// plugin host auto-wires them), so — mirroring mem0's install_codex_hooks.py — we
|
|
37
|
+
// MERGE our entries into that file (creating it if absent) and surface the
|
|
38
|
+
// `codex_hooks = true` feature-flag requirement. The merge is idempotent: entries
|
|
39
|
+
// we own are identified by an owner marker in the command string and stripped
|
|
40
|
+
// before fresh ones are added, so re-install/upgrade leaves no duplicates.
|
|
41
|
+
//
|
|
42
|
+
// The capture-adapter scripts (integrations/codex/scripts/**) do NOT ship with
|
|
43
|
+
// the published installer (it ships only dist/), so — exactly like the Hermes
|
|
44
|
+
// adapter — we FETCH them from the pinned release tarball and copy them under
|
|
45
|
+
// ~/.librarian/codex-capture; the merged hook commands point their
|
|
46
|
+
// ${LIBRARIAN_CODEX_ROOT} placeholder at that dir.
|
|
47
|
+
//
|
|
48
|
+
// ASSUMPTION (the one genuine unknown): the assumed hook events + payload shape
|
|
49
|
+
// are derived from mem0's proven Codex wiring + the Claude payload (documented in
|
|
50
|
+
// integrations/codex/scripts/lib/transcript.mjs). SC1 (true e2e against a running
|
|
51
|
+
// Codex) is DEFERRED — there is no codex CLI on the build machine to confirm.
|
|
52
|
+
// The placeholder in hooks/codex-hooks.json, rewritten to the absolute scripts
|
|
53
|
+
// install dir at merge time. Matches the env var the entry shell reads.
|
|
54
|
+
const ROOT_PLACEHOLDER = "${LIBRARIAN_CODEX_ROOT}";
|
|
55
|
+
// Substring that identifies entries THIS installer owns (stable across install
|
|
56
|
+
// paths), so the merge can strip + re-add idempotently. Mirrors mem0's
|
|
57
|
+
// OWNER_MARKER = "mem0-plugin".
|
|
58
|
+
const HOOKS_OWNER_MARKER = "the-librarian-codex";
|
|
59
|
+
// The pinned monorepo release we fetch the adapter from: the tag matching this
|
|
60
|
+
// CLI's own version. DERIVED (not hardcoded) so it can't drift — same rationale
|
|
61
|
+
// as the Hermes adapter's PINNED_REF.
|
|
62
|
+
export const CODEX_CAPTURE_PINNED_REF = `v${cliVersion()}`;
|
|
30
63
|
/** Read config.toml, or "" if it doesn't exist yet. */
|
|
31
64
|
function readConfig() {
|
|
32
65
|
try {
|
|
@@ -106,6 +139,141 @@ function writeConfig(content) {
|
|
|
106
139
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
107
140
|
fs.writeFileSync(file, content, "utf8");
|
|
108
141
|
}
|
|
142
|
+
/** The default fetcher: codeload tarball → `tar` extract → integration dir. */
|
|
143
|
+
const defaultCaptureFetcher = async (ref) => {
|
|
144
|
+
const url = `https://codeload.github.com/JimJafar/the-librarian/tar.gz/refs/tags/${ref}`;
|
|
145
|
+
const work = fs.mkdtempSync(path.join(os.tmpdir(), "librarian-codex-fetch-"));
|
|
146
|
+
const tarball = path.join(work, "src.tar.gz");
|
|
147
|
+
const res = await fetch(url, { redirect: "error" });
|
|
148
|
+
if (!res.ok) {
|
|
149
|
+
throw new Error(`Failed to fetch Codex capture adapter (${ref}): HTTP ${res.status}`);
|
|
150
|
+
}
|
|
151
|
+
const buf = Buffer.from(await res.arrayBuffer());
|
|
152
|
+
fs.writeFileSync(tarball, buf);
|
|
153
|
+
// codeload nests the integration at `the-librarian-<ref>/integrations/codex/**`
|
|
154
|
+
// — three leading path components. Strip them so `scripts/` + `hooks/` land at
|
|
155
|
+
// the extraction root, which is what the caller copies into ~/.librarian/.
|
|
156
|
+
const out = path.join(work, "adapter");
|
|
157
|
+
fs.mkdirSync(out, { recursive: true });
|
|
158
|
+
const extract = await run("tar", [
|
|
159
|
+
"-xzf",
|
|
160
|
+
tarball,
|
|
161
|
+
"-C",
|
|
162
|
+
out,
|
|
163
|
+
"--strip-components=3",
|
|
164
|
+
"--wildcards",
|
|
165
|
+
"*/integrations/codex/*",
|
|
166
|
+
]);
|
|
167
|
+
if (extract.code !== 0) {
|
|
168
|
+
throw new Error(`Failed to extract Codex capture adapter: ${(extract.stderr || "").trim()}`);
|
|
169
|
+
}
|
|
170
|
+
return out;
|
|
171
|
+
};
|
|
172
|
+
let captureFetcher = defaultCaptureFetcher;
|
|
173
|
+
/** Override the capture-adapter fetcher (tests inject a local-fixture fetcher). */
|
|
174
|
+
export function setCodexCaptureFetcher(next) {
|
|
175
|
+
captureFetcher = next;
|
|
176
|
+
}
|
|
177
|
+
/** Restore the default (network) capture-adapter fetcher (tests). */
|
|
178
|
+
export function resetCodexCaptureFetcher() {
|
|
179
|
+
captureFetcher = defaultCaptureFetcher;
|
|
180
|
+
}
|
|
181
|
+
/** Recursively copy a directory tree, overwriting any prior copy (idempotent). */
|
|
182
|
+
function copyDir(from, to) {
|
|
183
|
+
fs.rmSync(to, { recursive: true, force: true });
|
|
184
|
+
fs.mkdirSync(path.dirname(to), { recursive: true });
|
|
185
|
+
fs.cpSync(from, to, { recursive: true });
|
|
186
|
+
}
|
|
187
|
+
/** Read ~/.codex/hooks.json, or an empty shape if absent/unparseable. */
|
|
188
|
+
function readHooksFile() {
|
|
189
|
+
try {
|
|
190
|
+
const raw = fs.readFileSync(codexHooksPath(), "utf8");
|
|
191
|
+
const parsed = JSON.parse(raw);
|
|
192
|
+
if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
|
|
193
|
+
return parsed;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
// absent / unreadable / malformed — start from an empty shape
|
|
198
|
+
}
|
|
199
|
+
return { hooks: {} };
|
|
200
|
+
}
|
|
201
|
+
function writeHooksFile(config) {
|
|
202
|
+
const file = codexHooksPath();
|
|
203
|
+
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
204
|
+
fs.writeFileSync(file, `${JSON.stringify(config, null, 2)}\n`, "utf8");
|
|
205
|
+
}
|
|
206
|
+
/** Does this entry belong to us (owner marker in any command string)? */
|
|
207
|
+
function isOwnedEntry(entry) {
|
|
208
|
+
return (entry.hooks ?? []).some((h) => typeof h.command === "string" && h.command.includes(HOOKS_OWNER_MARKER));
|
|
209
|
+
}
|
|
210
|
+
/** Remove every entry we own from a hooks file (so a re-merge can't duplicate). */
|
|
211
|
+
function stripOwnedEntries(config) {
|
|
212
|
+
const hooks = config.hooks ?? {};
|
|
213
|
+
for (const event of Object.keys(hooks)) {
|
|
214
|
+
hooks[event] = (hooks[event] ?? []).filter((e) => !isOwnedEntry(e));
|
|
215
|
+
if (hooks[event].length === 0)
|
|
216
|
+
delete hooks[event];
|
|
217
|
+
}
|
|
218
|
+
config.hooks = hooks;
|
|
219
|
+
return config;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Load our hooks template, rewrite the ${LIBRARIAN_CODEX_ROOT} placeholder to the
|
|
223
|
+
* absolute scripts dir, and return the parsed shape. The template lives in the
|
|
224
|
+
* fetched integration dir alongside the scripts it points at.
|
|
225
|
+
*/
|
|
226
|
+
function loadTemplate(integrationDir, scriptsRoot) {
|
|
227
|
+
const raw = fs.readFileSync(path.join(integrationDir, "hooks", "codex-hooks.json"), "utf8");
|
|
228
|
+
// JSON-string-escape the path so a backslash (Windows) can't break the JSON.
|
|
229
|
+
const safe = JSON.stringify(scriptsRoot).slice(1, -1);
|
|
230
|
+
const rewritten = raw.split(ROOT_PLACEHOLDER).join(safe);
|
|
231
|
+
return JSON.parse(rewritten);
|
|
232
|
+
}
|
|
233
|
+
/** Merge template entries onto a (stripped) config, appending per event. */
|
|
234
|
+
function mergeTemplate(config, template) {
|
|
235
|
+
const hooks = (config.hooks ??= {});
|
|
236
|
+
for (const [event, entries] of Object.entries(template.hooks ?? {})) {
|
|
237
|
+
// Only `template.hooks` is iterated, so the template's top-level "//" doc key
|
|
238
|
+
// (a sibling of `hooks`, not inside it) is never carried over — excluded
|
|
239
|
+
// structurally, no filtering needed here.
|
|
240
|
+
(hooks[event] ??= []).push(...entries);
|
|
241
|
+
}
|
|
242
|
+
return config;
|
|
243
|
+
}
|
|
244
|
+
/** True iff `codex_hooks = true` is set under [features] in config.toml. */
|
|
245
|
+
function captureFeatureFlagEnabled(config) {
|
|
246
|
+
for (const line of config.split("\n")) {
|
|
247
|
+
// Strip an inline comment, then collapse whitespace, so `codex_hooks = true`
|
|
248
|
+
// (any spacing) matches but a `# codex_hooks = true` comment does not.
|
|
249
|
+
const stripped = (line.split("#", 1)[0] ?? "").trim().replace(/\s+/g, "");
|
|
250
|
+
if (stripped === "codex_hooks=true")
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Wire (or re-wire) the per-turn capture hooks: fetch + copy the adapter scripts,
|
|
257
|
+
* then idempotently merge our entries into ~/.codex/hooks.json. Returns whether
|
|
258
|
+
* the user still needs to enable the `codex_hooks` feature flag (so the caller can
|
|
259
|
+
* surface the hint, mirroring mem0's print_feature_flag_hint).
|
|
260
|
+
*/
|
|
261
|
+
async function installCaptureHooks() {
|
|
262
|
+
const integrationDir = await captureFetcher(CODEX_CAPTURE_PINNED_REF);
|
|
263
|
+
const scriptsRoot = codexCaptureDir();
|
|
264
|
+
copyDir(integrationDir, scriptsRoot);
|
|
265
|
+
const template = loadTemplate(integrationDir, scriptsRoot);
|
|
266
|
+
const config = stripOwnedEntries(readHooksFile());
|
|
267
|
+
writeHooksFile(mergeTemplate(config, template));
|
|
268
|
+
return { featureFlagNeeded: !captureFeatureFlagEnabled(readConfig()) };
|
|
269
|
+
}
|
|
270
|
+
/** Remove our capture wiring: strip owned hook entries + delete the scripts dir. */
|
|
271
|
+
function uninstallCaptureHooks() {
|
|
272
|
+
if (fs.existsSync(codexHooksPath())) {
|
|
273
|
+
writeHooksFile(stripOwnedEntries(readHooksFile()));
|
|
274
|
+
}
|
|
275
|
+
fs.rmSync(codexCaptureDir(), { recursive: true, force: true });
|
|
276
|
+
}
|
|
109
277
|
export const codex = {
|
|
110
278
|
id: "codex",
|
|
111
279
|
displayName: "Codex",
|
|
@@ -117,32 +285,20 @@ export const codex = {
|
|
|
117
285
|
return { installed: true, version };
|
|
118
286
|
},
|
|
119
287
|
async install(cfg) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (result.code !== 0) {
|
|
134
|
-
throw new Error(`codex mcp add failed: ${oneLine(result.stderr || result.stdout)}`);
|
|
135
|
-
}
|
|
136
|
-
// Stamp our config-shape version alongside the CLI-written table so
|
|
137
|
-
// detect can report it (the CLI doesn't write the marker comment).
|
|
138
|
-
stampVersionIfMissing();
|
|
139
|
-
return;
|
|
288
|
+
// Two independently-idempotent halves: (1) the MCP server table (the tools +
|
|
289
|
+
// primer surface) and (2) the per-turn auto-capture hooks. Both run on every
|
|
290
|
+
// install so a second install repairs either half if only one is present.
|
|
291
|
+
await installMcpTable(cfg);
|
|
292
|
+
const { featureFlagNeeded } = await installCaptureHooks();
|
|
293
|
+
// Codex won't FIRE lifecycle hooks until `codex_hooks = true` is set under
|
|
294
|
+
// [features] in config.toml (mirrors mem0's print_feature_flag_hint). We can't
|
|
295
|
+
// edit a TOML table the user owns safely from here, so we SURFACE the one-time
|
|
296
|
+
// requirement on stderr. Fail-soft: this is a hint, never a hard failure.
|
|
297
|
+
if (featureFlagNeeded) {
|
|
298
|
+
process.stderr.write(`\nCodex auto-capture is wired, but Codex won't run the hooks until you enable the\n` +
|
|
299
|
+
`feature flag. Add this to ${codexConfigPath()}:\n\n` +
|
|
300
|
+
` [features]\n codex_hooks = true\n\nThen restart Codex.\n`);
|
|
140
301
|
}
|
|
141
|
-
// Fallback: no `codex` on PATH. We can still write the config file.
|
|
142
|
-
const config = readConfig();
|
|
143
|
-
if (hasTable(config))
|
|
144
|
-
return; // idempotent
|
|
145
|
-
writeConfig(withTable(config, cfg));
|
|
146
302
|
},
|
|
147
303
|
async uninstall() {
|
|
148
304
|
if (await which(CLI)) {
|
|
@@ -155,12 +311,47 @@ export const codex = {
|
|
|
155
311
|
if (hasTable(config) || parseConfigVersion(config) !== undefined) {
|
|
156
312
|
writeConfig(withoutTable(config));
|
|
157
313
|
}
|
|
314
|
+
// Remove the auto-capture wiring (owned hook entries + the scripts dir).
|
|
315
|
+
uninstallCaptureHooks();
|
|
158
316
|
},
|
|
159
317
|
async update(cfg) {
|
|
160
318
|
// Re-applying is idempotent; install short-circuits when present.
|
|
161
319
|
await this.install(cfg);
|
|
162
320
|
},
|
|
163
321
|
};
|
|
322
|
+
/**
|
|
323
|
+
* Install/repair just the MCP server table — the original Codex wiring. Prefers
|
|
324
|
+
* the native `codex` CLI; falls back to editing config.toml directly when the CLI
|
|
325
|
+
* isn't on PATH. Idempotent (a present table is a no-op).
|
|
326
|
+
*/
|
|
327
|
+
async function installMcpTable(cfg) {
|
|
328
|
+
if (await which(CLI)) {
|
|
329
|
+
// Idempotent: if our table is already present, do nothing.
|
|
330
|
+
if (hasTable(readConfig()))
|
|
331
|
+
return;
|
|
332
|
+
const result = await run(CLI, [
|
|
333
|
+
"mcp",
|
|
334
|
+
"add",
|
|
335
|
+
SERVER_ID,
|
|
336
|
+
"--url",
|
|
337
|
+
cfg.mcpUrl,
|
|
338
|
+
"--bearer-token-env-var",
|
|
339
|
+
TOKEN_ENV_VAR,
|
|
340
|
+
]);
|
|
341
|
+
if (result.code !== 0) {
|
|
342
|
+
throw new Error(`codex mcp add failed: ${oneLine(result.stderr || result.stdout)}`);
|
|
343
|
+
}
|
|
344
|
+
// Stamp our config-shape version alongside the CLI-written table so
|
|
345
|
+
// detect can report it (the CLI doesn't write the marker comment).
|
|
346
|
+
stampVersionIfMissing();
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
// Fallback: no `codex` on PATH. We can still write the config file.
|
|
350
|
+
const config = readConfig();
|
|
351
|
+
if (hasTable(config))
|
|
352
|
+
return; // idempotent
|
|
353
|
+
writeConfig(withTable(config, cfg));
|
|
354
|
+
}
|
|
164
355
|
/** If the table exists but our version marker doesn't, add the marker. */
|
|
165
356
|
function stampVersionIfMissing() {
|
|
166
357
|
const config = readConfig();
|