@phren/cli 0.3.48 → 0.3.50
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/git-host-gitboy.js +2 -2
- package/dist/bridge/git-host-gitlab.js +2 -2
- package/dist/bridge/git-host-http.d.ts +9 -0
- package/dist/bridge/git-host-http.js +11 -0
- package/dist/bridge/git-hosts.d.ts +3 -1
- package/dist/bridge/git-publish.js +12 -5
- package/dist/bridge/git.d.ts +2 -0
- package/dist/bridge/git.js +8 -2
- package/dist/bridge/project-git.d.ts +4 -3
- package/dist/bridge/project-git.js +17 -4
- package/dist/bridge/project-memory.d.ts +2 -0
- package/dist/bridge/project-memory.js +27 -13
- package/dist/bridge/protocol.js +1 -1
- package/dist/bridge/server-routes.d.ts +1 -0
- package/dist/bridge/server-routes.js +7 -4
- package/dist/bridge-hook.mjs +2050 -1742
- 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/tools/search.js +34 -4
- package/package.json +1 -1
|
@@ -286,10 +286,10 @@ export const gitboy = {
|
|
|
286
286
|
return { ok: false, reason: result.reason ?? "failed", message: result.message ?? "gitboy refused the merge." };
|
|
287
287
|
}
|
|
288
288
|
},
|
|
289
|
-
async whoami(root, host, token) {
|
|
289
|
+
async whoami(root, host, token, checkedApi) {
|
|
290
290
|
if (!host.domain)
|
|
291
291
|
throw new HostApiError("failed", "This repository has no gitboy remote.");
|
|
292
|
-
const api = await apiRoot(root, host.domain, `https://${host.domain}/api/v1`);
|
|
292
|
+
const api = checkedApi ?? await apiRoot(root, host.domain, `https://${host.domain}/api/v1`);
|
|
293
293
|
const { json } = await hostJson(`${api}/user`, { token, scheme: "bearer" });
|
|
294
294
|
return { user: String(obj(json).username ?? "") };
|
|
295
295
|
},
|
|
@@ -219,10 +219,10 @@ export const gitlab = {
|
|
|
219
219
|
return { ok: false, reason: result.reason ?? "failed", message: result.message ?? "GitLab refused the merge." };
|
|
220
220
|
}
|
|
221
221
|
},
|
|
222
|
-
async whoami(root, host, token) {
|
|
222
|
+
async whoami(root, host, token, checkedApi) {
|
|
223
223
|
if (!host.domain)
|
|
224
224
|
throw new HostApiError("failed", "This repository has no GitLab remote.");
|
|
225
|
-
const base = await apiRoot(root, host.domain, `https://${host.domain}/api/v4`);
|
|
225
|
+
const base = checkedApi ?? await apiRoot(root, host.domain, `https://${host.domain}/api/v4`);
|
|
226
226
|
const { json } = await hostJson(`${base}/user`, { token, scheme: "private-token" });
|
|
227
227
|
return { user: String(obj(json).username ?? "") };
|
|
228
228
|
},
|
|
@@ -16,6 +16,15 @@ export declare class HostApiError extends Error {
|
|
|
16
16
|
* writable by whatever runs in the checkout, and must never be able to send
|
|
17
17
|
* a stored token to another server. */
|
|
18
18
|
export declare function apiRoot(root: string, domain: string, fallback: string): Promise<string>;
|
|
19
|
+
/** Resolve the exact endpoint once, so Connect can check and use the same URL.
|
|
20
|
+
* Only the hostname/port is exposed to clients, never API URL credentials. */
|
|
21
|
+
export declare function tokenDestination(root: string, host: {
|
|
22
|
+
kind: string | null;
|
|
23
|
+
domain: string | null;
|
|
24
|
+
}): Promise<{
|
|
25
|
+
api: string | null;
|
|
26
|
+
apiHost: string | null;
|
|
27
|
+
}>;
|
|
19
28
|
export interface HostRequest {
|
|
20
29
|
token?: string;
|
|
21
30
|
/** How the token is sent: GitLab's PRIVATE-TOKEN header or a bearer token. */
|
|
@@ -20,6 +20,17 @@ export async function apiRoot(root, domain, fallback) {
|
|
|
20
20
|
const configured = (await git(root, "config", "--global", "--get", `phren.${domain}.api`).catch(() => "")).trim();
|
|
21
21
|
return (configured || fallback).replace(/\/+$/, "");
|
|
22
22
|
}
|
|
23
|
+
/** Resolve the exact endpoint once, so Connect can check and use the same URL.
|
|
24
|
+
* Only the hostname/port is exposed to clients, never API URL credentials. */
|
|
25
|
+
export async function tokenDestination(root, host) {
|
|
26
|
+
if (!host.domain || (host.kind !== "gitlab" && host.kind !== "gitboy"))
|
|
27
|
+
return { api: null, apiHost: host.domain };
|
|
28
|
+
const api = await apiRoot(root, host.domain, `https://${host.domain}/api/${host.kind === "gitlab" ? "v4" : "v1"}`);
|
|
29
|
+
const url = new URL(api);
|
|
30
|
+
if (!["https:", "http:"].includes(url.protocol) || !url.host)
|
|
31
|
+
throw new HostApiError("failed", "Invalid git host API address.");
|
|
32
|
+
return { api, apiHost: url.host.toLowerCase() };
|
|
33
|
+
}
|
|
23
34
|
export async function hostJson(url, request) {
|
|
24
35
|
const headers = { accept: "application/json", "user-agent": "phren-hook" };
|
|
25
36
|
if (request.token) {
|
|
@@ -22,6 +22,8 @@ export interface GitHost {
|
|
|
22
22
|
name: string;
|
|
23
23
|
/** The remote's domain and the repository's web address, when known. */
|
|
24
24
|
domain: string | null;
|
|
25
|
+
/** Actual token destination (including a configured API port), when resolved. */
|
|
26
|
+
apiHost?: string | null;
|
|
25
27
|
webUrl: string | null;
|
|
26
28
|
remote: string | null;
|
|
27
29
|
/** How the kind was found: from the URL, from an override, or not at all. */
|
|
@@ -56,7 +58,7 @@ export interface GitHostProvider {
|
|
|
56
58
|
* comes back as `{ ok: false, reason: "blocked", message }`. */
|
|
57
59
|
merge(root: string, request: MergeRequest, host: GitHost): Promise<Json>;
|
|
58
60
|
/** Who a token signs in as, for Connect; HTTP hosts only. */
|
|
59
|
-
whoami?(root: string, host: GitHost, token: string): Promise<{
|
|
61
|
+
whoami?(root: string, host: GitHost, token: string, api?: string): Promise<{
|
|
60
62
|
user: string;
|
|
61
63
|
}>;
|
|
62
64
|
}
|
|
@@ -7,7 +7,7 @@ import { defaultBranch, invalidatePulls, invalidateTree } from "./git.js";
|
|
|
7
7
|
import { z } from "zod";
|
|
8
8
|
import { detectHost, providerFor, unknownHost } from "./git-hosts.js";
|
|
9
9
|
import { writeHostToken } from "./git-host-auth.js";
|
|
10
|
-
import { HostApiError } from "./git-host-http.js";
|
|
10
|
+
import { HostApiError, tokenDestination } from "./git-host-http.js";
|
|
11
11
|
/** Finishing a session from the phone: commit what is staged, push the
|
|
12
12
|
* current branch, open a pull request. Each acts on the repository the
|
|
13
13
|
* existing /v1/git/* routes resolve (the pane's, a child's worktree, or a
|
|
@@ -231,16 +231,22 @@ export async function gitMergeRequest(cwd, data) {
|
|
|
231
231
|
* gitboy host: the token is checked against the host first and stored in the
|
|
232
232
|
* Hook's git-hosts.json with the account it signs in as. GitHub keeps gh's. */
|
|
233
233
|
export async function gitHostToken(cwd, data) {
|
|
234
|
-
const { token } = z.object({ token: z.string().max(4096) }).parse(data);
|
|
234
|
+
const { token, expectedHost } = z.object({ token: z.string().max(4096), expectedHost: z.string().trim().min(1).max(253).optional() }).parse(data);
|
|
235
235
|
const root = await repository(cwd);
|
|
236
236
|
const branch = (await git(root, "branch", "--show-current").catch(() => "")).trim();
|
|
237
237
|
const host = await detectHost(root, branch);
|
|
238
|
+
const { api, apiHost } = await tokenDestination(root, host);
|
|
239
|
+
host.apiHost = apiHost;
|
|
240
|
+
// Pin the resolved endpoint through validation, even if config changes now.
|
|
241
|
+
if (expectedHost !== undefined && apiHost !== expectedHost.toLowerCase()) {
|
|
242
|
+
throw new BridgeError(409, "The project's remote changed. Reopen to review the new host.", { code: "host-changed" });
|
|
243
|
+
}
|
|
238
244
|
const provider = providerFor(host);
|
|
239
245
|
if (!provider || !host.domain || !host.kind) {
|
|
240
246
|
const { reason, message } = unknownHost(host);
|
|
241
247
|
return { ok: false, reason, message, host };
|
|
242
248
|
}
|
|
243
|
-
if (host.kind === "github" || !provider.whoami)
|
|
249
|
+
if (host.kind === "github" || !provider.whoami || !api)
|
|
244
250
|
return { ok: false, reason: "unsupported", message: "GitHub uses the GitHub CLI's sign-in: run gh auth login on this computer.", host };
|
|
245
251
|
const kind = host.kind;
|
|
246
252
|
if (!token.trim()) {
|
|
@@ -248,13 +254,14 @@ export async function gitHostToken(cwd, data) {
|
|
|
248
254
|
return { ok: true, disconnected: true, domain: host.domain, host };
|
|
249
255
|
}
|
|
250
256
|
try {
|
|
251
|
-
const
|
|
257
|
+
const identity = await provider.whoami(root, host, token.trim(), api);
|
|
258
|
+
const user = identity.user.replaceAll(token.trim(), "[redacted]");
|
|
252
259
|
await writeHostToken(host.domain, kind, token.trim(), user || undefined);
|
|
253
260
|
return { ok: true, domain: host.domain, kind, ...(user ? { user } : {}), host };
|
|
254
261
|
}
|
|
255
262
|
catch (error) {
|
|
256
263
|
if (error instanceof HostApiError)
|
|
257
|
-
return { ok: false, reason: error.reason, message: error.reason === "auth" ? `${host.name} refused that token.` :
|
|
264
|
+
return { ok: false, reason: error.reason, message: error.reason === "auth" ? `${host.name} refused that token.` : `${host.name} could not validate that token.`, host };
|
|
258
265
|
throw error;
|
|
259
266
|
}
|
|
260
267
|
}
|
package/dist/bridge/git.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { type Json } from "./protocol.js";
|
|
2
|
+
import { detectHost } from "./git-hosts.js";
|
|
2
3
|
export { checkRollup, checkRuns } from "./git-hosts.js";
|
|
3
4
|
interface Counts {
|
|
4
5
|
additions: number;
|
|
@@ -40,6 +41,7 @@ export interface GitStatus {
|
|
|
40
41
|
files: GitStatusFile[];
|
|
41
42
|
/** The branch a push guards: the upstream remote's `HEAD`, else `main`/`master`. */
|
|
42
43
|
defaultBranch: string | null;
|
|
44
|
+
host: Awaited<ReturnType<typeof detectHost>>;
|
|
43
45
|
}
|
|
44
46
|
/** Working-tree status, one record per section: a file edited in both the index
|
|
45
47
|
* and the working tree appears once with `staged: true` and once with `false`. */
|
package/dist/bridge/git.js
CHANGED
|
@@ -4,6 +4,7 @@ import { lstat, open, readdir, realpath } from "node:fs/promises";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { BridgeError } from "./protocol.js";
|
|
6
6
|
import { git, gitHead, gitRoot, withGitReadDeadline, withIndependentGitReadDeadline, withoutGitReadDeadline } from "./projects.js";
|
|
7
|
+
import { tokenDestination } from "./git-host-http.js";
|
|
7
8
|
import { detectHost, providerFor, unknownHost } from "./git-hosts.js";
|
|
8
9
|
import { hostCredentialIdentity } from "./git-host-auth.js";
|
|
9
10
|
import { LookupCache } from "./lookup-cache.js";
|
|
@@ -130,6 +131,9 @@ async function readGitStatus(cwd, untrackedPath) {
|
|
|
130
131
|
treeCache.delete(root);
|
|
131
132
|
const data = await collect(root);
|
|
132
133
|
const fallback = await defaultBranch(root, data.upstream?.split("/")[0] || "origin");
|
|
134
|
+
const host = await detectHost(root, data.branch);
|
|
135
|
+
const { apiHost } = await tokenDestination(root, host);
|
|
136
|
+
host.apiHost = apiHost;
|
|
133
137
|
if (untrackedPath !== undefined) {
|
|
134
138
|
const prefix = await repositoryPath(root, untrackedPath);
|
|
135
139
|
if (!data.untracked.some(file => file.endsWith("/") && (prefix + "/").startsWith(file))
|
|
@@ -177,7 +181,7 @@ async function readGitStatus(cwd, untrackedPath) {
|
|
|
177
181
|
branch: data.branch, upstream: data.upstream ?? null, ahead: data.ahead, behind: data.behind,
|
|
178
182
|
staged: data.staged.size, unstaged: data.unstaged.size, untracked: data.untracked.length,
|
|
179
183
|
additions: files.reduce((total, file) => total + file.additions, 0), deletions: files.reduce((total, file) => total + file.deletions, 0), files,
|
|
180
|
-
defaultBranch: fallback };
|
|
184
|
+
defaultBranch: fallback, host };
|
|
181
185
|
}
|
|
182
186
|
/** The repository's remotes, so a branch ref can be told from a remote-tracking
|
|
183
187
|
* one even when a local branch name contains a slash. */
|
|
@@ -330,7 +334,9 @@ export async function gitPulls(cwd, retried = false) {
|
|
|
330
334
|
const { root, branch, host } = await withIndependentGitReadDeadline(async () => {
|
|
331
335
|
const root = await repository(cwd);
|
|
332
336
|
const branch = (await git(root, "branch", "--show-current").catch(() => "")).trim();
|
|
333
|
-
|
|
337
|
+
const host = await detectHost(root, branch);
|
|
338
|
+
const { apiHost } = await tokenDestination(root, host);
|
|
339
|
+
return { root, branch, host: { ...host, apiHost } };
|
|
334
340
|
});
|
|
335
341
|
const provider = providerFor(host);
|
|
336
342
|
const credential = await credentialIdentity(host);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { type Json } from "./protocol.js";
|
|
2
|
-
/**
|
|
2
|
+
/** Project git reads and token Connect share the same checkout lookup.
|
|
3
|
+
* `GET /v1/projects/:project/git`: the project's host, branch and open pull
|
|
3
4
|
* requests with their checks, read from its checkout on this computer, so the
|
|
4
5
|
* desktop's Projects page needs no session running there. */
|
|
5
6
|
export declare const PROJECT_GIT_ROUTE: RegExp;
|
|
6
|
-
/** The recorded source folder for this computer wins; otherwise the folders
|
|
7
|
-
* `/v1/projects/locate` offers, newest session first. */
|
|
8
7
|
export declare function projectGit(base: string, rawProject: string, activity: Json[]): Promise<Json>;
|
|
8
|
+
/** No pull-list read here: resolve locally before passing a token to the host. */
|
|
9
|
+
export declare function projectHostToken(base: string, rawProject: string, activity: Json[], data: unknown): Promise<Json>;
|
|
@@ -1,17 +1,20 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import { getProjectSourcePath } from "../project-config.js";
|
|
2
3
|
import { resolveProject } from "../store-routing.js";
|
|
3
4
|
import { isValidProjectName } from "../utils.js";
|
|
5
|
+
import { gitHostToken } from "./git-publish.js";
|
|
4
6
|
import { gitPulls } from "./git.js";
|
|
5
7
|
import { locateProject } from "./locate.js";
|
|
6
8
|
import { gitRoot } from "./projects.js";
|
|
7
9
|
import { BridgeError } from "./protocol.js";
|
|
8
|
-
/**
|
|
10
|
+
/** Project git reads and token Connect share the same checkout lookup.
|
|
11
|
+
* `GET /v1/projects/:project/git`: the project's host, branch and open pull
|
|
9
12
|
* requests with their checks, read from its checkout on this computer, so the
|
|
10
13
|
* desktop's Projects page needs no session running there. */
|
|
11
|
-
export const PROJECT_GIT_ROUTE = /^\/v1\/projects\/([^/]+)\/git
|
|
14
|
+
export const PROJECT_GIT_ROUTE = /^\/v1\/projects\/([^/]+)\/git(?:\/(host-token))?$/;
|
|
12
15
|
/** The recorded source folder for this computer wins; otherwise the folders
|
|
13
16
|
* `/v1/projects/locate` offers, newest session first. */
|
|
14
|
-
|
|
17
|
+
async function projectCheckout(base, rawProject, activity) {
|
|
15
18
|
let project;
|
|
16
19
|
try {
|
|
17
20
|
project = decodeURIComponent(rawProject);
|
|
@@ -33,7 +36,17 @@ export async function projectGit(base, rawProject, activity) {
|
|
|
33
36
|
for (const folder of folders) {
|
|
34
37
|
const root = await gitRoot(folder).catch(() => undefined);
|
|
35
38
|
if (root)
|
|
36
|
-
return { project, directory: root
|
|
39
|
+
return { project, directory: root };
|
|
37
40
|
}
|
|
38
41
|
throw new BridgeError(404, "No checkout of this project on this computer.", { code: "no-checkout" });
|
|
39
42
|
}
|
|
43
|
+
export async function projectGit(base, rawProject, activity) {
|
|
44
|
+
const checkout = await projectCheckout(base, rawProject, activity);
|
|
45
|
+
return { ...checkout, ...(await gitPulls(checkout.directory)) };
|
|
46
|
+
}
|
|
47
|
+
/** No pull-list read here: resolve locally before passing a token to the host. */
|
|
48
|
+
export async function projectHostToken(base, rawProject, activity, data) {
|
|
49
|
+
const request = z.object({ token: z.string().max(4096), expectedHost: z.string().trim().min(1).max(253) }).parse(data);
|
|
50
|
+
const checkout = await projectCheckout(base, rawProject, activity);
|
|
51
|
+
return gitHostToken(checkout.directory, request);
|
|
52
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type CitationFreshness } from "../content/citation-freshness.js";
|
|
1
2
|
import { type FindingItem } from "../data/access.js";
|
|
2
3
|
export declare const PROJECT_MEMORY_ROUTE: RegExp;
|
|
3
4
|
export declare const MEMORY_LIMITS: {
|
|
@@ -12,6 +13,7 @@ export interface MemoryFinding {
|
|
|
12
13
|
type: string | null;
|
|
13
14
|
status: FindingItem["status"];
|
|
14
15
|
created: string | null;
|
|
16
|
+
citationFreshness?: CitationFreshness;
|
|
15
17
|
citation: {
|
|
16
18
|
file: string | null;
|
|
17
19
|
line: number | null;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cachedCitationFreshness, refreshCitationFreshness } from "../content/citation-freshness.js";
|
|
1
2
|
import * as fs from "node:fs";
|
|
2
3
|
import * as path from "node:path";
|
|
3
4
|
import { readFindings } from "../data/access.js";
|
|
@@ -24,7 +25,11 @@ const TAG = new RegExp(`^\\[(${FINDING_TAGS.join("|")})\\]\\s*`, "i");
|
|
|
24
25
|
const DATE = /^\d{4}-\d{2}-\d{2}/;
|
|
25
26
|
/** Text that trips phren's credential detector is withheld whole, never cut. */
|
|
26
27
|
const safe = (text) => redactSecretsForLog(text);
|
|
27
|
-
function
|
|
28
|
+
function freshnessOptions(root, project) {
|
|
29
|
+
return { phrenPath: root, projectRemote: getProjectRemote(root, project, readProjectConfig(root, project)) };
|
|
30
|
+
}
|
|
31
|
+
function finding(item, opts) {
|
|
32
|
+
const citationFreshness = item.citationData ? cachedCitationFreshness(item.citationData, opts) : undefined;
|
|
28
33
|
const tag = TAG.exec(item.text);
|
|
29
34
|
const cite = item.citationData;
|
|
30
35
|
const citation = cite && (cite.file || cite.line || cite.commit || cite.symbol)
|
|
@@ -36,6 +41,7 @@ function finding(item) {
|
|
|
36
41
|
text: safe(tag ? item.text.slice(tag[0].length) : item.text),
|
|
37
42
|
type: tag ? tag[1].toLowerCase() : null,
|
|
38
43
|
status: item.status, created, citation,
|
|
44
|
+
...(citationFreshness ? { citationFreshness } : {}),
|
|
39
45
|
};
|
|
40
46
|
}
|
|
41
47
|
function task(item) {
|
|
@@ -66,10 +72,14 @@ function locate(base, rawProject) {
|
|
|
66
72
|
return { project, root, storeId };
|
|
67
73
|
}
|
|
68
74
|
/** Newest first, so a cap drops the oldest. Undated findings sort last. */
|
|
69
|
-
function sortedFindings(root, project) {
|
|
75
|
+
function sortedFindings(root, project, opts) {
|
|
70
76
|
const result = readFindings(root, project);
|
|
71
77
|
if (!result.ok)
|
|
72
78
|
throw new BridgeError(404, "Project not found.");
|
|
79
|
+
const citations = result.data.flatMap(item => item.citationData ? [item.citationData] : []);
|
|
80
|
+
// One batch per poll, after the response has been shaped. Refresh deduplicates overlapping polls.
|
|
81
|
+
if (citations.length)
|
|
82
|
+
setImmediate(() => { void refreshCitationFreshness(citations, { ...opts, budgetMs: 1500 }); });
|
|
73
83
|
return result.data.map((item, index) => ({ item, index, date: DATE.test(item.date) ? item.date : "" }))
|
|
74
84
|
.sort((a, b) => b.date.localeCompare(a.date) || a.index - b.index).map(entry => entry.item);
|
|
75
85
|
}
|
|
@@ -79,7 +89,8 @@ function readTruths(root, project) {
|
|
|
79
89
|
}
|
|
80
90
|
export function projectMemory(base, rawProject) {
|
|
81
91
|
const { project, root, storeId } = locate(base, rawProject);
|
|
82
|
-
const
|
|
92
|
+
const opts = freshnessOptions(root, project);
|
|
93
|
+
const allFindings = sortedFindings(root, project, opts);
|
|
83
94
|
const truths = readTruths(root, project).map(text => ({ text: safe(text) }));
|
|
84
95
|
// Tasks are their own module; with it off the sections are empty.
|
|
85
96
|
const taskDoc = readTasks(root, project);
|
|
@@ -87,8 +98,8 @@ export function projectMemory(base, rawProject) {
|
|
|
87
98
|
const truncated = allFindings.length > MEMORY_LIMITS.findings || items.Active.length > MEMORY_LIMITS.active
|
|
88
99
|
|| items.Queue.length > MEMORY_LIMITS.queue || items.Done.length > MEMORY_LIMITS.done;
|
|
89
100
|
return {
|
|
90
|
-
project, store_id: storeId, remote:
|
|
91
|
-
findings: allFindings.slice(0, MEMORY_LIMITS.findings).map(finding),
|
|
101
|
+
project, store_id: storeId, remote: opts.projectRemote ?? null, truncated,
|
|
102
|
+
findings: allFindings.slice(0, MEMORY_LIMITS.findings).map(item => finding(item, opts)),
|
|
92
103
|
truths,
|
|
93
104
|
tasks: {
|
|
94
105
|
active: items.Active.slice(0, MEMORY_LIMITS.active).map(task),
|
|
@@ -102,11 +113,12 @@ export function projectMemory(base, rawProject) {
|
|
|
102
113
|
* type or variable the code index places in one of them. */
|
|
103
114
|
export async function memoryForFiles(base, rawProject, paths) {
|
|
104
115
|
const { project, root, storeId } = locate(base, rawProject);
|
|
116
|
+
const opts = freshnessOptions(root, project);
|
|
105
117
|
if (paths.length < 1 || paths.length > MAX_FILE_PATHS || !paths.every(isRepoPath)) {
|
|
106
118
|
throw new BridgeError(400, `Send 1 to ${MAX_FILE_PATHS} repository-relative paths.`);
|
|
107
119
|
}
|
|
108
120
|
const wanted = new Set(paths);
|
|
109
|
-
const all = sortedFindings(root, project);
|
|
121
|
+
const all = sortedFindings(root, project, opts);
|
|
110
122
|
const citedFile = (item) => item.citationData?.file?.replace(/^\.\//, "");
|
|
111
123
|
const named = all.filter(item => item.citationData?.symbol && !wanted.has(citedFile(item) ?? ""));
|
|
112
124
|
let symbols = "unavailable";
|
|
@@ -125,9 +137,9 @@ export async function memoryForFiles(base, rawProject, paths) {
|
|
|
125
137
|
for (const item of all) {
|
|
126
138
|
const file = citedFile(item), name = item.citationData?.symbol;
|
|
127
139
|
if (file && wanted.has(file))
|
|
128
|
-
matches.push({ ...finding(item), match: "file" });
|
|
140
|
+
matches.push({ ...finding(item, opts), match: "file" });
|
|
129
141
|
else if (name && files[name] && wanted.has(files[name]))
|
|
130
|
-
matches.push({ ...finding(item), match: "symbol" });
|
|
142
|
+
matches.push({ ...finding(item, opts), match: "symbol" });
|
|
131
143
|
}
|
|
132
144
|
return { project, store_id: storeId, symbols, truncated: matches.length > MEMORY_LIMITS.findings,
|
|
133
145
|
findings: matches.slice(0, MEMORY_LIMITS.findings) };
|
|
@@ -142,12 +154,13 @@ export async function memoryForFiles(base, rawProject, paths) {
|
|
|
142
154
|
*/
|
|
143
155
|
export function memorySearch(base, rawProject, q, limit) {
|
|
144
156
|
const { project, root } = locate(base, rawProject);
|
|
157
|
+
const opts = freshnessOptions(root, project);
|
|
145
158
|
if (!isSearchText(q))
|
|
146
159
|
throw new BridgeError(400, "q must be 1 to 1000 characters of text.");
|
|
147
160
|
if (!Number.isInteger(limit) || limit < 1 || limit > MAX_SEARCH_LIMIT)
|
|
148
161
|
throw new BridgeError(400, `limit must be 1 to ${MAX_SEARCH_LIMIT}.`);
|
|
149
162
|
const entries = [
|
|
150
|
-
...sortedFindings(root, project).map(item => ({ kind: "finding", text: item.text, item })),
|
|
163
|
+
...sortedFindings(root, project, opts).map(item => ({ kind: "finding", text: item.text, item })),
|
|
151
164
|
...readTruths(root, project).map(text => ({ kind: "truth", text, item: undefined })),
|
|
152
165
|
];
|
|
153
166
|
const tokens = tokenizeForOverlap(q, 64);
|
|
@@ -170,7 +183,7 @@ export function memorySearch(base, rawProject, q, limit) {
|
|
|
170
183
|
continue;
|
|
171
184
|
const inactive = entry.item && entry.item.status !== "active";
|
|
172
185
|
const score = Math.round((best.rarity / weight) * (inactive ? 0.5 : 1) * 1000) / 1000;
|
|
173
|
-
const shaped = entry.item ? finding(entry.item) : null;
|
|
186
|
+
const shaped = entry.item ? finding(entry.item, opts) : null;
|
|
174
187
|
hits.push({ kind: entry.kind, score, matched: best.distinct, text: shaped ? shaped.text : safe(entry.text), finding: shaped });
|
|
175
188
|
}
|
|
176
189
|
hits.sort((a, b) => b.score - a.score || b.matched - a.matched);
|
|
@@ -209,7 +222,8 @@ let writes = Promise.resolve();
|
|
|
209
222
|
* project's write permission, duplicate and conflict checks, the secret
|
|
210
223
|
* scan and citation validation against the code index. */
|
|
211
224
|
export async function saveFinding(base, rawProject, input) {
|
|
212
|
-
const { project } = locate(base, rawProject);
|
|
225
|
+
const { project, root } = locate(base, rawProject);
|
|
226
|
+
const opts = freshnessOptions(root, project);
|
|
213
227
|
if (Buffer.byteLength(JSON.stringify(input ?? null)) > MAX_FINDING_BODY)
|
|
214
228
|
throw new BridgeError(413, `The body must be at most ${MAX_FINDING_BODY} bytes.`);
|
|
215
229
|
const body = findingWriteSchema.parse(input);
|
|
@@ -229,9 +243,9 @@ export async function saveFinding(base, rawProject, input) {
|
|
|
229
243
|
throw new BridgeError(/permission|denied|not allowed/i.test(error) ? 403 : 400, safe(error));
|
|
230
244
|
}
|
|
231
245
|
const status = result.data?.status === "skipped" ? "duplicate" : "saved";
|
|
232
|
-
const saved = status === "saved" ? sortedFindings(
|
|
246
|
+
const saved = status === "saved" ? sortedFindings(root, project, opts)
|
|
233
247
|
.find(item => item.text === (result.data?.finding ?? "").replace(/^-\s+/, "").trim()) : undefined;
|
|
234
|
-
return { project, status, finding: saved ? finding(saved) : null };
|
|
248
|
+
return { project, status, finding: saved ? finding(saved, opts) : null };
|
|
235
249
|
}
|
|
236
250
|
// ── POST /tasks/complete ─────────────────────────────────────────────────────
|
|
237
251
|
/** Mark one open task done, by the stable id `/tasks?branch=` gave gitboy when
|
package/dist/bridge/protocol.js
CHANGED
|
@@ -64,8 +64,8 @@ export const requestID = () => randomUUID();
|
|
|
64
64
|
export async function atomic(file, value, mode = 0o600) {
|
|
65
65
|
const temporary = `${file}.${randomUUID()}.tmp`;
|
|
66
66
|
const text = typeof value === "string" ? value : JSON.stringify(value);
|
|
67
|
-
await writeFile(temporary, text, { mode, flag: "wx" });
|
|
68
67
|
try {
|
|
68
|
+
await writeFile(temporary, text, { mode, flag: "wx" });
|
|
69
69
|
await renameOver(temporary, file);
|
|
70
70
|
}
|
|
71
71
|
finally {
|
|
@@ -141,6 +141,7 @@ export declare const capabilities: {
|
|
|
141
141
|
gitReview: boolean;
|
|
142
142
|
memoryStoreBatch: boolean;
|
|
143
143
|
gitHosts: boolean;
|
|
144
|
+
projectHostToken: boolean;
|
|
144
145
|
};
|
|
145
146
|
export declare function capabilitiesForModules(snapshot: ModuleSnapshot): Record<string, unknown>;
|
|
146
147
|
export declare function requireRoute(snapshot: ModuleSnapshot, method: string, route: string): void;
|
|
@@ -28,7 +28,7 @@ import { MAX_FILE_RANGE, rangeInteger, readFileRange } from "./file-range.js";
|
|
|
28
28
|
import { resolveFilePath } from "./file-resolve.js";
|
|
29
29
|
import { storeRoute } from "./memory-store.js";
|
|
30
30
|
import { memoryForFiles, memorySearch, PROJECT_MEMORY_ROUTE, projectMemory, saveFinding, tasksForBranch, completeProjectTask } from "./project-memory.js";
|
|
31
|
-
import { PROJECT_GIT_ROUTE, projectGit } from "./project-git.js";
|
|
31
|
+
import { PROJECT_GIT_ROUTE, projectGit, projectHostToken } from "./project-git.js";
|
|
32
32
|
import { liveBackground, markBackground, paneRecord, recordTitle, replyExcerpt } from "./session-activity.js";
|
|
33
33
|
import { paneAccountField, paneChatState, panes, rpc, servers, snapshot, validateTarget, workspaceSnapshot } from "./herdr.js";
|
|
34
34
|
import { locateProject } from "./locate.js";
|
|
@@ -81,7 +81,7 @@ async function childActivity(source, session) {
|
|
|
81
81
|
export const capabilities = { transcript: true, progress: true, images: true, prompt: true, stop: true,
|
|
82
82
|
terminal: "ssh-pty", shell: "ssh-pty", paneTerminal: "ssh-pty", paneLayout: true, deskPresence: true, herdr: true, sessionRename: true, diff: true, webServers: true, webPreview: "ssh-exec", activity: true,
|
|
83
83
|
approvals: true, questions: false, accountUsage: true, providers: ["codex", "claude", "copilot", "opencode"],
|
|
84
|
-
files: true, repositoryFiles: true, fileResolution: true, subagents: true, sideQuestions: true, dispatch: true, conductorSets: true, setLink: true, ownerInbox: true, workerReports: true, queuedHandOff: true, approvalPush: "direct-apns", simulators: process.platform === "darwin", code: true, codeFiles: true, overviewStream: true, speech: true, speechTimestamps: true, speechTimestampStream: true, speechLive: true, speechVoices: true, speechFormats: [...SPEECH_FORMATS], transcribe: true, memoryStore: true, promptOnce: true, promptStatus: true, deliveryFrames: true, paneDeliveries: true, resources: true, sudo: true, sudoOutcome: true, previewDeltas: true, quickChat: true, agentFolder: true, launchPermissionMode: true, sessionMove: true, moveNewChat: true, projectMemory: true, fileWrite: true, fileSearch: true, gitReview: true, memoryStoreBatch: true, gitHosts: true };
|
|
84
|
+
files: true, repositoryFiles: true, fileResolution: true, subagents: true, sideQuestions: true, dispatch: true, conductorSets: true, setLink: true, ownerInbox: true, workerReports: true, queuedHandOff: true, approvalPush: "direct-apns", simulators: process.platform === "darwin", code: true, codeFiles: true, overviewStream: true, speech: true, speechTimestamps: true, speechTimestampStream: true, speechLive: true, speechVoices: true, speechFormats: [...SPEECH_FORMATS], transcribe: true, memoryStore: true, promptOnce: true, promptStatus: true, deliveryFrames: true, paneDeliveries: true, resources: true, sudo: true, sudoOutcome: true, previewDeltas: true, quickChat: true, agentFolder: true, launchPermissionMode: true, sessionMove: true, moveNewChat: true, projectMemory: true, fileWrite: true, fileSearch: true, gitReview: true, memoryStoreBatch: true, gitHosts: true, projectHostToken: true };
|
|
85
85
|
export function capabilitiesForModules(snapshot) {
|
|
86
86
|
const allowed = new Set(snapshot.modules.flatMap(module => module.capabilities));
|
|
87
87
|
const result = Object.fromEntries(Object.entries(capabilities).filter(([name]) => allowed.has(name)));
|
|
@@ -352,11 +352,14 @@ export function createRouteHandler(ctx) {
|
|
|
352
352
|
result = await saveFinding(modules.store, project, await body(request));
|
|
353
353
|
}
|
|
354
354
|
else if (PROJECT_GIT_ROUTE.test(url.pathname)) {
|
|
355
|
-
|
|
355
|
+
const [, project, tokenRoute] = PROJECT_GIT_ROUTE.exec(url.pathname);
|
|
356
|
+
if (request.method !== (tokenRoute ? "POST" : "GET"))
|
|
356
357
|
throw new BridgeError(405, "Unsupported request method.");
|
|
357
358
|
if (!modules.has("git"))
|
|
358
359
|
throw new BridgeError(404, disabledHint("git"));
|
|
359
|
-
result =
|
|
360
|
+
result = tokenRoute
|
|
361
|
+
? await projectHostToken(modules.store, project, await journal.recent(), await body(request))
|
|
362
|
+
: await projectGit(modules.store, project, await journal.recent());
|
|
360
363
|
}
|
|
361
364
|
else if (url.pathname.startsWith("/v1/store/")) {
|
|
362
365
|
result = await storeRoute(modules.store, request.method ?? "", url, request.method === "POST" ? await body(request) : undefined);
|