@retrace-dev/cli 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.
- package/LICENSE +202 -0
- package/README.md +13 -0
- package/dist/doctor.d.ts +16 -0
- package/dist/doctor.js +161 -0
- package/dist/export-cli.d.ts +2 -0
- package/dist/export-cli.js +107 -0
- package/dist/gdrive-cli.d.ts +2 -0
- package/dist/gdrive-cli.js +97 -0
- package/dist/git-hook.d.ts +61 -0
- package/dist/git-hook.js +365 -0
- package/dist/github-cli.d.ts +2 -0
- package/dist/github-cli.js +111 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +384 -0
- package/dist/is-main.d.ts +2 -0
- package/dist/is-main.js +13 -0
- package/dist/keys.d.ts +9 -0
- package/dist/keys.js +28 -0
- package/dist/remote-store.d.ts +211 -0
- package/dist/remote-store.js +75 -0
- package/dist/serve.d.ts +11 -0
- package/dist/serve.js +53 -0
- package/dist/sqlite-store.d.ts +246 -0
- package/dist/sqlite-store.js +121 -0
- package/package.json +36 -0
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,13 @@
|
|
|
1
|
+
# @retrace-dev/cli
|
|
2
|
+
|
|
3
|
+
Developer tooling for [Retrace](https://github.com/jordandru/retrace), a verifiable provenance ledger for AI-assisted software work.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm exec --package=@retrace-dev/cli -- retrace doctor
|
|
7
|
+
npm exec --package=@retrace-dev/cli -- retrace status --json
|
|
8
|
+
npm exec --package=@retrace-dev/cli -- retrace-git install --project my-project
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The package also installs `retrace-git`, `retrace-mcp`, `retrace-serve`, `retrace-export`, `retrace-github`, and `retrace-gdrive` binaries. Run the scoped `npm exec --package=@retrace-dev/cli -- retrace` form for doctor/status to avoid collisions with Android's unrelated `retrace` utility.
|
|
12
|
+
|
|
13
|
+
Node.js 22 or newer is required by the local SQLite-backed server. See the [repository README](https://github.com/jordandru/retrace#readme) for configuration and cloud deployment.
|
package/dist/doctor.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Actor, Credential } from "@retrace-dev/core";
|
|
3
|
+
type Level = "pass" | "warn" | "fail";
|
|
4
|
+
export type Finding = {
|
|
5
|
+
level: Level;
|
|
6
|
+
label: string;
|
|
7
|
+
detail: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function missingSchema(remote: Record<string, unknown>, local?: {
|
|
10
|
+
event: string[];
|
|
11
|
+
location: string[];
|
|
12
|
+
artifact: string[];
|
|
13
|
+
actions: string[];
|
|
14
|
+
}): string[];
|
|
15
|
+
export declare function credentialAuthorization(credential: Credential, actor: Actor): Finding;
|
|
16
|
+
export {};
|
package/dist/doctor.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/** retrace doctor — read-only preflight for the Git → Worker developer workflow. */
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
5
|
+
import { homedir } from "node:os";
|
|
6
|
+
import { basename, join, resolve } from "node:path";
|
|
7
|
+
import { Credential, renderProjectStatus, schemaSurface } from "@retrace-dev/core";
|
|
8
|
+
import { commitToEvent, resolveHookToken } from "./git-hook.js";
|
|
9
|
+
import { retraceHeaders } from "./remote-store.js";
|
|
10
|
+
import { isMainModule } from "./is-main.js";
|
|
11
|
+
const git = (repo, args) => execFileSync("git", ["-C", repo, ...args], { encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] }).trim();
|
|
12
|
+
const result = (level, label, detail) => ({ level, label, detail });
|
|
13
|
+
export function missingSchema(remote, local = schemaSurface()) {
|
|
14
|
+
return Object.entries(local).flatMap(([group, keys]) => {
|
|
15
|
+
const seen = Array.isArray(remote[group]) ? remote[group] : [];
|
|
16
|
+
return keys.filter((key) => !seen.includes(key)).map((key) => `${group}.${key}`);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
export function credentialAuthorization(credential, actor) {
|
|
20
|
+
if (credential.trust === "assert") {
|
|
21
|
+
const allowed = credential.allowed_actors ?? [];
|
|
22
|
+
return allowed.some((a) => a.type === actor.type && a.id === actor.id)
|
|
23
|
+
? result("pass", "actor authorization", `${actor.type}/${actor.id} is allowed by ${credential.actor.id}`)
|
|
24
|
+
: result("fail", "actor authorization", `${actor.type}/${actor.id} is not in ${credential.actor.id}.allowed_actors; update RETRACE_CREDENTIALS before committing`);
|
|
25
|
+
}
|
|
26
|
+
return credential.actor.type === actor.type && credential.actor.id === actor.id
|
|
27
|
+
? result("pass", "actor authorization", `${actor.type}/${actor.id} matches the pinned credential`)
|
|
28
|
+
: result("fail", "actor authorization", `HEAD is ${actor.type}/${actor.id}, but credential ${credential.actor.id} is pinned to ${credential.actor.type}/${credential.actor.id}`);
|
|
29
|
+
}
|
|
30
|
+
function loadCredential(cfg, env) {
|
|
31
|
+
if (!cfg.credential) {
|
|
32
|
+
const token = env.RETRACE_HOOK_TOKEN ?? env.RETRACE_TOKEN ?? cfg.token;
|
|
33
|
+
return { token, finding: token ? result("warn", "credential", "using an owner/file token; prefer a named scoped credential") : result("fail", "credential", "no hook token is configured") };
|
|
34
|
+
}
|
|
35
|
+
const file = env.RETRACE_CREDENTIALS_FILE ?? join(homedir(), ".retrace", "worker-credentials.json");
|
|
36
|
+
try {
|
|
37
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
38
|
+
if (!Array.isArray(parsed))
|
|
39
|
+
throw new Error("expected a JSON array");
|
|
40
|
+
const raw = parsed.find((c) => c?.actor?.id === cfg.credential);
|
|
41
|
+
if (!raw)
|
|
42
|
+
throw new Error(`credential ${cfg.credential} was not found`);
|
|
43
|
+
const credential = Credential.parse(raw);
|
|
44
|
+
return { credential, token: resolveHookToken(cfg, env, file), finding: result("pass", "credential", `${cfg.credential} resolved from ${file}`) };
|
|
45
|
+
}
|
|
46
|
+
catch (e) {
|
|
47
|
+
return { finding: result("fail", "credential", `${e?.message ?? e}; check RETRACE_CREDENTIALS_FILE`) };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function main() {
|
|
51
|
+
const args = process.argv.slice(2);
|
|
52
|
+
const command = args[0] === "status" ? "status" : "doctor";
|
|
53
|
+
if (args[0] && args[0] !== "doctor" && args[0] !== "status" && !args[0].startsWith(".") && !args[0].startsWith("/") && !existsSync(resolve(args[0]))) {
|
|
54
|
+
console.error("usage: retrace <doctor [repo] | status [project] [--json]>");
|
|
55
|
+
process.exit(2);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const arg = command === "doctor" ? (args[0] === "doctor" ? args[1] : args[0]) : undefined;
|
|
59
|
+
let repo;
|
|
60
|
+
try {
|
|
61
|
+
repo = resolve(git(resolve(arg ?? process.cwd()), ["rev-parse", "--show-toplevel"]));
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
console.error("FAIL repository — not inside a Git repository (or pass its path)");
|
|
65
|
+
process.exit(1);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const findings = [];
|
|
69
|
+
const cfgPath = join(repo, ".retrace.json");
|
|
70
|
+
let cfg = {};
|
|
71
|
+
if (!existsSync(cfgPath))
|
|
72
|
+
findings.push(result("fail", "repository wiring", `${cfgPath} is missing; run retrace-git install --repo ${repo}`));
|
|
73
|
+
else
|
|
74
|
+
try {
|
|
75
|
+
cfg = JSON.parse(readFileSync(cfgPath, "utf8"));
|
|
76
|
+
findings.push(result("pass", "repository wiring", cfgPath));
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
findings.push(result("fail", "repository wiring", `${cfgPath} is invalid JSON: ${e.message}`));
|
|
80
|
+
}
|
|
81
|
+
const gitDir = resolve(repo, git(repo, ["rev-parse", "--git-dir"]));
|
|
82
|
+
const hook = join(gitDir, "hooks", "post-commit");
|
|
83
|
+
const hookOk = existsSync(hook) && readFileSync(hook, "utf8").includes("# retrace-git hook");
|
|
84
|
+
findings.push(hookOk ? result("pass", "post-commit hook", hook) : result("fail", "post-commit hook", `not installed at ${hook}; run retrace-git install --repo ${repo}`));
|
|
85
|
+
const project = process.env.RETRACE_PROJECT ?? cfg.project ?? basename(repo);
|
|
86
|
+
const url = (process.env.RETRACE_URL ?? cfg.url ?? "").replace(/\/$/, "");
|
|
87
|
+
const auth = loadCredential(cfg, process.env);
|
|
88
|
+
findings.push(auth.finding);
|
|
89
|
+
if (command === "status") {
|
|
90
|
+
const selected = args[1] && !args[1].startsWith("--") ? args[1] : project;
|
|
91
|
+
if (!url) {
|
|
92
|
+
console.error("retrace status: RETRACE_URL or .retrace.json url is required");
|
|
93
|
+
process.exit(1);
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const res = await fetch(`${url}/projects/${encodeURIComponent(selected)}/status`, { headers: retraceHeaders(auth.token) });
|
|
97
|
+
if (!res.ok) {
|
|
98
|
+
console.error(`retrace status: HTTP ${res.status}: ${await res.text()}`);
|
|
99
|
+
process.exit(1);
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const status = await res.json();
|
|
103
|
+
console.log(args.includes("--json") ? JSON.stringify(status, null, 2) : renderProjectStatus(status));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
let headEvent;
|
|
107
|
+
try {
|
|
108
|
+
headEvent = commitToEvent(repo, "HEAD", { ...cfg, project, repoName: cfg.repoName });
|
|
109
|
+
if (auth.credential)
|
|
110
|
+
findings.push(credentialAuthorization(auth.credential, headEvent.actor));
|
|
111
|
+
}
|
|
112
|
+
catch (e) {
|
|
113
|
+
findings.push(result("fail", "HEAD", `could not inspect the current commit: ${e.message}`));
|
|
114
|
+
}
|
|
115
|
+
if (!url)
|
|
116
|
+
findings.push(result("warn", "deployment", "no RETRACE_URL or .retrace.json url; remote checks skipped"));
|
|
117
|
+
else {
|
|
118
|
+
const headers = retraceHeaders(auth.token);
|
|
119
|
+
try {
|
|
120
|
+
const res = await fetch(`${url}/api`, { headers: retraceHeaders() });
|
|
121
|
+
if (!res.ok)
|
|
122
|
+
throw new Error(`HTTP ${res.status}`);
|
|
123
|
+
const api = await res.json();
|
|
124
|
+
const missing = missingSchema(api.schema ?? {});
|
|
125
|
+
findings.push(missing.length ? result("fail", "deployment schema", `would drop: ${missing.join(", ")}; deploy this build first`) : result("pass", "deployment schema", `${url} understands this build`));
|
|
126
|
+
}
|
|
127
|
+
catch (e) {
|
|
128
|
+
findings.push(result("fail", "deployment", `${url}/api is unreachable: ${e.message}`));
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
const res = await fetch(`${url}/projects/${encodeURIComponent(project)}/verify`, { headers });
|
|
132
|
+
if (!res.ok)
|
|
133
|
+
throw new Error(`HTTP ${res.status}: ${await res.text()}`);
|
|
134
|
+
const v = await res.json();
|
|
135
|
+
findings.push(v.ok ? result("pass", "ledger integrity", `${project}: ${v.checked} events verified`) : result("fail", "ledger integrity", `${project}: ${v.reason ?? "verification failed"}`));
|
|
136
|
+
}
|
|
137
|
+
catch (e) {
|
|
138
|
+
findings.push(result("fail", "ledger access", `${e.message}; check URL and credential`));
|
|
139
|
+
}
|
|
140
|
+
if (headEvent) {
|
|
141
|
+
const commit = headEvent.artifacts.find((a) => a.kind === "commit")?.id;
|
|
142
|
+
try {
|
|
143
|
+
const res = await fetch(`${url}/projects/${encodeURIComponent(project)}/events?artifact_id=${encodeURIComponent(commit ?? "")}`, { headers });
|
|
144
|
+
if (!res.ok)
|
|
145
|
+
throw new Error(`HTTP ${res.status}: ${await res.text()}`);
|
|
146
|
+
const events = await res.json();
|
|
147
|
+
findings.push(events.length ? result("pass", "HEAD delivery", `${commit} is event #${events.at(-1)?.seq}`) : result("warn", "HEAD delivery", `${commit} is not in the ledger; run retrace-git commit --repo ${repo} HEAD`));
|
|
148
|
+
}
|
|
149
|
+
catch (e) {
|
|
150
|
+
findings.push(result("fail", "HEAD delivery", e.message));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
for (const f of findings)
|
|
155
|
+
console.log(`${f.level.toUpperCase()} ${f.label} — ${f.detail}`);
|
|
156
|
+
const failed = findings.filter((f) => f.level === "fail").length, warned = findings.filter((f) => f.level === "warn").length;
|
|
157
|
+
console.log(`\n${failed ? "NOT READY" : "READY"} — ${findings.length - failed - warned} passed, ${warned} warnings, ${failed} failures`);
|
|
158
|
+
process.exit(failed ? 1 : 0);
|
|
159
|
+
}
|
|
160
|
+
if (isMainModule(import.meta.url))
|
|
161
|
+
main().catch((e) => { console.error("retrace doctor:", e.message ?? e); process.exit(1); });
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* retrace-export — signing keys, signed exports, offline verification.
|
|
4
|
+
* retrace-export keygen [--print-private] create ~/.retrace/signing-key.json if missing; print kid + public JWK
|
|
5
|
+
* retrace-export export <project> [--artifact <id>] [--out file.json] [--report file.html]
|
|
6
|
+
* retrace-export verify <bundle.json> [--pubkey <jwk.json|url>]
|
|
7
|
+
* retrace-export share <project> [--artifact <id>] [--label ..] [--days n] (local server must be running for the link to resolve)
|
|
8
|
+
* Uses the same store config as the MCP server (RETRACE_DB / RETRACE_URL+RETRACE_TOKEN).
|
|
9
|
+
*/
|
|
10
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
11
|
+
import { buildExportBundle, verifyExportBundle, renderReportHtml, parseSigningKey, newShareId } from "@retrace-dev/core";
|
|
12
|
+
import { makeStore } from "./index.js";
|
|
13
|
+
import { RemoteStore } from "./remote-store.js";
|
|
14
|
+
import { ensureSigningKey } from "./keys.js";
|
|
15
|
+
import { isMainModule } from "./is-main.js";
|
|
16
|
+
function parseArgs(argv) {
|
|
17
|
+
const flags = {};
|
|
18
|
+
const pos = [];
|
|
19
|
+
for (let i = 0; i < argv.length; i++) {
|
|
20
|
+
const a = argv[i];
|
|
21
|
+
if (a.startsWith("--")) {
|
|
22
|
+
const n = argv[i + 1];
|
|
23
|
+
if (n && !n.startsWith("--")) {
|
|
24
|
+
flags[a.slice(2)] = n;
|
|
25
|
+
i++;
|
|
26
|
+
}
|
|
27
|
+
else
|
|
28
|
+
flags[a.slice(2)] = true;
|
|
29
|
+
}
|
|
30
|
+
else
|
|
31
|
+
pos.push(a);
|
|
32
|
+
}
|
|
33
|
+
return { flags, pos };
|
|
34
|
+
}
|
|
35
|
+
async function main() {
|
|
36
|
+
const { flags, pos } = parseArgs(process.argv.slice(2));
|
|
37
|
+
const cmd = pos[0];
|
|
38
|
+
if (cmd === "keygen") {
|
|
39
|
+
const k = await ensureSigningKey();
|
|
40
|
+
console.log(`${k.created ? "created" : "existing"} signing key at ${k.path}\nkid: ${k.kid}\npublic JWK: ${JSON.stringify(k.publicKey)}`);
|
|
41
|
+
if (flags["print-private"])
|
|
42
|
+
console.log(`\nRETRACE_SIGNING_KEY='${JSON.stringify(k.privateKey)}'`);
|
|
43
|
+
else
|
|
44
|
+
console.log(`\nFor the Cloudflare Worker: wrangler secret put RETRACE_SIGNING_KEY (paste the private JWK; print it with --print-private)`);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (cmd === "export") {
|
|
48
|
+
const project = pos[1];
|
|
49
|
+
if (!project)
|
|
50
|
+
throw new Error("usage: retrace-export export <project>");
|
|
51
|
+
const store = makeStore();
|
|
52
|
+
let bundle;
|
|
53
|
+
if (store instanceof RemoteStore)
|
|
54
|
+
bundle = await store.export({ project, artifact_id: flags.artifact });
|
|
55
|
+
else {
|
|
56
|
+
const key = parseSigningKey(process.env.RETRACE_SIGNING_KEY) ?? (await ensureSigningKey()).privateKey;
|
|
57
|
+
bundle = await buildExportBundle(store, { project, artifact_id: flags.artifact }, { signingKey: key, issuerName: process.env.RETRACE_ISSUER });
|
|
58
|
+
}
|
|
59
|
+
const out = flags.out ?? `retrace-${project}${flags.artifact ? "-" + String(flags.artifact).replace(/[^\w.-]+/g, "_") : ""}.json`;
|
|
60
|
+
writeFileSync(out, JSON.stringify(bundle, null, 2));
|
|
61
|
+
console.log(`wrote ${out} — ${bundle.events.length} events, chain ${bundle.chain.ok ? "intact" : "BROKEN"}, ${bundle.signature ? "signed kid " + bundle.issuer.kid : "UNSIGNED"}`);
|
|
62
|
+
if (flags.report) {
|
|
63
|
+
writeFileSync(flags.report, renderReportHtml(bundle, await verifyExportBundle(bundle)));
|
|
64
|
+
console.log(`wrote ${flags.report}`);
|
|
65
|
+
}
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (cmd === "verify") {
|
|
69
|
+
const file = pos[1];
|
|
70
|
+
if (!file)
|
|
71
|
+
throw new Error("usage: retrace-export verify <bundle.json> [--pubkey jwk.json|url]");
|
|
72
|
+
const bundle = JSON.parse(readFileSync(file, "utf8"));
|
|
73
|
+
let trusted;
|
|
74
|
+
if (flags.pubkey) {
|
|
75
|
+
const src = String(flags.pubkey);
|
|
76
|
+
const raw = /^https?:/.test(src) ? await (await fetch(src)).json() : JSON.parse(readFileSync(src, "utf8"));
|
|
77
|
+
trusted = raw.public_key ?? raw;
|
|
78
|
+
}
|
|
79
|
+
const v = await verifyExportBundle(bundle, trusted);
|
|
80
|
+
const ok = v.signature === "valid" && v.events_intact && v.links_consistent && v.chain_ok_at_export;
|
|
81
|
+
console.log(`${ok ? "VALID" : "NOT VALID"} — signature: ${v.signature}${v.kid ? " (kid " + v.kid + (trusted ? ", trusted key" : ", key embedded in bundle") + ")" : ""}; events intact: ${v.events_intact}; links: ${v.links_consistent}; chain ok at export: ${v.chain_ok_at_export}; ${bundle.events.length} events`);
|
|
82
|
+
for (const p of v.problems)
|
|
83
|
+
console.log(" - " + p);
|
|
84
|
+
process.exit(ok ? 0 : 2);
|
|
85
|
+
}
|
|
86
|
+
if (cmd === "share") {
|
|
87
|
+
const project = pos[1];
|
|
88
|
+
if (!project)
|
|
89
|
+
throw new Error("usage: retrace-export share <project>");
|
|
90
|
+
const store = makeStore();
|
|
91
|
+
const body = { project, artifact_id: flags.artifact, label: flags.label, expires_in_days: flags.days ? Number(flags.days) : undefined };
|
|
92
|
+
if (store instanceof RemoteStore) {
|
|
93
|
+
const r = await store.share(body);
|
|
94
|
+
console.log(`${r.url}\nreport: ${r.url}/report`);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const id = newShareId();
|
|
98
|
+
const now = new Date();
|
|
99
|
+
await store.createShare({ id, project, artifact_id: body.artifact_id, label: body.label, created_at: now.toISOString(), expires_at: body.expires_in_days ? new Date(now.getTime() + body.expires_in_days * 86400000).toISOString() : undefined });
|
|
100
|
+
const base = process.env.RETRACE_PUBLIC_URL ?? `http://localhost:${process.env.RETRACE_PORT ?? 7777}`;
|
|
101
|
+
console.log(`${base}/s/${id}\nreport: ${base}/s/${id}/report`);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
console.log("retrace-export <keygen|export <project>|verify <bundle.json>|share <project>> [--artifact id] [--out f] [--report f.html] [--pubkey jwk|url] [--label s] [--days n]");
|
|
105
|
+
}
|
|
106
|
+
if (isMainModule(import.meta.url))
|
|
107
|
+
main().catch((e) => { console.error("retrace-export:", e.message ?? e); process.exit(1); });
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* retrace-gdrive — Google Drive adapter helpers (the Apps Script forwarder is the zero-infra path; this is for backfills & testing).
|
|
4
|
+
* retrace-gdrive backfill --token <OAuth access token> [--project p] [--folder <id>] [--since 2026-08-01] [--max 1000]
|
|
5
|
+
* queries the Drive Activity API directly (scope drive.activity.readonly; e.g. `gcloud auth print-access-token`
|
|
6
|
+
* or OAuth Playground) and logs the mapped events. Actor emails resolve via People API when the token allows.
|
|
7
|
+
* retrace-gdrive replay <payload.json> [--project p] map a saved forwarder payload / activity.query response and log it
|
|
8
|
+
* Store config: RETRACE_DB (local) or RETRACE_URL(+RETRACE_TOKEN).
|
|
9
|
+
*/
|
|
10
|
+
import { readFileSync } from "node:fs";
|
|
11
|
+
import { mapDriveActivities, appendEvent, describeEvent } from "@retrace-dev/core";
|
|
12
|
+
import { makeStore } from "./index.js";
|
|
13
|
+
import { RemoteStore } from "./remote-store.js";
|
|
14
|
+
import { isMainModule } from "./is-main.js";
|
|
15
|
+
function parseArgs(argv) {
|
|
16
|
+
const flags = {};
|
|
17
|
+
const pos = [];
|
|
18
|
+
for (let i = 0; i < argv.length; i++) {
|
|
19
|
+
const a = argv[i];
|
|
20
|
+
if (a.startsWith("--")) {
|
|
21
|
+
const n = argv[i + 1];
|
|
22
|
+
if (n && !n.startsWith("--")) {
|
|
23
|
+
flags[a.slice(2)] = n;
|
|
24
|
+
i++;
|
|
25
|
+
}
|
|
26
|
+
else
|
|
27
|
+
flags[a.slice(2)] = true;
|
|
28
|
+
}
|
|
29
|
+
else
|
|
30
|
+
pos.push(a);
|
|
31
|
+
}
|
|
32
|
+
return { flags, pos };
|
|
33
|
+
}
|
|
34
|
+
async function logAll(payload, project) {
|
|
35
|
+
const inputs = mapDriveActivities({ ...payload, project: project ?? payload.project }, "google-drive");
|
|
36
|
+
const store = makeStore();
|
|
37
|
+
let n = 0, d = 0;
|
|
38
|
+
for (const input of inputs) {
|
|
39
|
+
const r = store instanceof RemoteStore ? await store.append(input) : await appendEvent(store, input);
|
|
40
|
+
r.deduped ? d++ : (n++, console.log(describeEvent(r.event)));
|
|
41
|
+
}
|
|
42
|
+
return { logged: n, deduped: d, mapped: inputs.length };
|
|
43
|
+
}
|
|
44
|
+
async function main() {
|
|
45
|
+
const { flags, pos } = parseArgs(process.argv.slice(2));
|
|
46
|
+
const cmd = pos[0];
|
|
47
|
+
const project = flags.project ?? process.env.RETRACE_PROJECT;
|
|
48
|
+
if (cmd === "replay") {
|
|
49
|
+
const raw = JSON.parse(readFileSync(pos[1], "utf8"));
|
|
50
|
+
const payload = Array.isArray(raw.activities) ? raw : { activities: raw };
|
|
51
|
+
const r = await logAll(payload, project);
|
|
52
|
+
console.log(`replay: ${r.mapped} mapped, ${r.logged} logged, ${r.deduped} deduped`);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (cmd === "backfill") {
|
|
56
|
+
const token = flags.token ?? process.env.GOOGLE_ACCESS_TOKEN;
|
|
57
|
+
if (!token)
|
|
58
|
+
throw new Error("--token <OAuth access token> required (scope drive.activity.readonly)");
|
|
59
|
+
const since = flags.since ? new Date(String(flags.since)).toISOString() : new Date(Date.now() - 7 * 86400000).toISOString();
|
|
60
|
+
const max = Number(flags.max ?? 1000);
|
|
61
|
+
const acts = [];
|
|
62
|
+
let pageToken;
|
|
63
|
+
do {
|
|
64
|
+
const body = { filter: `time >= "${since}"`, pageSize: 100, ...(pageToken ? { pageToken } : {}), ...(flags.folder ? { ancestorName: `items/${flags.folder}` } : {}) };
|
|
65
|
+
const res = await fetch("https://driveactivity.googleapis.com/v2/activity:query", { method: "POST", headers: { authorization: `Bearer ${token}`, "content-type": "application/json" }, body: JSON.stringify(body) });
|
|
66
|
+
if (!res.ok)
|
|
67
|
+
throw new Error(`Drive Activity ${res.status}: ${await res.text()}`);
|
|
68
|
+
const j = await res.json();
|
|
69
|
+
acts.push(...(j.activities ?? []));
|
|
70
|
+
pageToken = j.nextPageToken;
|
|
71
|
+
} while (pageToken && acts.length < max);
|
|
72
|
+
const actors = {};
|
|
73
|
+
const names = new Set();
|
|
74
|
+
for (const a of acts)
|
|
75
|
+
for (const x of a.actors ?? []) {
|
|
76
|
+
const pn = (x.user ?? x.impersonation?.impersonatedUser)?.knownUser?.personName;
|
|
77
|
+
if (pn)
|
|
78
|
+
names.add(pn);
|
|
79
|
+
}
|
|
80
|
+
for (const pn of names) {
|
|
81
|
+
try {
|
|
82
|
+
const res = await fetch(`https://people.googleapis.com/v1/${pn}?personFields=emailAddresses,names`, { headers: { authorization: `Bearer ${token}` } });
|
|
83
|
+
if (res.ok) {
|
|
84
|
+
const p = await res.json();
|
|
85
|
+
actors[pn] = { email: p.emailAddresses?.[0]?.value, name: p.names?.[0]?.displayName };
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
catch { }
|
|
89
|
+
}
|
|
90
|
+
const r = await logAll({ activities: acts, actors, source: "cli" }, project);
|
|
91
|
+
console.log(`backfill: ${acts.length} activities, ${r.mapped} mapped, ${r.logged} logged, ${r.deduped} deduped`);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
console.log("retrace-gdrive <backfill --token T [--folder id] [--since date] | replay <payload.json>> [--project name]");
|
|
95
|
+
}
|
|
96
|
+
if (isMainModule(import.meta.url))
|
|
97
|
+
main().catch((e) => { console.error("retrace-gdrive:", e.message ?? e); process.exit(1); });
|