@phren/cli 0.3.50 → 0.3.51

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.
@@ -98,7 +98,7 @@ export const BUILTIN_MODULES = [
98
98
  capabilities: [
99
99
  "hook", "transcript", "progress", "images", "prompt", "stop", "terminal", "shell", "paneTerminal", "paneLayout", "deskPresence", "herdr",
100
100
  "webServers", "webPreview", "activity", "approvals", "questions", "accountUsage", "providers",
101
- "files", "repositoryFiles", "fileResolution", "subagents", "sideQuestions", "approvalPush", "simulators", "overviewStream", "speech", "speechTimestamps", "speechTimestampStream", "speechLive", "speechVoices", "speechFormats", "transcribe", "promptOnce", "promptStatus", "deliveryFrames", "resources", "sessionRename", "sudo", "sudoOutcome", "previewDeltas", "quickChat", "agentFolder", "launchPermissionMode", "sessionMove", "moveNewChat",
101
+ "files", "repositoryFiles", "fileResolution", "subagents", "sideQuestions", "approvalPush", "simulators", "overviewStream", "speech", "speechTimestamps", "speechTimestampStream", "speechLive", "speechVoices", "speechFormats", "transcribe", "promptOnce", "promptStatus", "deliveryFrames", "resources", "sessionRename", "sudo", "sudoOutcome", "previewDeltas", "quickChat", "agentFolder", "launchPermissionMode", "sessionMove", "moveNewChat", "moveConductor",
102
102
  ],
103
103
  storeFiles: [".runtime/sessions/opencode-*.events.jsonl", ".runtime/approvals/opencode-*.json"],
104
104
  localFiles: ["<bridge>/installed.json", "<bridge>/versions/**", "<bridge>/current", "<bridge>/dispatch", "<bridge>/askpass", "<bridge>/computer-id", "<bridge>/canary.json", "<bridge>/canary-daily", "<bridge>/moves/*.json"],
@@ -0,0 +1,43 @@
1
+ export interface GitboyPushUpdate {
2
+ ref: string;
3
+ old: string;
4
+ new: string;
5
+ /** Files changed between old and new; null when gitboy could not say (new branch, deletion, tag, over budget). */
6
+ changedPaths: string[] | null;
7
+ truncated: boolean;
8
+ }
9
+ export interface GitboyPush {
10
+ deliveryId: string;
11
+ event: "push";
12
+ repository: {
13
+ owner: string;
14
+ name: string;
15
+ } | null;
16
+ updates: GitboyPushUpdate[];
17
+ }
18
+ export interface GitboyStoreRepo {
19
+ owner: string;
20
+ name: string;
21
+ branch: string;
22
+ }
23
+ /** True when `header` is `sha256=<hex HMAC-SHA256 of rawBody>` under `secret`. */
24
+ export declare function verifyGitboySignature(secret: string, rawBody: Buffer, header: string | undefined): boolean;
25
+ type Headers = Record<string, string | string[] | undefined>;
26
+ /** A gitboy `push` delivery, or null for any other event, a missing delivery id or a malformed body. Never throws. */
27
+ export declare function parseGitboyPush(rawBody: Buffer, headers: Headers): GitboyPush | null;
28
+ /**
29
+ * True when the push is to the store's repository (owner and name compared case-insensitively,
30
+ * as gitboy resolves them) and moves `refs/heads/<branch>` exactly.
31
+ */
32
+ export declare function storePushMatches(push: GitboyPush, store: GitboyStoreRepo): boolean;
33
+ export declare const DEFAULT_DELIVERY_LOG_SIZE = 1000;
34
+ /** Recently seen delivery ids, oldest evicted first. gitboy retries keep the delivery id. */
35
+ export declare class DeliveryLog {
36
+ private readonly capacity;
37
+ private readonly ids;
38
+ constructor(capacity?: number);
39
+ /** Records `id` and reports whether it had already been seen. */
40
+ seen(id: string): boolean;
41
+ get size(): number;
42
+ }
43
+ export {};
@@ -0,0 +1,119 @@
1
+ /**
2
+ * Transport-agnostic core for gitboy push webhooks: signature checks, push payload parsing,
3
+ * matching a push to a store's branch, and delivery de-duplication. Prepared for webhook-driven
4
+ * store sync; nothing in production calls it yet, and periodic polling (pull.ts) stays the fallback.
5
+ */
6
+ import { createHmac, timingSafeEqual } from "crypto";
7
+ const SIGNATURE_PREFIX = "sha256=";
8
+ const SHA256_HEX = /^[0-9a-f]{64}$/i;
9
+ /** True when `header` is `sha256=<hex HMAC-SHA256 of rawBody>` under `secret`. */
10
+ export function verifyGitboySignature(secret, rawBody, header) {
11
+ if (!secret || typeof header !== "string" || !header.startsWith(SIGNATURE_PREFIX))
12
+ return false;
13
+ const hex = header.slice(SIGNATURE_PREFIX.length);
14
+ if (!SHA256_HEX.test(hex))
15
+ return false;
16
+ const expected = createHmac("sha256", secret).update(rawBody).digest();
17
+ const given = Buffer.from(hex, "hex");
18
+ return given.length === expected.length && timingSafeEqual(given, expected);
19
+ }
20
+ function header(headers, name) {
21
+ const wanted = name.toLowerCase();
22
+ for (const [key, value] of Object.entries(headers)) {
23
+ if (key.toLowerCase() !== wanted)
24
+ continue;
25
+ const first = Array.isArray(value) ? value[0] : value;
26
+ return typeof first === "string" ? first : undefined;
27
+ }
28
+ return undefined;
29
+ }
30
+ function isRecord(value) {
31
+ return typeof value === "object" && value !== null && !Array.isArray(value);
32
+ }
33
+ /** gitboy's push payload names the repository `full_name: "owner/name"` beside `name`. */
34
+ function parseRepository(value) {
35
+ if (!isRecord(value) || typeof value.full_name !== "string")
36
+ return null;
37
+ const slash = value.full_name.indexOf("/");
38
+ if (slash <= 0)
39
+ return null;
40
+ const owner = value.full_name.slice(0, slash);
41
+ const name = value.full_name.slice(slash + 1);
42
+ if (!name || name.includes("/"))
43
+ return null;
44
+ return { owner, name };
45
+ }
46
+ function parseUpdate(value) {
47
+ if (!isRecord(value))
48
+ return null;
49
+ const { ref, old, new: next } = value;
50
+ if (typeof ref !== "string" || typeof old !== "string" || typeof next !== "string")
51
+ return null;
52
+ const paths = value.changed_paths;
53
+ const changedPaths = Array.isArray(paths) && paths.every((p) => typeof p === "string") ? paths : null;
54
+ return { ref, old, new: next, changedPaths, truncated: value.changed_paths_truncated === true };
55
+ }
56
+ /** A gitboy `push` delivery, or null for any other event, a missing delivery id or a malformed body. Never throws. */
57
+ export function parseGitboyPush(rawBody, headers) {
58
+ if (header(headers, "x-gitboy-event") !== "push")
59
+ return null;
60
+ const deliveryId = header(headers, "x-gitboy-delivery");
61
+ if (!deliveryId)
62
+ return null;
63
+ let payload;
64
+ try {
65
+ payload = JSON.parse(rawBody.toString("utf8"));
66
+ }
67
+ catch {
68
+ return null;
69
+ }
70
+ if (!isRecord(payload) || !Array.isArray(payload.updates))
71
+ return null;
72
+ const updates = [];
73
+ for (const entry of payload.updates) {
74
+ const update = parseUpdate(entry);
75
+ if (update)
76
+ updates.push(update);
77
+ }
78
+ return { deliveryId, event: "push", repository: parseRepository(payload.repository), updates };
79
+ }
80
+ /**
81
+ * True when the push is to the store's repository (owner and name compared case-insensitively,
82
+ * as gitboy resolves them) and moves `refs/heads/<branch>` exactly.
83
+ */
84
+ export function storePushMatches(push, store) {
85
+ const repo = push.repository;
86
+ if (!repo || !store.branch)
87
+ return false;
88
+ if (repo.owner.toLowerCase() !== store.owner.toLowerCase())
89
+ return false;
90
+ if (repo.name.toLowerCase() !== store.name.toLowerCase())
91
+ return false;
92
+ const ref = `refs/heads/${store.branch}`;
93
+ return push.updates.some((update) => update.ref === ref);
94
+ }
95
+ export const DEFAULT_DELIVERY_LOG_SIZE = 1_000;
96
+ /** Recently seen delivery ids, oldest evicted first. gitboy retries keep the delivery id. */
97
+ export class DeliveryLog {
98
+ capacity;
99
+ ids = new Set();
100
+ constructor(capacity = DEFAULT_DELIVERY_LOG_SIZE) {
101
+ this.capacity = capacity;
102
+ }
103
+ /** Records `id` and reports whether it had already been seen. */
104
+ seen(id) {
105
+ if (this.ids.has(id))
106
+ return true;
107
+ this.ids.add(id);
108
+ while (this.ids.size > this.capacity) {
109
+ const oldest = this.ids.values().next().value;
110
+ if (oldest === undefined)
111
+ break;
112
+ this.ids.delete(oldest);
113
+ }
114
+ return false;
115
+ }
116
+ get size() {
117
+ return this.ids.size;
118
+ }
119
+ }
@@ -141,7 +141,7 @@ export function register(server) {
141
141
  inputSchema: moveSessionSchema,
142
142
  }, async (input) => {
143
143
  try {
144
- const result = await moveSession(input);
144
+ const result = await moveSession(input, { agent: true });
145
145
  const move = result.move;
146
146
  const message = move.state === "moved" ? `Moved to ${String(object(move.to).harness)} (${String(move.placement)}); hand-off at ${String(object(move.handoff).path)}.`
147
147
  : move.state === "failed" ? `Move failed: ${String(move.error ?? "unknown error")}` : `Move ${String(move.id)} is ${String(move.state)}; check again with status:true.`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phren/cli",
3
- "version": "0.3.50",
3
+ "version": "0.3.51",
4
4
  "description": "Knowledge layer for AI agents - CLI, MCP server, and data layer",
5
5
  "type": "module",
6
6
  "bin": {