@phren/cli 0.3.49 → 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.
- package/dist/bridge/computers.js +5 -4
- package/dist/bridge/conductor-role.d.ts +4 -0
- package/dist/bridge/conductor-role.js +20 -1
- package/dist/bridge/dispatch-origins.d.ts +32 -0
- package/dist/bridge/dispatch-origins.js +44 -0
- package/dist/bridge/dispatch-returns.d.ts +2 -1
- package/dist/bridge/dispatch-returns.js +9 -2
- package/dist/bridge/dispatch.d.ts +5 -0
- package/dist/bridge/dispatch.js +119 -23
- package/dist/bridge/hand-off.d.ts +1 -0
- package/dist/bridge/hand-off.js +1 -1
- package/dist/bridge/install.d.ts +1 -0
- package/dist/bridge/install.js +7 -0
- package/dist/bridge/project-memory.d.ts +2 -0
- package/dist/bridge/project-memory.js +27 -13
- package/dist/bridge/request-origin.d.ts +6 -0
- package/dist/bridge/request-origin.js +6 -0
- package/dist/bridge/scoped-gateway.d.ts +3 -0
- package/dist/bridge/scoped-gateway.js +22 -4
- package/dist/bridge/server-routes.d.ts +1 -0
- package/dist/bridge/server-routes.js +10 -2
- package/dist/bridge/session-move.d.ts +10 -2
- package/dist/bridge/session-move.js +124 -12
- package/dist/bridge-hook.mjs +2280 -1720
- package/dist/cli/hooks-output.js +21 -3
- package/dist/content/citation-freshness.d.ts +29 -0
- package/dist/content/citation-freshness.js +311 -0
- package/dist/modules/registry.js +1 -1
- package/dist/shared/retrieval.d.ts +2 -1
- package/dist/shared/retrieval.js +40 -8
- package/dist/sync/gitboy-webhook.d.ts +43 -0
- package/dist/sync/gitboy-webhook.js +119 -0
- package/dist/tools/dispatch.js +1 -1
- package/dist/tools/search.js +34 -4
- package/package.json +1 -1
|
@@ -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
|
+
}
|
package/dist/tools/dispatch.js
CHANGED
|
@@ -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/dist/tools/search.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { cachedCitationFreshness, refreshCitationFreshness, citationFreshnessAnnotation } from "../content/citation-freshness.js";
|
|
2
|
+
import { getProjectRemote, readProjectConfig } from "../project-config.js";
|
|
1
3
|
import { nonInteractiveGitEnv } from "../utils-helpers.js";
|
|
2
4
|
import { projectMemoryCounts } from "../content/summarize.js";
|
|
3
5
|
import { moduleEnabled } from "../modules/runtime.js";
|
|
@@ -17,8 +19,8 @@ import { runCustomHooks } from "../hooks.js";
|
|
|
17
19
|
import { entryScoreKey, getQualityMultiplier, getRetentionPolicy, recordLookupEvents } from "../shared/governance.js";
|
|
18
20
|
import { bestFindingNodeId } from "../finding-graph-id.js";
|
|
19
21
|
import { callLlm } from "../content/dedup.js";
|
|
20
|
-
import { rankResults, searchKnowledgeRows, applyTrustFilter, searchFederatedStores } from "../shared/retrieval.js";
|
|
21
|
-
import { formatActorAttribution, parseScopeComment, parseSourceComment, collectSymbolCitations } from "../content/citation.js";
|
|
22
|
+
import { markStaleCitations, rankResults, searchKnowledgeRows, applyTrustFilter, searchFederatedStores } from "../shared/retrieval.js";
|
|
23
|
+
import { parseCitationComment, formatActorAttribution, parseScopeComment, parseSourceComment, collectSymbolCitations } from "../content/citation.js";
|
|
22
24
|
import { resolveActiveSessionScope } from "./session.js";
|
|
23
25
|
import { logger } from "../logger.js";
|
|
24
26
|
import { CLANKER_FETCH_HINT, clankerEnabled, findEntry, formatRow, queryTerms, rowKeywords, rowTitle, rowsForDoc } from "../clanker.js";
|
|
@@ -421,11 +423,31 @@ async function handleSearchKnowledge(ctx, { query, limit, project, type, tag, si
|
|
|
421
423
|
if (rows.length > maxResults) {
|
|
422
424
|
rows = rows.slice(0, maxResults);
|
|
423
425
|
}
|
|
426
|
+
const citationOptionsByProject = new Map();
|
|
427
|
+
const citationOptions = (row) => {
|
|
428
|
+
// Indexed paths also identify findings from registered secondary stores.
|
|
429
|
+
const root = row.path ? path.dirname(path.dirname(row.path)) : phrenPath;
|
|
430
|
+
const key = JSON.stringify([root, row.project]);
|
|
431
|
+
let opts = citationOptionsByProject.get(key);
|
|
432
|
+
if (!opts) {
|
|
433
|
+
opts = { phrenPath, projectRemote: getProjectRemote(root, row.project, readProjectConfig(root, row.project)) };
|
|
434
|
+
citationOptionsByProject.set(key, opts);
|
|
435
|
+
}
|
|
436
|
+
return opts;
|
|
437
|
+
};
|
|
438
|
+
const citationsByRow = rows.map(row => row.type === "findings" ? row.content.split("\n")
|
|
439
|
+
.map(parseCitationComment).filter(cite => cite !== null)
|
|
440
|
+
.map(cite => ({ ...cite, projectRemote: citationOptions(row).projectRemote })) : []);
|
|
441
|
+
await refreshCitationFreshness(citationsByRow.flat(), { phrenPath, budgetMs: 1500 });
|
|
424
442
|
// Snippets share one character budget so a response stays well under the
|
|
425
443
|
// client's tool-result limit however long the matched lines are.
|
|
426
444
|
const perResultChars = snippetBudget(rows.length);
|
|
427
445
|
const results = rows.map((row) => {
|
|
428
|
-
const
|
|
446
|
+
const excerpt = extractSnippet(row.content, query, 5, perResultChars);
|
|
447
|
+
const snippet = row.type === "findings" ? markStaleCitations(excerpt, citationOptions(row)) : excerpt;
|
|
448
|
+
const citations = row.type === "findings" ? snippet.split("\n").map(parseCitationComment)
|
|
449
|
+
.filter(citation => citation !== null).slice(0, 20).map(citation => ({ file: citation.file, commit: citation.commit,
|
|
450
|
+
citationFreshness: cachedCitationFreshness(citation, citationOptions(row)) })) : [];
|
|
429
451
|
const lifecycle = row.type === "findings" ? lifecycleByRowKey.get(findingRowKey(row)) : undefined;
|
|
430
452
|
const federationSource = "federationSource" in row ? row.federationSource : undefined;
|
|
431
453
|
const symbols = row.type === "findings" ? collectSymbolCitations(row.content) : [];
|
|
@@ -436,6 +458,7 @@ async function handleSearchKnowledge(ctx, { query, limit, project, type, tag, si
|
|
|
436
458
|
filename: row.filename,
|
|
437
459
|
type: row.type,
|
|
438
460
|
snippet,
|
|
461
|
+
...(citations.length ? { citations } : {}),
|
|
439
462
|
truncated: snippet.length < row.content.length,
|
|
440
463
|
path: row.path,
|
|
441
464
|
status: lifecycle?.primaryStatus,
|
|
@@ -500,7 +523,14 @@ async function handleSearchKnowledge(ctx, { query, limit, project, type, tag, si
|
|
|
500
523
|
const federationSource = "federationSource" in row ? row.federationSource : undefined;
|
|
501
524
|
const docId = federationSource ? `${federationSource}:${row.project}/${row.filename}` : `mem:${getDocSourceKey(row, phrenPath)}`;
|
|
502
525
|
const bestLine = extractSnippet(row.content, query, 1, 400);
|
|
503
|
-
|
|
526
|
+
const selected = rowsForDoc(row, docId, terms, bestLine, Math.min(3, rowCap - clankerRows.length));
|
|
527
|
+
for (const hit of selected) {
|
|
528
|
+
const entry = findEntry(row.content, hit.id);
|
|
529
|
+
const citation = entry?.text.split("\n").map(parseCitationComment).find(cite => cite !== null);
|
|
530
|
+
if (citation)
|
|
531
|
+
hit.title += citationFreshnessAnnotation(citation, cachedCitationFreshness(citation, citationOptions(row)));
|
|
532
|
+
}
|
|
533
|
+
clankerRows.push(...selected);
|
|
504
534
|
}
|
|
505
535
|
runCustomHooks(phrenPath, "post-search", { PHREN_QUERY: query, PHREN_RESULT_COUNT: String(clankerRows.length) });
|
|
506
536
|
return mcpResponse({
|