@kyleroche/relay 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +24 -2
- package/dist/hooks/_lib.mjs +105 -0
- package/dist/hooks/session-end.mjs +17 -0
- package/dist/hooks/session-start.mjs +17 -0
- package/dist/hooks/user-prompt.mjs +18 -0
- package/dist/migrations/001_init.sql +153 -0
- package/dist/migrations/002_assets.sql +33 -0
- package/dist/migrations/003_tokens.sql +14 -0
- package/dist/migrations/004_tasks.sql +12 -0
- package/dist/migrations/005_webhooks.sql +28 -0
- package/dist/migrations/006_oauth.sql +85 -0
- package/dist/migrations/007_workers.sql +31 -0
- package/dist/relay-mcp.js +5159 -0
- package/dist/relay.js +8293 -0
- package/package.json +64 -3
- package/templates/relay-caller.yml +48 -0
- package/templates/relay-cloud.yml +168 -0
- package/templates/relay-review.yml +66 -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
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @kyleroche/relay
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `relay` command: your coding-agent subscriptions (Claude Code, Codex, Grok) working as one system. GitHub
|
|
4
|
+
issues are the task bus, runners on your own machines run the vendor CLIs under the machine's own login, a Postgres
|
|
5
|
+
database holds shared memory and an append-only event feed, and a small web app shows it all. Credentials never
|
|
6
|
+
leave the machine they were created on.
|
|
7
|
+
|
|
8
|
+
Needs Node 24 or newer. No checkout required:
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npx @kyleroche/relay doctor # what is installed, logged in, and reachable
|
|
12
|
+
npx @kyleroche/relay setup # hooks + memory MCP server into each CLI you have; prints the plan, --yes writes
|
|
13
|
+
cd ~/code/some-repo && npx @kyleroche/relay link
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`relay link` is the only per-repo step: it registers the repo, digests its files and writes the project summary
|
|
17
|
+
(Sonnet, a few cents), renders `relay.md` from that summary, and installs the owned sections, caller workflows and
|
|
18
|
+
labels. Re-running it is safe and makes no model calls unless files changed.
|
|
19
|
+
|
|
20
|
+
The package ships the CLI (`dist/relay.js`), the stdio memory server the CLIs talk to (`dist/relay-mcp.js`), the
|
|
21
|
+
dependency-free session hooks `relay setup` installs (`dist/hooks/`), the SQL migrations, and the caller workflow
|
|
22
|
+
templates. Locally it runs on an embedded Postgres (PGlite) under `~/.harness`; set `DATABASE_URL` for a server.
|
|
23
|
+
|
|
24
|
+
Source, architecture and the hosted web app: [github.com/kyleroche/relay](https://github.com/kyleroche/relay) and
|
|
25
|
+
[relay.kyro.house](https://relay.kyro.house). Apache-2.0.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
// Shared helpers for the relay hook scripts. Plain Node ESM with no dependencies, because a hook runs on every
|
|
2
|
+
// session start and prompt: it must answer fast and must never break the session. The heavy work (PGlite, the
|
|
3
|
+
// brief compiler) lives in the CLI, which these scripts spawn (dist/relay.js, or the repo's own tsx) only when the cache misses.
|
|
4
|
+
import { spawnSync, spawn } from "node:child_process";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import { existsSync, mkdirSync, openSync, readFileSync } from "node:fs";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { dirname, join, resolve } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
export const HOOKS_DIR = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
/** In the published package the hooks sit at dist/hooks beside the bundled CLI, dist/relay.js. */
|
|
14
|
+
export const BUNDLED_CLI = resolve(HOOKS_DIR, "..", "relay.js");
|
|
15
|
+
/** In a checkout they sit at packages/cli/hooks and the CLI is TypeScript, run through the repo's tsx. */
|
|
16
|
+
export const RELAY_ROOT = resolve(HOOKS_DIR, "..", "..", "..");
|
|
17
|
+
export const CLI_MAIN = join(RELAY_ROOT, "packages", "cli", "src", "main.ts");
|
|
18
|
+
export const RELAY_HOME = process.env.RELAY_HOME ?? join(homedir(), ".harness");
|
|
19
|
+
export const BRIEF_TTL_MS = 10 * 60_000;
|
|
20
|
+
|
|
21
|
+
/** `--cli <name>` from argv; the CLI the hook was installed for. */
|
|
22
|
+
export function cliName() {
|
|
23
|
+
const i = process.argv.indexOf("--cli");
|
|
24
|
+
return i >= 0 && process.argv[i + 1] ? process.argv[i + 1] : "claude";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Read the hook payload from stdin (JSON, or nothing). Never blocks for more than a moment. */
|
|
28
|
+
export function readPayload() {
|
|
29
|
+
try {
|
|
30
|
+
const raw = readFileSync(0, "utf8");
|
|
31
|
+
return raw.trim() ? JSON.parse(raw) : {};
|
|
32
|
+
} catch {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Nearest ancestor of `cwd` holding .relay/rules.json, and the slug it names. Null when the repo is not linked. */
|
|
38
|
+
export function linkedProject(cwd) {
|
|
39
|
+
let dir = resolve(cwd || process.cwd());
|
|
40
|
+
for (;;) {
|
|
41
|
+
const p = join(dir, ".relay", "rules.json");
|
|
42
|
+
if (existsSync(p)) {
|
|
43
|
+
try {
|
|
44
|
+
const j = JSON.parse(readFileSync(p, "utf8"));
|
|
45
|
+
return j && typeof j.project === "string" ? { root: dir, project: j.project } : null;
|
|
46
|
+
} catch {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
const up = dirname(dir);
|
|
51
|
+
if (up === dir) return null;
|
|
52
|
+
dir = up;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const sha256 = (s) => createHash("sha256").update(s).digest("hex");
|
|
57
|
+
const safe = (s) => s.replace(/[^A-Za-z0-9_.-]+/g, "_").slice(0, 60);
|
|
58
|
+
|
|
59
|
+
/** Same layout as packages/core/src/hooks/cache.ts: <RELAY_HOME>/cache/brief/<project>-<sha(key)[0:12]>.json */
|
|
60
|
+
export function briefCachePath(project, key) {
|
|
61
|
+
return join(RELAY_HOME, "cache", "brief", `${safe(project)}-${sha256(key).slice(0, 12)}.json`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Same key as packages/cli/src/commands/brief.ts briefCacheKey(). */
|
|
65
|
+
export const briefCacheKey = (intent, maxTokens, model = "", lane = "") => `${intent}|${maxTokens}|${model}|${lane}`;
|
|
66
|
+
|
|
67
|
+
export function readCachedBrief(project, key) {
|
|
68
|
+
const p = briefCachePath(project, key);
|
|
69
|
+
if (!existsSync(p)) return undefined;
|
|
70
|
+
try {
|
|
71
|
+
const j = JSON.parse(readFileSync(p, "utf8"));
|
|
72
|
+
return Date.now() - j.ts > BRIEF_TTL_MS ? undefined : j;
|
|
73
|
+
} catch {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The command line that runs the relay CLI with this node: dist/relay.js in the package; the repo's tsx and packages/cli/src/main.ts in a checkout. */
|
|
79
|
+
export function relayArgv(args) {
|
|
80
|
+
if (existsSync(BUNDLED_CLI)) return [process.execPath, [BUNDLED_CLI, ...args]];
|
|
81
|
+
const tsx = createRequire(import.meta.url).resolve("tsx/cli");
|
|
82
|
+
return [process.execPath, [tsx, CLI_MAIN, ...args]];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** Run the relay CLI synchronously; returns stdout ("" on any failure or timeout). */
|
|
86
|
+
export function runRelay(args, timeoutMs) {
|
|
87
|
+
const [bin, argv] = relayArgv(args);
|
|
88
|
+
const r = spawnSync(bin, argv, { encoding: "utf8", timeout: timeoutMs, env: { ...process.env, RELAY_HOOK: "1" }, maxBuffer: 4 * 1024 * 1024, stdio: ["ignore", "pipe", "pipe"] });
|
|
89
|
+
if (r.error || r.status !== 0) {
|
|
90
|
+
if (process.env.RELAY_HOOK_DEBUG) process.stderr.write(`[relay hook] ${r.error ? r.error.message : `exit ${r.status}`}: ${(r.stderr || "").slice(0, 500)}\n`);
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
return r.stdout || "";
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Start the relay CLI detached, output appended to <RELAY_HOME>/cache/<logName>; the hook returns at once. */
|
|
97
|
+
export function spawnRelayDetached(args, logName) {
|
|
98
|
+
const dir = join(RELAY_HOME, "cache");
|
|
99
|
+
mkdirSync(dir, { recursive: true });
|
|
100
|
+
const out = openSync(join(dir, logName), "a");
|
|
101
|
+
const [bin, argv] = relayArgv(args);
|
|
102
|
+
const child = spawn(bin, argv, { detached: true, stdio: ["ignore", out, out], env: { ...process.env, RELAY_HOOK: "1" } });
|
|
103
|
+
child.unref();
|
|
104
|
+
return child.pid;
|
|
105
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SessionEnd (Claude Code, Codex) / Stop (Grok Build) hook: run `relay capture` on the session transcript, detached,
|
|
3
|
+
// so the session never waits on the Sonnet call. Output goes to <RELAY_HOME>/cache/capture.log. Per-turn Stop
|
|
4
|
+
// hooks are cheap because capture keeps a byte offset per transcript and only reads the new turns.
|
|
5
|
+
// Payload (stdin JSON) fields used: transcript_path (or rollout_path / session_path), session_id, cwd.
|
|
6
|
+
import { existsSync } from "node:fs";
|
|
7
|
+
import { cliName, linkedProject, readPayload, spawnRelayDetached } from "./_lib.mjs";
|
|
8
|
+
|
|
9
|
+
const payload = readPayload();
|
|
10
|
+
const link = linkedProject(payload.cwd || process.cwd());
|
|
11
|
+
if (!link) process.exit(0);
|
|
12
|
+
const transcript = payload.transcript_path ?? payload.rollout_path ?? payload.session_path ?? payload.transcript;
|
|
13
|
+
if (typeof transcript !== "string" || !existsSync(transcript)) process.exit(0);
|
|
14
|
+
|
|
15
|
+
const args = ["capture", "--hook", "--transcript", transcript, "--project", link.project, "--cwd", link.root, "--source", cliName()];
|
|
16
|
+
if (payload.session_id) args.push("--session", String(payload.session_id));
|
|
17
|
+
spawnRelayDetached(args, "capture.log");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// SessionStart hook (Claude Code, Codex, Grok Build): print the project's brief so it lands in the session's
|
|
3
|
+
// context. Budget: 2.5K tokens. Cached per project for ten minutes, so most starts never spawn the CLI.
|
|
4
|
+
// Silent when the cwd is not a linked repo. Payload (stdin JSON) fields used: cwd.
|
|
5
|
+
import { briefCacheKey, cliName, linkedProject, readCachedBrief, readPayload, runRelay } from "./_lib.mjs";
|
|
6
|
+
|
|
7
|
+
const INTENT = "session start";
|
|
8
|
+
const MAX_TOKENS = 2500;
|
|
9
|
+
|
|
10
|
+
const payload = readPayload();
|
|
11
|
+
const link = linkedProject(payload.cwd || process.cwd());
|
|
12
|
+
if (!link) process.exit(0);
|
|
13
|
+
|
|
14
|
+
const lane = cliName();
|
|
15
|
+
const cached = readCachedBrief(link.project, briefCacheKey(INTENT, MAX_TOKENS, "", lane));
|
|
16
|
+
const text = cached ? cached.text : runRelay(["brief", "--hook", "--project", link.project, "--cwd", link.root, "--max-tokens", String(MAX_TOKENS), "--lane", lane, "--", INTENT], 15_000);
|
|
17
|
+
if (text.trim()) process.stdout.write(`# relay brief for ${link.project}\n\n${text.trimEnd()}\n`);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// UserPromptSubmit hook (Claude Code, Grok Build; Codex has no such hook): print the decisions and preferences
|
|
3
|
+
// that match the prompt so they are in context before the model answers. Budget: 1K tokens. Only runs in a linked
|
|
4
|
+
// repo, and only for prompts long enough to be about something (short acknowledgements and slash commands skip).
|
|
5
|
+
// Payload (stdin JSON) fields used: prompt, cwd.
|
|
6
|
+
import { cliName, linkedProject, readPayload, runRelay } from "./_lib.mjs";
|
|
7
|
+
|
|
8
|
+
const MAX_TOKENS = 1000;
|
|
9
|
+
const MIN_PROMPT_CHARS = 20;
|
|
10
|
+
|
|
11
|
+
const payload = readPayload();
|
|
12
|
+
const link = linkedProject(payload.cwd || process.cwd());
|
|
13
|
+
if (!link) process.exit(0);
|
|
14
|
+
const prompt = String(payload.prompt ?? payload.user_prompt ?? payload.input ?? "").trim();
|
|
15
|
+
if (prompt.length < MIN_PROMPT_CHARS || prompt.startsWith("/")) process.exit(0);
|
|
16
|
+
|
|
17
|
+
const text = runRelay(["recall", "--hook", "--project", link.project, "--cwd", link.root, "--max-tokens", String(MAX_TOKENS), "--lane", cliName(), "--", prompt.slice(0, 2000)], 10_000);
|
|
18
|
+
if (text.trim()) process.stdout.write(text);
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
-- relay memory + event log. Postgres 15+. Works on Neon (prod) and PGlite (local/tests).
|
|
2
|
+
-- Vector search needs the pgvector extension; full-text uses built-in tsvector.
|
|
3
|
+
CREATE EXTENSION IF NOT EXISTS vector;
|
|
4
|
+
|
|
5
|
+
CREATE TABLE IF NOT EXISTS meta (
|
|
6
|
+
key text PRIMARY KEY,
|
|
7
|
+
value jsonb NOT NULL,
|
|
8
|
+
updated_at timestamptz NOT NULL DEFAULT now()
|
|
9
|
+
);
|
|
10
|
+
|
|
11
|
+
-- A registered repository. slug is the GitHub repo name; repo is "owner/name".
|
|
12
|
+
CREATE TABLE IF NOT EXISTS projects (
|
|
13
|
+
slug text PRIMARY KEY,
|
|
14
|
+
repo text,
|
|
15
|
+
path text,
|
|
16
|
+
stack text,
|
|
17
|
+
check_cmd text,
|
|
18
|
+
summary text,
|
|
19
|
+
summary_tokens int,
|
|
20
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
21
|
+
updated_at timestamptz NOT NULL DEFAULT now()
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
-- Per-file digest keyed by content hash; re-summarized only when sha256 changes.
|
|
25
|
+
CREATE TABLE IF NOT EXISTS file_digests (
|
|
26
|
+
project text NOT NULL REFERENCES projects(slug) ON DELETE CASCADE,
|
|
27
|
+
path text NOT NULL,
|
|
28
|
+
sha256 text NOT NULL,
|
|
29
|
+
size int NOT NULL DEFAULT 0,
|
|
30
|
+
summary text,
|
|
31
|
+
summary_sha text,
|
|
32
|
+
tokens int NOT NULL DEFAULT 0,
|
|
33
|
+
seen_at timestamptz NOT NULL DEFAULT now(),
|
|
34
|
+
summarized_at timestamptz,
|
|
35
|
+
PRIMARY KEY (project, path)
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
-- Durable, cross-tool memory: decisions and preferences.
|
|
39
|
+
CREATE TABLE IF NOT EXISTS decisions (
|
|
40
|
+
id bigserial PRIMARY KEY,
|
|
41
|
+
project text REFERENCES projects(slug) ON DELETE CASCADE,
|
|
42
|
+
text text NOT NULL,
|
|
43
|
+
source text, -- 'claude' | 'codex' | 'grok' | 'pr' | 'human' | 'nightly'
|
|
44
|
+
source_ref text, -- session id, PR url, etc.
|
|
45
|
+
valid_from timestamptz NOT NULL DEFAULT now(),
|
|
46
|
+
valid_to timestamptz, -- null = current; set when superseded
|
|
47
|
+
superseded_by bigint REFERENCES decisions(id),
|
|
48
|
+
embedding vector(1536),
|
|
49
|
+
tsv tsvector GENERATED ALWAYS AS (to_tsvector('english', text)) STORED,
|
|
50
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
51
|
+
);
|
|
52
|
+
CREATE INDEX IF NOT EXISTS decisions_project_idx ON decisions(project) WHERE valid_to IS NULL;
|
|
53
|
+
CREATE INDEX IF NOT EXISTS decisions_tsv_idx ON decisions USING gin(tsv);
|
|
54
|
+
|
|
55
|
+
CREATE TABLE IF NOT EXISTS preferences (
|
|
56
|
+
key text NOT NULL,
|
|
57
|
+
scope text NOT NULL, -- 'global' | 'project' | 'lane' | 'model'
|
|
58
|
+
scope_id text NOT NULL DEFAULT '',
|
|
59
|
+
value text NOT NULL,
|
|
60
|
+
reason text,
|
|
61
|
+
updated_at timestamptz NOT NULL DEFAULT now(),
|
|
62
|
+
PRIMARY KEY (key, scope, scope_id)
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
-- Official vendor guidance per model (the onboarding gate).
|
|
66
|
+
CREATE TABLE IF NOT EXISTS providers (
|
|
67
|
+
slug text PRIMARY KEY,
|
|
68
|
+
name text NOT NULL,
|
|
69
|
+
doc_domains text[] NOT NULL DEFAULT '{}',
|
|
70
|
+
skill_sources text[] NOT NULL DEFAULT '{}',
|
|
71
|
+
updated_at timestamptz NOT NULL DEFAULT now()
|
|
72
|
+
);
|
|
73
|
+
CREATE TABLE IF NOT EXISTS models (
|
|
74
|
+
id text PRIMARY KEY, -- e.g. bytedance/seedance-2.5
|
|
75
|
+
provider text NOT NULL REFERENCES providers(slug),
|
|
76
|
+
lanes text[] NOT NULL DEFAULT '{}',
|
|
77
|
+
onboarded_at timestamptz,
|
|
78
|
+
guidance_count int NOT NULL DEFAULT 0,
|
|
79
|
+
skill_count int NOT NULL DEFAULT 0,
|
|
80
|
+
stale_days int NOT NULL DEFAULT 30,
|
|
81
|
+
updated_at timestamptz NOT NULL DEFAULT now()
|
|
82
|
+
);
|
|
83
|
+
CREATE TABLE IF NOT EXISTS sources (
|
|
84
|
+
url text PRIMARY KEY,
|
|
85
|
+
provider text NOT NULL,
|
|
86
|
+
title text,
|
|
87
|
+
sha256 text,
|
|
88
|
+
etag text,
|
|
89
|
+
official boolean NOT NULL DEFAULT true,
|
|
90
|
+
fetched_at timestamptz,
|
|
91
|
+
checked_at timestamptz,
|
|
92
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
93
|
+
);
|
|
94
|
+
CREATE TABLE IF NOT EXISTS guidance (
|
|
95
|
+
id text NOT NULL, -- sha256(source_url#index:head); the same source may guide several models
|
|
96
|
+
model text NOT NULL REFERENCES models(id) ON DELETE CASCADE,
|
|
97
|
+
provider text NOT NULL,
|
|
98
|
+
source_url text NOT NULL REFERENCES sources(url) ON DELETE CASCADE,
|
|
99
|
+
chunk_index int NOT NULL,
|
|
100
|
+
kind text NOT NULL, -- prompting | limits | api | moderation | style | skill
|
|
101
|
+
title text NOT NULL,
|
|
102
|
+
text text NOT NULL,
|
|
103
|
+
tokens int NOT NULL,
|
|
104
|
+
embedding vector(1536),
|
|
105
|
+
tsv tsvector GENERATED ALWAYS AS (to_tsvector('english', coalesce(title,'') || ' ' || text)) STORED,
|
|
106
|
+
fetched_at timestamptz NOT NULL DEFAULT now(),
|
|
107
|
+
PRIMARY KEY (model, id)
|
|
108
|
+
);
|
|
109
|
+
CREATE INDEX IF NOT EXISTS guidance_model_idx ON guidance(model);
|
|
110
|
+
CREATE INDEX IF NOT EXISTS guidance_tsv_idx ON guidance USING gin(tsv);
|
|
111
|
+
CREATE TABLE IF NOT EXISTS skills (
|
|
112
|
+
name text NOT NULL,
|
|
113
|
+
model text NOT NULL REFERENCES models(id) ON DELETE CASCADE,
|
|
114
|
+
provider text NOT NULL,
|
|
115
|
+
install_path text NOT NULL,
|
|
116
|
+
version text NOT NULL,
|
|
117
|
+
sha256 text NOT NULL,
|
|
118
|
+
source_url text NOT NULL,
|
|
119
|
+
installed_at timestamptz NOT NULL DEFAULT now(),
|
|
120
|
+
PRIMARY KEY (name, model)
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
-- The event feed: one append-only log of everything agents and humans did. The ledger is a view over it.
|
|
124
|
+
CREATE TABLE IF NOT EXISTS events (
|
|
125
|
+
id bigserial PRIMARY KEY,
|
|
126
|
+
ts timestamptz NOT NULL DEFAULT now(),
|
|
127
|
+
kind text NOT NULL, -- issue.opened | run.started | run.finished | step.usage | pr.opened | pr.merged | preview.ready | decision.captured | memory.consolidated | onboard.refreshed | ...
|
|
128
|
+
actor text NOT NULL, -- 'human:kyle' | 'bot:grok' | 'runner:mini' | 'agent:claude' | ...
|
|
129
|
+
project text,
|
|
130
|
+
repo text,
|
|
131
|
+
issue int,
|
|
132
|
+
pr int,
|
|
133
|
+
lane text,
|
|
134
|
+
model text,
|
|
135
|
+
subscription text, -- max | codex | grok | gateway | cursor | local
|
|
136
|
+
tokens_in bigint NOT NULL DEFAULT 0,
|
|
137
|
+
tokens_out bigint NOT NULL DEFAULT 0,
|
|
138
|
+
cache_read bigint NOT NULL DEFAULT 0,
|
|
139
|
+
cache_write bigint NOT NULL DEFAULT 0,
|
|
140
|
+
cost_equiv numeric(12,6) NOT NULL DEFAULT 0,
|
|
141
|
+
duration_ms int,
|
|
142
|
+
summary text NOT NULL,
|
|
143
|
+
url text,
|
|
144
|
+
payload jsonb NOT NULL DEFAULT '{}'::jsonb,
|
|
145
|
+
dedupe_key text UNIQUE -- e.g. github delivery id, so webhooks are idempotent
|
|
146
|
+
);
|
|
147
|
+
CREATE INDEX IF NOT EXISTS events_ts_idx ON events(ts DESC);
|
|
148
|
+
CREATE INDEX IF NOT EXISTS events_project_ts_idx ON events(project, ts DESC);
|
|
149
|
+
CREATE INDEX IF NOT EXISTS events_kind_ts_idx ON events(kind, ts DESC);
|
|
150
|
+
|
|
151
|
+
CREATE OR REPLACE VIEW ledger AS
|
|
152
|
+
SELECT ts, actor, project, lane, model, subscription, tokens_in, tokens_out, cache_read, cache_write, cost_equiv, duration_ms, url
|
|
153
|
+
FROM events WHERE kind = 'step.usage';
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
-- Asset library: media too large to share inline, versioned, with an approve-or-reject review loop (docs/ASSETS.md).
|
|
2
|
+
-- Access control is the app's job (API scopes); the table carries no per-row grants.
|
|
3
|
+
CREATE TABLE IF NOT EXISTS assets (
|
|
4
|
+
id text PRIMARY KEY, -- ulid
|
|
5
|
+
project text REFERENCES projects(slug) ON DELETE SET NULL,
|
|
6
|
+
issue int,
|
|
7
|
+
pr int,
|
|
8
|
+
title text NOT NULL,
|
|
9
|
+
description text,
|
|
10
|
+
kind text NOT NULL, -- image | video | audio | pdf | html | file
|
|
11
|
+
mime text NOT NULL,
|
|
12
|
+
size bigint NOT NULL,
|
|
13
|
+
sha256 text NOT NULL,
|
|
14
|
+
storage_key text NOT NULL, -- blob pathname or local relative path
|
|
15
|
+
thumb_key text,
|
|
16
|
+
width int,
|
|
17
|
+
height int,
|
|
18
|
+
duration_ms int,
|
|
19
|
+
version int NOT NULL DEFAULT 1,
|
|
20
|
+
parent_id text REFERENCES assets(id) ON DELETE SET NULL, -- previous version; survives the parent's expiry
|
|
21
|
+
status text NOT NULL DEFAULT 'pending', -- pending | approved | rejected | superseded | published
|
|
22
|
+
created_by text NOT NULL, -- actor, e.g. bot:grok, runner:mini, human:kyle
|
|
23
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
24
|
+
reviewed_by text,
|
|
25
|
+
reviewed_at timestamptz,
|
|
26
|
+
review_note text,
|
|
27
|
+
public_url text, -- set only after an explicit publish
|
|
28
|
+
expires_at timestamptz, -- set when rejected or superseded; null = keep
|
|
29
|
+
tags text[] NOT NULL DEFAULT '{}'
|
|
30
|
+
);
|
|
31
|
+
CREATE INDEX IF NOT EXISTS assets_project_status_idx ON assets(project, status, created_at DESC);
|
|
32
|
+
CREATE INDEX IF NOT EXISTS assets_expires_idx ON assets(expires_at) WHERE expires_at IS NOT NULL;
|
|
33
|
+
CREATE INDEX IF NOT EXISTS assets_parent_idx ON assets(parent_id);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
-- API bearer tokens for the web app and the HTTP MCP server. Only the SHA-256 of a token is stored; the plaintext is
|
|
2
|
+
-- shown once by `relay token create`. Scopes are the names the OpenAPI description publishes (feed:read, memory:read,
|
|
3
|
+
-- memory:write, assets:read, assets:write, assets:review).
|
|
4
|
+
CREATE TABLE IF NOT EXISTS tokens (
|
|
5
|
+
id text PRIMARY KEY, -- ulid
|
|
6
|
+
name text NOT NULL,
|
|
7
|
+
token_hash text NOT NULL UNIQUE, -- sha256 hex of the plaintext token
|
|
8
|
+
scopes text[] NOT NULL DEFAULT '{}',
|
|
9
|
+
created_by text NOT NULL, -- actor, e.g. human:kyle
|
|
10
|
+
created_at timestamptz NOT NULL DEFAULT now(),
|
|
11
|
+
last_used_at timestamptz,
|
|
12
|
+
revoked_at timestamptz
|
|
13
|
+
);
|
|
14
|
+
CREATE INDEX IF NOT EXISTS tokens_hash_live_idx ON tokens(token_hash) WHERE revoked_at IS NULL;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-- Tasks: a thin record over a GitHub issue so bots can address work by one id ("<owner>/<repo>#<n>") and create it
|
|
2
|
+
-- idempotently. State is never stored here; it is derived from the feed (packages/core/src/db/tasks.ts taskState).
|
|
3
|
+
CREATE TABLE IF NOT EXISTS tasks (
|
|
4
|
+
id text PRIMARY KEY, -- "<owner>/<repo>#<n>"
|
|
5
|
+
project text NOT NULL REFERENCES projects(slug) ON DELETE CASCADE,
|
|
6
|
+
repo text NOT NULL, -- "owner/name"
|
|
7
|
+
issue int NOT NULL,
|
|
8
|
+
idempotency_key text UNIQUE, -- caller-supplied; a repeat create returns the same task
|
|
9
|
+
created_by text NOT NULL, -- actor, e.g. bot:grok or human:kyle
|
|
10
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
11
|
+
);
|
|
12
|
+
CREATE INDEX IF NOT EXISTS tasks_project_created_idx ON tasks(project, created_at DESC);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
-- Outbound webhooks (docs/FEED.md "Outbound webhooks"): after an event is written, matching hooks receive a signed
|
|
2
|
+
-- POST. The secret and bearer are stored as given because the dispatcher needs them to sign and authenticate; the
|
|
3
|
+
-- API never returns them after creation. One delivery row per (webhook, event) records the attempts.
|
|
4
|
+
CREATE TABLE IF NOT EXISTS webhooks (
|
|
5
|
+
id text PRIMARY KEY, -- ulid
|
|
6
|
+
project text REFERENCES projects(slug) ON DELETE CASCADE, -- null = every project
|
|
7
|
+
url text NOT NULL,
|
|
8
|
+
secret text NOT NULL, -- HMAC key for X-Relay-Signature
|
|
9
|
+
bearer text, -- sent as Authorization: Bearer when set
|
|
10
|
+
events text[] NOT NULL DEFAULT '{}', -- kinds, prefixes ending in '.', or '*'
|
|
11
|
+
active boolean NOT NULL DEFAULT true,
|
|
12
|
+
created_by text NOT NULL DEFAULT '',
|
|
13
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
14
|
+
);
|
|
15
|
+
CREATE INDEX IF NOT EXISTS webhooks_active_idx ON webhooks(active) WHERE active;
|
|
16
|
+
|
|
17
|
+
CREATE TABLE IF NOT EXISTS webhook_deliveries (
|
|
18
|
+
id text PRIMARY KEY, -- ulid; also the X-Relay-Delivery header
|
|
19
|
+
webhook_id text NOT NULL REFERENCES webhooks(id) ON DELETE CASCADE,
|
|
20
|
+
event_id bigint, -- events.id; null for test.ping
|
|
21
|
+
kind text NOT NULL DEFAULT '',
|
|
22
|
+
status text NOT NULL DEFAULT 'pending', -- pending | delivered | failed
|
|
23
|
+
attempts int NOT NULL DEFAULT 0,
|
|
24
|
+
last_error text,
|
|
25
|
+
delivered_at timestamptz,
|
|
26
|
+
created_at timestamptz NOT NULL DEFAULT now()
|
|
27
|
+
);
|
|
28
|
+
CREATE INDEX IF NOT EXISTS webhook_deliveries_hook_idx ON webhook_deliveries(webhook_id, created_at DESC);
|