@phnx-labs/agents-cli 1.23.20 → 1.23.22
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/CHANGELOG.md +126 -0
- package/README.md +17 -0
- package/dist/bootstrap.js +5 -4
- package/dist/cli/command-registry.js +2 -0
- package/dist/commands/config.js +16 -0
- package/dist/commands/daemon.js +3 -3
- package/dist/commands/doctor.js +10 -19
- package/dist/commands/events.js +1 -14
- package/dist/commands/feed-watch.js +5 -2
- package/dist/commands/go.js +2 -2
- package/dist/commands/lead.d.ts +3 -0
- package/dist/commands/lead.js +280 -0
- package/dist/commands/projects.js +3 -2
- package/dist/commands/ps-roster.d.ts +2 -12
- package/dist/commands/ps-roster.js +5 -87
- package/dist/commands/ps.js +3 -1
- package/dist/commands/repo.js +12 -12
- package/dist/commands/resource-view.js +5 -5
- package/dist/commands/sessions-browser.js +2 -2
- package/dist/commands/sessions-watch.js +5 -2
- package/dist/commands/setup-secrets.d.ts +3 -4
- package/dist/commands/setup-secrets.js +15 -46
- package/dist/commands/setup-session-backup.js +1 -1
- package/dist/commands/ssh.d.ts +0 -4
- package/dist/commands/ssh.js +14 -81
- package/dist/commands/teams-picker.js +1 -12
- package/dist/commands/teams.js +1 -13
- package/dist/commands/view.d.ts +1 -40
- package/dist/commands/view.js +9 -330
- package/dist/commands/watchdog.js +4 -4
- package/dist/index.js +4 -0
- package/dist/lib/accounting/usage.d.ts +0 -1
- package/dist/lib/accounting/usage.js +1 -112
- package/dist/lib/accounts/add.js +1 -1
- package/dist/lib/accounts/migrate.js +1 -1
- package/dist/lib/auto-pull-worker.js +2 -16
- package/dist/lib/auto-pull.d.ts +1 -0
- package/dist/lib/auto-pull.js +27 -0
- package/dist/lib/browser-client.js +2 -11
- package/dist/lib/cloud/codex.js +3 -0
- package/dist/lib/commands.d.ts +0 -6
- package/dist/lib/commands.js +3 -116
- package/dist/lib/comms-render.d.ts +1 -7
- package/dist/lib/comms-render.js +0 -19
- package/dist/lib/computer-client.js +2 -11
- package/dist/lib/config-keys.d.ts +7 -3
- package/dist/lib/config-keys.js +15 -2
- package/dist/lib/crabbox/runtimes.d.ts +0 -14
- package/dist/lib/crabbox/runtimes.js +0 -80
- package/dist/lib/daemon/attention-notify-service.d.ts +51 -28
- package/dist/lib/daemon/attention-notify-service.js +219 -53
- package/dist/lib/daemon/daemon.js +1 -2
- package/dist/lib/daemon/feed-stream-service.js +2 -4
- package/dist/lib/device-config.d.ts +0 -5
- package/dist/lib/device-config.js +20 -27
- package/dist/lib/devices/doctor-findings.d.ts +2 -1
- package/dist/lib/devices/doctor-findings.js +12 -1
- package/dist/lib/devices/fleet.d.ts +6 -0
- package/dist/lib/devices/fleet.js +15 -0
- package/dist/lib/devices/harness-inventory.d.ts +9 -0
- package/dist/lib/devices/harness-inventory.js +66 -0
- package/dist/lib/exec.js +1 -3
- package/dist/lib/feed/attention.d.ts +16 -1
- package/dist/lib/feed/attention.js +63 -1
- package/dist/lib/feed/feed.d.ts +1 -1
- package/dist/lib/feed/feed.js +12 -2
- package/dist/lib/feed/hub.d.ts +9 -0
- package/dist/lib/feed/hub.js +27 -1
- package/dist/lib/feed/notify-schedule.d.ts +16 -0
- package/dist/lib/feed/notify-schedule.js +62 -0
- package/dist/lib/feed/ticket-priority.d.ts +4 -0
- package/dist/lib/feed/ticket-priority.js +30 -0
- package/dist/lib/feed/watch.d.ts +1 -0
- package/dist/lib/feed/watch.js +27 -3
- package/dist/lib/feed-ranking.d.ts +1 -0
- package/dist/lib/feed-ranking.js +3 -1
- package/dist/lib/format.d.ts +0 -2
- package/dist/lib/format.js +0 -8
- package/dist/lib/github/open-prs.d.ts +0 -2
- package/dist/lib/github/open-prs.js +17 -35
- package/dist/lib/github/project-prs.d.ts +5 -0
- package/dist/lib/github/project-prs.js +73 -32
- package/dist/lib/helper-versions.js +1 -1
- package/dist/lib/hooks/cache.d.ts +1 -0
- package/dist/lib/hooks/cache.js +12 -1
- package/dist/lib/installations/duplicate-prune.d.ts +37 -0
- package/dist/lib/installations/duplicate-prune.js +85 -0
- package/dist/lib/installations/inventory-json.d.ts +20 -0
- package/dist/lib/installations/inventory-json.js +252 -0
- package/dist/lib/installations/shims.d.ts +0 -18
- package/dist/lib/installations/shims.js +1 -257
- package/dist/lib/lead/brief.d.ts +49 -0
- package/dist/lib/lead/brief.js +173 -0
- package/dist/lib/lead/client.d.ts +21 -0
- package/dist/lib/lead/client.js +167 -0
- package/dist/lib/lead/confirm.d.ts +22 -0
- package/dist/lib/lead/confirm.js +73 -0
- package/dist/lib/lead/events.d.ts +106 -0
- package/dist/lib/lead/events.js +188 -0
- package/dist/lib/lead/harness.d.ts +29 -0
- package/dist/lib/lead/harness.js +107 -0
- package/dist/lib/lead/host.d.ts +132 -0
- package/dist/lib/lead/host.js +675 -0
- package/dist/lib/lead/paths.d.ts +22 -0
- package/dist/lib/lead/paths.js +69 -0
- package/dist/lib/lead/refs.d.ts +17 -0
- package/dist/lib/lead/refs.js +75 -0
- package/dist/lib/lead/roster.d.ts +26 -0
- package/dist/lib/lead/roster.js +121 -0
- package/dist/lib/lead/shapes.d.ts +23 -0
- package/dist/lib/lead/shapes.js +95 -0
- package/dist/lib/lead/store.d.ts +46 -0
- package/dist/lib/lead/store.js +77 -0
- package/dist/lib/lead/tools.d.ts +18 -0
- package/dist/lib/lead/tools.js +106 -0
- package/dist/lib/lead/visibility.d.ts +16 -0
- package/dist/lib/lead/visibility.js +77 -0
- package/dist/lib/mailbox.d.ts +0 -18
- package/dist/lib/mailbox.js +0 -170
- package/dist/lib/menubar/notify-desktop.d.ts +5 -0
- package/dist/lib/menubar/notify-desktop.js +24 -0
- package/dist/lib/models.js +1 -19
- package/dist/lib/permissions.d.ts +0 -6
- package/dist/lib/permissions.js +0 -140
- package/dist/lib/platform/process.d.ts +1 -0
- package/dist/lib/platform/process.js +5 -0
- package/dist/lib/probe.js +13 -1
- package/dist/lib/project-status.js +4 -3
- package/dist/lib/projects.d.ts +9 -0
- package/dist/lib/projects.js +61 -3
- package/dist/lib/scheduling/routines.d.ts +1 -13
- package/dist/lib/scheduling/routines.js +1 -37
- package/dist/lib/secrets-cli.d.ts +3 -3
- package/dist/lib/secrets-cli.js +1 -1
- package/dist/lib/secrets-client.d.ts +4 -37
- package/dist/lib/secrets-client.js +19 -265
- package/dist/lib/session/active.d.ts +18 -8
- package/dist/lib/session/active.js +94 -18
- package/dist/lib/session/db.d.ts +0 -16
- package/dist/lib/session/db.js +1 -134
- package/dist/lib/session/detached.d.ts +0 -1
- package/dist/lib/session/detached.js +0 -18
- package/dist/lib/session/pending-work.d.ts +21 -0
- package/dist/lib/session/pending-work.js +284 -0
- package/dist/lib/session/remote/remote-list.d.ts +0 -3
- package/dist/lib/session/remote/remote-list.js +1 -23
- package/dist/lib/session/remote/watch.d.ts +5 -0
- package/dist/lib/session/remote/watch.js +19 -2
- package/dist/lib/session/session-cache.d.ts +1 -1
- package/dist/lib/session/session-cache.js +12 -5
- package/dist/lib/session/sync/provision.js +1 -2
- package/dist/lib/smart-launch.js +7 -2
- package/dist/lib/snapshot.js +3 -4
- package/dist/lib/ssh-exec.d.ts +0 -40
- package/dist/lib/ssh-exec.js +0 -108
- package/dist/lib/ssh-tunnel.d.ts +0 -6
- package/dist/lib/ssh-tunnel.js +0 -42
- package/dist/lib/standalone-tools.js +12 -1
- package/dist/lib/startup/command-registry.js +1 -1
- package/dist/lib/startup/spellcheck.d.ts +0 -1
- package/dist/lib/startup/spellcheck.js +1 -20
- package/dist/lib/state.d.ts +0 -6
- package/dist/lib/state.js +1 -14
- package/dist/lib/teams/delivery.d.ts +1 -0
- package/dist/lib/teams/delivery.js +13 -0
- package/dist/lib/types.d.ts +0 -37
- package/dist/lib/types.js +0 -9
- package/dist/lib/watchdog/log.d.ts +1 -1
- package/dist/lib/watchdog/log.js +6 -4
- package/package.json +2 -1
- package/dist/lib/artifact-actions.d.ts +0 -7
- package/dist/lib/artifact-actions.js +0 -39
- package/dist/lib/session/sync/managed-config.d.ts +0 -3
- package/dist/lib/session/sync/managed-config.js +0 -3
- package/dist/lib/session/sync/worker-template.d.ts +0 -1
- package/dist/lib/session/sync/worker-template.js +0 -807
- package/dist/lib/storage/selection.d.ts +0 -8
- package/dist/lib/storage/selection.js +0 -10
- package/dist/lib/watchdog/index.d.ts +0 -3
- package/dist/lib/watchdog/index.js +0 -3
package/dist/lib/format.js
CHANGED
|
@@ -93,17 +93,9 @@ export function parseCommaSeparatedList(value) {
|
|
|
93
93
|
.map((item) => item.trim())
|
|
94
94
|
.filter(Boolean);
|
|
95
95
|
}
|
|
96
|
-
export function visibleWidth(s) {
|
|
97
|
-
// eslint-disable-next-line no-control-regex
|
|
98
|
-
return s.replace(/\x1b\[[0-9;]*m/g, '').length;
|
|
99
|
-
}
|
|
100
96
|
export function padRight(s, width) {
|
|
101
97
|
return s.length >= width ? s : s + ' '.repeat(width - s.length);
|
|
102
98
|
}
|
|
103
|
-
export function padVisible(s, width) {
|
|
104
|
-
const w = visibleWidth(s);
|
|
105
|
-
return w >= width ? s : s + ' '.repeat(width - w);
|
|
106
|
-
}
|
|
107
99
|
export function isJsonMode(opts) {
|
|
108
100
|
// Piped output stays human-readable unless the caller explicitly requests JSON.
|
|
109
101
|
return Boolean(opts.json);
|
|
@@ -30,8 +30,6 @@ export interface OpenPrsOptions {
|
|
|
30
30
|
owners?: string[];
|
|
31
31
|
repo?: string;
|
|
32
32
|
number?: number;
|
|
33
|
-
cacheDir?: string;
|
|
34
|
-
nowMs?: number;
|
|
35
33
|
}
|
|
36
34
|
export declare const SEARCH_RESULT_CAP = 1000;
|
|
37
35
|
export declare function listViewerOwners(viewer: string | null, gh?: GhExec): Promise<string[]>;
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { ghExec, canonicalizeRepo, projectRepoSlugs } from './pr-mergeable.js';
|
|
2
|
-
import { CiErrors,
|
|
3
|
-
import { getCacheDir } from '../state.js';
|
|
2
|
+
import { CiErrors, PR_NODE_FIELDS, enrichPr, fetchOnePr, fetchViewer, ghFailure, prFromNode, readRepoMergeAbility, } from './project-prs.js';
|
|
4
3
|
const NEEDS_ME_RANK = { review: 0, failing: 1, conflicts: 2 };
|
|
5
4
|
export const SEARCH_RESULT_CAP = 1000;
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
5
|
+
const SEARCH_QUERY = `query($q: String!, $endCursor: String) {
|
|
6
|
+
search(query: $q, type: ISSUE, first: 100, after: $endCursor) {
|
|
7
|
+
pageInfo { hasNextPage endCursor }
|
|
8
|
+
nodes { ... on PullRequest { ${PR_NODE_FIELDS} } }
|
|
9
|
+
}
|
|
10
|
+
}`;
|
|
13
11
|
async function searchOpenPrs(qualifier, gh) {
|
|
14
|
-
const q = encodeURIComponent(`is:pr is:open archived:false ${qualifier}`);
|
|
15
12
|
const out = await gh([
|
|
16
|
-
'api',
|
|
13
|
+
'api', 'graphql', '--paginate',
|
|
14
|
+
'-f', `q=is:pr is:open archived:false sort:updated-desc ${qualifier}`, '-f', `query=${SEARCH_QUERY}`,
|
|
15
|
+
'--jq', '.data.search.nodes[] | select(.number)',
|
|
17
16
|
]);
|
|
18
|
-
return
|
|
17
|
+
return out.split('\n').filter((l) => l.trim()).map((l) => prFromNode(JSON.parse(l)));
|
|
19
18
|
}
|
|
20
19
|
export async function listViewerOwners(viewer, gh = ghExec) {
|
|
21
20
|
const orgs = (await gh(['api', 'user/orgs', '--paginate', '--cache', '1h', '--jq', '.[].login']))
|
|
@@ -113,39 +112,22 @@ export async function buildOpenPrs(defs, opts = {}, gh = ghExec) {
|
|
|
113
112
|
prs.set(pr.number, pr);
|
|
114
113
|
bySlug.set(slug, prs);
|
|
115
114
|
}
|
|
116
|
-
const cacheDir = opts.cacheDir ?? getCacheDir();
|
|
117
|
-
const rollups = new KeyedCache(cacheDir, 'project-pr-ci.json', '@', isCachedRollup);
|
|
118
|
-
const nowMs = opts.nowMs ?? Date.now();
|
|
119
115
|
const projects = await projectMap;
|
|
120
|
-
const
|
|
121
|
-
for (const slug of bySlug.keys())
|
|
122
|
-
readers.set(slug, { slug, gh, rollups, errors: new CiErrors(), nowMs, reads: new Map() });
|
|
116
|
+
const errors = new Map([...bySlug.keys()].map((slug) => [slug, new CiErrors()]));
|
|
123
117
|
const merges = new Map([...bySlug.keys()].map((slug) => [slug, readRepoMergeAbility(slug, gh).catch((err) => {
|
|
124
|
-
|
|
118
|
+
errors.get(slug).record(err);
|
|
125
119
|
return null;
|
|
126
120
|
})]));
|
|
127
|
-
const listed = [...bySlug].flatMap(([slug, prs]) => [...prs.values()].map((pr) => ({ slug, pr })));
|
|
128
|
-
const read = await mapBounded(listed, 8, async ({ slug, pr: row }) => {
|
|
129
|
-
const ci = readers.get(slug);
|
|
130
|
-
let pr = row;
|
|
131
|
-
try {
|
|
132
|
-
pr = await fetchOnePr(slug, row.number, gh, '60s');
|
|
133
|
-
}
|
|
134
|
-
catch (err) {
|
|
135
|
-
ci.errors.record(err);
|
|
136
|
-
}
|
|
137
|
-
const ciSummary = await readCi(ci, pr.headSha || null);
|
|
138
|
-
return { slug, pr: withNeeds({ ...pr, ...ciSummary }, viewer, requested.has(key(slug, pr.number))) };
|
|
139
|
-
});
|
|
140
121
|
const repositories = await Promise.all([...bySlug.keys()].map(async (slug) => ({
|
|
141
122
|
slug,
|
|
142
123
|
projects: projects.get(slug.toLowerCase()) ?? [],
|
|
143
124
|
merge: await merges.get(slug),
|
|
144
|
-
pullRequests:
|
|
145
|
-
|
|
125
|
+
pullRequests: [...bySlug.get(slug).values()]
|
|
126
|
+
.map((pr) => withNeeds(pr, viewer, requested.has(key(slug, pr.number))))
|
|
127
|
+
.sort(compareOpenPrs),
|
|
128
|
+
ciError: errors.get(slug).message,
|
|
146
129
|
})));
|
|
147
130
|
repositories.sort(compareRepos);
|
|
148
|
-
rollups.save();
|
|
149
131
|
const owners = ownerReads.map((r) => r.owner);
|
|
150
132
|
return {
|
|
151
133
|
viewer,
|
|
@@ -94,6 +94,11 @@ export interface ProjectPrsOptions {
|
|
|
94
94
|
number?: number;
|
|
95
95
|
}
|
|
96
96
|
export declare function rowToProjectPr(row: Record<string, unknown>): ProjectPr;
|
|
97
|
+
export declare const PR_NODE_FIELDS = "\n number title url isDraft state createdAt updatedAt body\n author { __typename login avatarUrl }\n repository { nameWithOwner }\n headRefName baseRefName headRefOid mergeable mergeStateStatus\n autoMergeRequest { enabledBy { login } mergeMethod }\n commits(last: 1) { nodes { commit { statusCheckRollup { state contexts(first: 100) { pageInfo { hasNextPage } nodes {\n __typename\n ... on CheckRun { name status conclusion detailsUrl }\n ... on StatusContext { context state targetUrl }\n } } } } } }";
|
|
98
|
+
export declare function prFromNode(node: Record<string, unknown>): {
|
|
99
|
+
slug: string;
|
|
100
|
+
pr: ProjectPr;
|
|
101
|
+
};
|
|
97
102
|
export declare function listOpenPrs(repo: string, gh?: GhExec): Promise<ProjectPr[]>;
|
|
98
103
|
export declare function fetchOnePr(repo: string, number: number, gh?: GhExec, cache?: string): Promise<ProjectPr>;
|
|
99
104
|
export declare function fetchReviewAndHead(repo: string, number: number, gh?: GhExec): Promise<{
|
|
@@ -50,16 +50,75 @@ export function rowToProjectPr(row) {
|
|
|
50
50
|
: null,
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
+
export const PR_NODE_FIELDS = `
|
|
54
|
+
number title url isDraft state createdAt updatedAt body
|
|
55
|
+
author { __typename login avatarUrl }
|
|
56
|
+
repository { nameWithOwner }
|
|
57
|
+
headRefName baseRefName headRefOid mergeable mergeStateStatus
|
|
58
|
+
autoMergeRequest { enabledBy { login } mergeMethod }
|
|
59
|
+
commits(last: 1) { nodes { commit { statusCheckRollup { state contexts(first: 100) { pageInfo { hasNextPage } nodes {
|
|
60
|
+
__typename
|
|
61
|
+
... on CheckRun { name status conclusion detailsUrl }
|
|
62
|
+
... on StatusContext { context state targetUrl }
|
|
63
|
+
} } } } } }`;
|
|
64
|
+
const OPEN_PRS_QUERY = `query($owner: String!, $name: String!, $endCursor: String) {
|
|
65
|
+
repository(owner: $owner, name: $name) {
|
|
66
|
+
pullRequests(states: OPEN, first: 100, after: $endCursor, orderBy: {field: CREATED_AT, direction: DESC}) {
|
|
67
|
+
pageInfo { hasNextPage endCursor }
|
|
68
|
+
nodes { ${PR_NODE_FIELDS} }
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}`;
|
|
72
|
+
const MERGEABLE = { MERGEABLE: true, CONFLICTING: false };
|
|
73
|
+
function rollupFromContexts(contexts) {
|
|
74
|
+
const byName = new Map();
|
|
75
|
+
for (const c of contexts) {
|
|
76
|
+
if (c.__typename !== 'StatusContext')
|
|
77
|
+
continue;
|
|
78
|
+
const name = String(c.context ?? '');
|
|
79
|
+
if (!byName.has(name))
|
|
80
|
+
byName.set(name, { name, state: String(c.state ?? ''), link: String(c.targetUrl ?? '') });
|
|
81
|
+
}
|
|
82
|
+
for (const c of contexts) {
|
|
83
|
+
if (c.__typename !== 'CheckRun')
|
|
84
|
+
continue;
|
|
85
|
+
const name = String(c.name ?? '');
|
|
86
|
+
byName.set(name, { name, status: String(c.status ?? ''), conclusion: String(c.conclusion ?? ''), link: String(c.detailsUrl ?? '') });
|
|
87
|
+
}
|
|
88
|
+
return [...byName.values()];
|
|
89
|
+
}
|
|
90
|
+
export function prFromNode(node) {
|
|
91
|
+
const rec = (v) => (isRecord(v) ? v : {});
|
|
92
|
+
const author = rec(node.author);
|
|
93
|
+
const auto = isRecord(node.autoMergeRequest) ? node.autoMergeRequest : null;
|
|
94
|
+
const commits = rec(node.commits).nodes;
|
|
95
|
+
const commit = rec(rec(Array.isArray(commits) ? commits[0] : null).commit);
|
|
96
|
+
const rollup = rec(commit.statusCheckRollup);
|
|
97
|
+
const contexts = rec(rollup.contexts).nodes;
|
|
98
|
+
const truncated = rec(rec(rollup.contexts).pageInfo).hasNextPage === true;
|
|
99
|
+
const pr = rowToProjectPr({
|
|
100
|
+
...node,
|
|
101
|
+
login: `${author.login ?? ''}${author.__typename === 'Bot' ? '[bot]' : ''}`,
|
|
102
|
+
avatarUrl: author.avatarUrl ?? '',
|
|
103
|
+
headSha: node.headRefOid ?? '',
|
|
104
|
+
mergeable: MERGEABLE[String(node.mergeable)] ?? null,
|
|
105
|
+
mergeableState: typeof node.mergeStateStatus === 'string' ? node.mergeStateStatus.toLowerCase() : null,
|
|
106
|
+
autoMerge: auto ? { enabledBy: rec(auto.enabledBy).login ?? '', method: String(auto.mergeMethod ?? '').toLowerCase() } : null,
|
|
107
|
+
});
|
|
108
|
+
const items = rollupFromContexts(Array.isArray(contexts) ? contexts.filter(isRecord) : []);
|
|
109
|
+
const ci = { ...ciFromRollupItems(items) };
|
|
110
|
+
if (truncated && typeof rollup.state === 'string')
|
|
111
|
+
ci.ciState = rollup.state;
|
|
112
|
+
return { slug: String(rec(node.repository).nameWithOwner ?? ''), pr: { ...pr, ...ci } };
|
|
113
|
+
}
|
|
53
114
|
export async function listOpenPrs(repo, gh = ghExec) {
|
|
115
|
+
const [owner, name] = repo.split('/');
|
|
54
116
|
const out = await gh([
|
|
55
|
-
'api',
|
|
56
|
-
`
|
|
57
|
-
'--
|
|
58
|
-
'--cache', '60s',
|
|
59
|
-
'--jq',
|
|
60
|
-
`.[] | ${PR_JQ}`,
|
|
117
|
+
'api', 'graphql', '--paginate',
|
|
118
|
+
'-f', `owner=${owner}`, '-f', `name=${name}`, '-f', `query=${OPEN_PRS_QUERY}`,
|
|
119
|
+
'--jq', '.data.repository.pullRequests.nodes[]',
|
|
61
120
|
]);
|
|
62
|
-
return parseNdjson(out).map(
|
|
121
|
+
return parseNdjson(out).map((node) => prFromNode(node).pr);
|
|
63
122
|
}
|
|
64
123
|
export async function fetchOnePr(repo, number, gh = ghExec, cache) {
|
|
65
124
|
const out = await gh(['api', `repos/${repo}/pulls/${number}`, ...(cache ? ['--cache', cache] : []), '--jq', PR_JQ]);
|
|
@@ -270,16 +329,6 @@ export async function listRecentlyMerged(repo, sinceMs, gh = ghExec) {
|
|
|
270
329
|
}));
|
|
271
330
|
return { merged, truncated };
|
|
272
331
|
}
|
|
273
|
-
async function readMergeState(slug, number, gh, errors) {
|
|
274
|
-
try {
|
|
275
|
-
const { mergeable, mergeableState } = await fetchOnePr(slug, number, gh, '60s');
|
|
276
|
-
return { mergeable, mergeableState };
|
|
277
|
-
}
|
|
278
|
-
catch (err) {
|
|
279
|
-
errors.record(err);
|
|
280
|
-
return {};
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
332
|
async function readMergedDetail(slug, number, gh, details, errors) {
|
|
284
333
|
const hit = details.get(slug, number);
|
|
285
334
|
if (hit)
|
|
@@ -463,20 +512,13 @@ export async function buildProjectPrs(def, opts = {}, gh = ghExec, peers = [], c
|
|
|
463
512
|
? withMergesSince(tag, mergedListed ? merged.map((m) => m.pr) : null, { sinceMs, truncated: mergedRead?.truncated ?? false, base: defaultBranch?.name ?? null })
|
|
464
513
|
: null;
|
|
465
514
|
merged = merged.slice(0, MERGED_LIMIT);
|
|
466
|
-
const
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
readMergedDetail(slug, m.pr.number, gh, details, errors),
|
|
474
|
-
readCi(ci, m.pr.mergeCommitSha),
|
|
475
|
-
]);
|
|
476
|
-
return { ...m.pr, ...(detail ?? {}), ...mergeCi };
|
|
477
|
-
}),
|
|
478
|
-
]);
|
|
479
|
-
pullRequests = pullRequests.map((pr, i) => ({ ...pr, ...openCi[i] }));
|
|
515
|
+
const recentlyMerged = await mapBounded(merged, 8, async (m) => {
|
|
516
|
+
const [detail, mergeCi] = await Promise.all([
|
|
517
|
+
readMergedDetail(slug, m.pr.number, gh, details, errors),
|
|
518
|
+
readCi(ci, m.pr.mergeCommitSha),
|
|
519
|
+
]);
|
|
520
|
+
return { ...m.pr, ...(detail ?? {}), ...mergeCi };
|
|
521
|
+
});
|
|
480
522
|
const { merge, error: mergeError } = await mergeRead;
|
|
481
523
|
if (mergeError !== null)
|
|
482
524
|
errors.record(mergeError);
|
|
@@ -484,7 +526,6 @@ export async function buildProjectPrs(def, opts = {}, gh = ghExec, peers = [], c
|
|
|
484
526
|
details.prune(slug, new Set(mergedListed.map((m) => String(m.pr.number))));
|
|
485
527
|
if (defaultBranch) {
|
|
486
528
|
rollups.prune(slug, new Set([
|
|
487
|
-
...listed.map((pr) => pr.headSha),
|
|
488
529
|
...mergedListed.flatMap((m) => (m.pr.mergeCommitSha ? [m.pr.mergeCommitSha] : [])),
|
|
489
530
|
defaultBranch.sha,
|
|
490
531
|
]));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { HookCache, HookCacheConfig, HookMatches } from '../types.js';
|
|
2
2
|
export declare function parseCacheConfig(raw: HookCache | undefined): HookCacheConfig | null;
|
|
3
3
|
export declare function parseDuration(d: number | string | undefined): number | null;
|
|
4
|
+
export declare function parseSince(raw: string): Date;
|
|
4
5
|
export declare function isValidHookShimName(name: string): boolean;
|
|
5
6
|
export declare function getHookShimPath(name: string): string;
|
|
6
7
|
export interface HookShimPaths {
|
package/dist/lib/hooks/cache.js
CHANGED
|
@@ -34,13 +34,15 @@ export function parseDuration(d) {
|
|
|
34
34
|
return null;
|
|
35
35
|
if (typeof d === 'number')
|
|
36
36
|
return Number.isFinite(d) && d > 0 ? Math.floor(d) : null;
|
|
37
|
-
const m = d.trim().match(/^(\d+)\s*(s|sec|secs|m|min|mins|h|hr|hrs|d|day|days)?$/i);
|
|
37
|
+
const m = d.trim().match(/^(\d+)\s*(s|sec|secs|m|min|mins|h|hr|hrs|d|day|days|w|wk|wks|week|weeks)?$/i);
|
|
38
38
|
if (!m)
|
|
39
39
|
return null;
|
|
40
40
|
const value = parseInt(m[1], 10);
|
|
41
41
|
if (!Number.isFinite(value) || value <= 0)
|
|
42
42
|
return null;
|
|
43
43
|
const unit = (m[2] || 's').toLowerCase();
|
|
44
|
+
if (unit.startsWith('w'))
|
|
45
|
+
return value * 604800;
|
|
44
46
|
if (unit.startsWith('d'))
|
|
45
47
|
return value * 86400;
|
|
46
48
|
if (unit.startsWith('h'))
|
|
@@ -49,6 +51,15 @@ export function parseDuration(d) {
|
|
|
49
51
|
return value * 60;
|
|
50
52
|
return value;
|
|
51
53
|
}
|
|
54
|
+
export function parseSince(raw) {
|
|
55
|
+
const seconds = parseDuration(raw);
|
|
56
|
+
if (seconds != null)
|
|
57
|
+
return new Date(Date.now() - seconds * 1000);
|
|
58
|
+
const ms = Date.parse(raw);
|
|
59
|
+
if (Number.isNaN(ms))
|
|
60
|
+
throw new Error(`Invalid --since value: ${raw} (use e.g. 2h, 7d, 1w, or an ISO date)`);
|
|
61
|
+
return new Date(ms);
|
|
62
|
+
}
|
|
52
63
|
// Shim names become path segments; validation is the traversal boundary.
|
|
53
64
|
export function isValidHookShimName(name) {
|
|
54
65
|
return (!!name &&
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { AccountInfo } from '../agents.js';
|
|
2
|
+
export declare function compareVersionLabels(a: string, b: string): number;
|
|
3
|
+
export declare function pruneGroupKey(info: Pick<AccountInfo, 'accountKey' | 'email'>): string | null;
|
|
4
|
+
export interface PruneCandidate {
|
|
5
|
+
version: string;
|
|
6
|
+
release: string;
|
|
7
|
+
email: string | null;
|
|
8
|
+
accountKey: string | null;
|
|
9
|
+
signedIn: boolean;
|
|
10
|
+
hasBinary: boolean;
|
|
11
|
+
}
|
|
12
|
+
export interface DuplicatePruneEntry {
|
|
13
|
+
version: string;
|
|
14
|
+
email: string;
|
|
15
|
+
keeper: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* PURE duplicate-home detection: given every installed home for one agent, decide
|
|
19
|
+
* which are redundant duplicates of the SAME logical account and which single home
|
|
20
|
+
* to keep per account. Extracted from buildAgentPrunePlan so the keeper/merge rules
|
|
21
|
+
* are unit-tested without touching disk.
|
|
22
|
+
*
|
|
23
|
+
* Two rules, both conservative:
|
|
24
|
+
* - GROUPING. A home with a captured `accountKey` groups by it (account+org, so a
|
|
25
|
+
* personal Max and a Team seat on the same email stay separate). A home with NO
|
|
26
|
+
* accountKey folds into a same-email account ONLY when a sibling home for that
|
|
27
|
+
* email IS identified — that email-only home is an incompletely-captured re-login
|
|
28
|
+
* of the known account, not a distinct seat (PHNX-3887). Otherwise it groups by
|
|
29
|
+
* its bare email and only ever collapses against another equally-bare home.
|
|
30
|
+
* - KEEPER. Within a group the keeper is the home that best represents the account:
|
|
31
|
+
* captured identity first, then a signed-in credential, then the newest RUNNING
|
|
32
|
+
* release, then the highest dir label as a stable tiebreak. This is deliberately
|
|
33
|
+
* NOT "highest dir-name semver" — in the wild that is the freshly re-logged-in
|
|
34
|
+
* duplicate that never captured its identity or usage, and keeping it while
|
|
35
|
+
* trashing the identified home is the exact bug this replaces.
|
|
36
|
+
*/
|
|
37
|
+
export declare function planDuplicatePrune(candidates: PruneCandidate[]): DuplicatePruneEntry[];
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
export function compareVersionLabels(a, b) {
|
|
2
|
+
const partsA = a.split('.').map(Number);
|
|
3
|
+
const partsB = b.split('.').map(Number);
|
|
4
|
+
for (let i = 0; i < 3; i++) {
|
|
5
|
+
if (partsA[i] > partsB[i])
|
|
6
|
+
return 1;
|
|
7
|
+
if (partsA[i] < partsB[i])
|
|
8
|
+
return -1;
|
|
9
|
+
}
|
|
10
|
+
return 0;
|
|
11
|
+
}
|
|
12
|
+
export function pruneGroupKey(info) {
|
|
13
|
+
return info.accountKey ?? info.email?.toLowerCase() ?? null;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* PURE duplicate-home detection: given every installed home for one agent, decide
|
|
17
|
+
* which are redundant duplicates of the SAME logical account and which single home
|
|
18
|
+
* to keep per account. Extracted from buildAgentPrunePlan so the keeper/merge rules
|
|
19
|
+
* are unit-tested without touching disk.
|
|
20
|
+
*
|
|
21
|
+
* Two rules, both conservative:
|
|
22
|
+
* - GROUPING. A home with a captured `accountKey` groups by it (account+org, so a
|
|
23
|
+
* personal Max and a Team seat on the same email stay separate). A home with NO
|
|
24
|
+
* accountKey folds into a same-email account ONLY when a sibling home for that
|
|
25
|
+
* email IS identified — that email-only home is an incompletely-captured re-login
|
|
26
|
+
* of the known account, not a distinct seat (PHNX-3887). Otherwise it groups by
|
|
27
|
+
* its bare email and only ever collapses against another equally-bare home.
|
|
28
|
+
* - KEEPER. Within a group the keeper is the home that best represents the account:
|
|
29
|
+
* captured identity first, then a signed-in credential, then the newest RUNNING
|
|
30
|
+
* release, then the highest dir label as a stable tiebreak. This is deliberately
|
|
31
|
+
* NOT "highest dir-name semver" — in the wild that is the freshly re-logged-in
|
|
32
|
+
* duplicate that never captured its identity or usage, and keeping it while
|
|
33
|
+
* trashing the identified home is the exact bug this replaces.
|
|
34
|
+
*/
|
|
35
|
+
export function planDuplicatePrune(candidates) {
|
|
36
|
+
const installed = candidates.filter((c) => c.hasBinary && c.email);
|
|
37
|
+
const emailToAccountKeys = new Map();
|
|
38
|
+
for (const c of installed) {
|
|
39
|
+
if (!c.accountKey)
|
|
40
|
+
continue;
|
|
41
|
+
const email = c.email.toLowerCase();
|
|
42
|
+
(emailToAccountKeys.get(email) ?? emailToAccountKeys.set(email, new Set()).get(email)).add(c.accountKey);
|
|
43
|
+
}
|
|
44
|
+
const groupKeyFor = (c) => {
|
|
45
|
+
if (c.accountKey)
|
|
46
|
+
return c.accountKey;
|
|
47
|
+
const email = c.email?.toLowerCase();
|
|
48
|
+
const keys = email ? emailToAccountKeys.get(email) : undefined;
|
|
49
|
+
if (keys && keys.size === 1)
|
|
50
|
+
return [...keys][0];
|
|
51
|
+
if (keys && keys.size >= 2)
|
|
52
|
+
return `ambiguous:${c.email.toLowerCase()}:${c.version}`;
|
|
53
|
+
return pruneGroupKey(c);
|
|
54
|
+
};
|
|
55
|
+
const byAccount = new Map();
|
|
56
|
+
for (const c of installed) {
|
|
57
|
+
const key = groupKeyFor(c);
|
|
58
|
+
if (!key)
|
|
59
|
+
continue;
|
|
60
|
+
(byAccount.get(key) ?? byAccount.set(key, []).get(key)).push(c);
|
|
61
|
+
}
|
|
62
|
+
const rank = (c) => [c.accountKey ? 1 : 0, c.signedIn ? 1 : 0];
|
|
63
|
+
const better = (a, b) => {
|
|
64
|
+
const [aa, ab] = rank(a);
|
|
65
|
+
const [ba, bb] = rank(b);
|
|
66
|
+
if (aa !== ba)
|
|
67
|
+
return ba - aa;
|
|
68
|
+
if (ab !== bb)
|
|
69
|
+
return bb - ab;
|
|
70
|
+
if (a.release !== b.release)
|
|
71
|
+
return compareVersionLabels(b.release, a.release);
|
|
72
|
+
return compareVersionLabels(b.version, a.version);
|
|
73
|
+
};
|
|
74
|
+
const out = [];
|
|
75
|
+
for (const group of byAccount.values()) {
|
|
76
|
+
if (group.length < 2)
|
|
77
|
+
continue;
|
|
78
|
+
const sorted = [...group].sort(better);
|
|
79
|
+
const keeper = sorted[0].version;
|
|
80
|
+
for (const dup of sorted.slice(1)) {
|
|
81
|
+
out.push({ version: dup.version, email: dup.email, keeper });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { getGitSyncStatus } from '../git.js';
|
|
2
|
+
import { type ProfileSummary } from '../profiles.js';
|
|
3
|
+
import type { AgentId } from '../types.js';
|
|
4
|
+
import type { ResourceSection, SyncState, ViewJsonAgent, ViewJsonRunReady } from '../view-types.js';
|
|
5
|
+
export declare function getHarnesses(): ProfileSummary[];
|
|
6
|
+
export type ResourceSyncType = 'commands' | 'skills' | 'hooks' | 'memory';
|
|
7
|
+
interface ResourceSyncData {
|
|
8
|
+
hasGitRepo: boolean;
|
|
9
|
+
commands: Awaited<ReturnType<typeof getGitSyncStatus>>;
|
|
10
|
+
skills: Awaited<ReturnType<typeof getGitSyncStatus>>;
|
|
11
|
+
hooks: Awaited<ReturnType<typeof getGitSyncStatus>>;
|
|
12
|
+
memory: Awaited<ReturnType<typeof getGitSyncStatus>>;
|
|
13
|
+
}
|
|
14
|
+
export declare function loadResourceSyncData(): Promise<ResourceSyncData>;
|
|
15
|
+
export declare function resolveResourceSyncState(agentId: AgentId, resourceName: string, resourceType: ResourceSyncType, syncStatus: Awaited<ReturnType<typeof getGitSyncStatus>>): SyncState | undefined;
|
|
16
|
+
export declare function computeAgentRunReady(agentId: AgentId): Promise<ViewJsonRunReady | undefined>;
|
|
17
|
+
export declare function collectAgentsJson(filterAgentId?: AgentId, resourceSections?: Set<ResourceSection>, opts?: {
|
|
18
|
+
forceRefresh?: boolean;
|
|
19
|
+
}): Promise<ViewJsonAgent[]>;
|
|
20
|
+
export {};
|