polyergon 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/.next/BUILD_ID +1 -0
- package/.next/app-build-manifest.json +35 -0
- package/.next/app-path-routes-manifest.json +1 -0
- package/.next/build-manifest.json +32 -0
- package/.next/export-marker.json +1 -0
- package/.next/images-manifest.json +1 -0
- package/.next/next-minimal-server.js.nft.json +1 -0
- package/.next/next-server.js.nft.json +1 -0
- package/.next/package.json +1 -0
- package/.next/prerender-manifest.json +1 -0
- package/.next/react-loadable-manifest.json +10 -0
- package/.next/required-server-files.json +1 -0
- package/.next/routes-manifest.json +1 -0
- package/.next/server/app/_not-found/page.js +1 -0
- package/.next/server/app/_not-found/page.js.nft.json +1 -0
- package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -0
- package/.next/server/app/_not-found.html +1 -0
- package/.next/server/app/_not-found.meta +6 -0
- package/.next/server/app/_not-found.rsc +9 -0
- package/.next/server/app/api/automations/existing/route.js +1 -0
- package/.next/server/app/api/automations/existing/route.js.nft.json +1 -0
- package/.next/server/app/api/backends/route.js +1 -0
- package/.next/server/app/api/backends/route.js.nft.json +1 -0
- package/.next/server/app/api/limits/route.js +1 -0
- package/.next/server/app/api/limits/route.js.nft.json +1 -0
- package/.next/server/app/api/meetings/[id]/route.js +1 -0
- package/.next/server/app/api/meetings/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/meetings/[id]/slack/route.js +3 -0
- package/.next/server/app/api/meetings/[id]/slack/route.js.nft.json +1 -0
- package/.next/server/app/api/meetings/library/route.js +1 -0
- package/.next/server/app/api/meetings/library/route.js.nft.json +1 -0
- package/.next/server/app/api/meetings/route.js +1 -0
- package/.next/server/app/api/meetings/route.js.nft.json +1 -0
- package/.next/server/app/api/models/route.js +1 -0
- package/.next/server/app/api/models/route.js.nft.json +1 -0
- package/.next/server/app/api/notes/route.js +1 -0
- package/.next/server/app/api/notes/route.js.nft.json +1 -0
- package/.next/server/app/api/orgs/[id]/route.js +1 -0
- package/.next/server/app/api/orgs/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/orgs/route.js +1 -0
- package/.next/server/app/api/orgs/route.js.nft.json +1 -0
- package/.next/server/app/api/prs/inbox/route.js +1 -0
- package/.next/server/app/api/prs/inbox/route.js.nft.json +1 -0
- package/.next/server/app/api/prs/refresh/route.js +1 -0
- package/.next/server/app/api/prs/refresh/route.js.nft.json +1 -0
- package/.next/server/app/api/prs/route.js +1 -0
- package/.next/server/app/api/prs/route.js.nft.json +1 -0
- package/.next/server/app/api/session-names/route.js +1 -0
- package/.next/server/app/api/session-names/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/[id]/route.js +1 -0
- package/.next/server/app/api/sessions/[id]/route.js.nft.json +1 -0
- package/.next/server/app/api/sessions/route.js +1 -0
- package/.next/server/app/api/sessions/route.js.nft.json +1 -0
- package/.next/server/app/api/settings/auth/route.js +1 -0
- package/.next/server/app/api/settings/auth/route.js.nft.json +1 -0
- package/.next/server/app/api/settings/route.js +1 -0
- package/.next/server/app/api/settings/route.js.nft.json +1 -0
- package/.next/server/app/api/settings/transcription/route.js +1 -0
- package/.next/server/app/api/settings/transcription/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/[name]/route.js +8 -0
- package/.next/server/app/api/skills/[name]/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/marketplace/route.js +2 -0
- package/.next/server/app/api/skills/marketplace/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/route.js +8 -0
- package/.next/server/app/api/skills/route.js.nft.json +1 -0
- package/.next/server/app/api/skills/view/route.js +8 -0
- package/.next/server/app/api/skills/view/route.js.nft.json +1 -0
- package/.next/server/app/api/slack/channels/route.js +1 -0
- package/.next/server/app/api/slack/channels/route.js.nft.json +1 -0
- package/.next/server/app/api/slack/configured/route.js +1 -0
- package/.next/server/app/api/slack/configured/route.js.nft.json +1 -0
- package/.next/server/app/api/slack/inbox/route.js +1 -0
- package/.next/server/app/api/slack/inbox/route.js.nft.json +1 -0
- package/.next/server/app/api/usage/route.js +1 -0
- package/.next/server/app/api/usage/route.js.nft.json +1 -0
- package/.next/server/app/demo/page.js +1 -0
- package/.next/server/app/demo/page.js.nft.json +1 -0
- package/.next/server/app/demo/page_client-reference-manifest.js +1 -0
- package/.next/server/app/demo.html +1 -0
- package/.next/server/app/demo.meta +6 -0
- package/.next/server/app/demo.rsc +7 -0
- package/.next/server/app/favicon.ico/route.js +12 -0
- package/.next/server/app/favicon.ico/route.js.nft.json +1 -0
- package/.next/server/app/favicon.ico.body +0 -0
- package/.next/server/app/favicon.ico.meta +1 -0
- package/.next/server/app/index.html +1 -0
- package/.next/server/app/index.meta +5 -0
- package/.next/server/app/index.rsc +7 -0
- package/.next/server/app/page.js +1 -0
- package/.next/server/app/page.js.nft.json +1 -0
- package/.next/server/app/page_client-reference-manifest.js +1 -0
- package/.next/server/app-paths-manifest.json +34 -0
- package/.next/server/chunks/348.js +1 -0
- package/.next/server/chunks/471.js +2 -0
- package/.next/server/chunks/590.js +7 -0
- package/.next/server/chunks/621.js +1 -0
- package/.next/server/chunks/682.js +6 -0
- package/.next/server/chunks/904.js +1 -0
- package/.next/server/chunks/948.js +2 -0
- package/.next/server/chunks/972.js +12 -0
- package/.next/server/chunks/font-manifest.json +1 -0
- package/.next/server/font-manifest.json +1 -0
- package/.next/server/functions-config-manifest.json +1 -0
- package/.next/server/interception-route-rewrite-manifest.js +1 -0
- package/.next/server/middleware-build-manifest.js +1 -0
- package/.next/server/middleware-manifest.json +6 -0
- package/.next/server/middleware-react-loadable-manifest.js +1 -0
- package/.next/server/next-font-manifest.js +1 -0
- package/.next/server/next-font-manifest.json +1 -0
- package/.next/server/pages/404.html +1 -0
- package/.next/server/pages/500.html +1 -0
- package/.next/server/pages/_app.js +1 -0
- package/.next/server/pages/_app.js.nft.json +1 -0
- package/.next/server/pages/_document.js +1 -0
- package/.next/server/pages/_document.js.nft.json +1 -0
- package/.next/server/pages/_error.js +1 -0
- package/.next/server/pages/_error.js.nft.json +1 -0
- package/.next/server/pages-manifest.json +1 -0
- package/.next/server/server-reference-manifest.js +1 -0
- package/.next/server/server-reference-manifest.json +1 -0
- package/.next/server/webpack-runtime.js +1 -0
- package/.next/static/chunks/117-0f4ac3c2c1871d4c.js +2 -0
- package/.next/static/chunks/171-f72ed164561ba218.js +1 -0
- package/.next/static/chunks/235.aef4cdc783360b73.js +1 -0
- package/.next/static/chunks/30d07d85.9045c666bb43d9e1.js +3 -0
- package/.next/static/chunks/app/_not-found/page-8ff6572bc7c9bc61.js +1 -0
- package/.next/static/chunks/app/demo/page-6711b34cd2af0e4a.js +1 -0
- package/.next/static/chunks/app/layout-d058836232e72324.js +1 -0
- package/.next/static/chunks/app/page-cebeba7d6d08548a.js +1 -0
- package/.next/static/chunks/fd9d1056-26bd8d656b496dba.js +1 -0
- package/.next/static/chunks/framework-f66176bb897dc684.js +1 -0
- package/.next/static/chunks/main-960df1c7509a5a8b.js +1 -0
- package/.next/static/chunks/main-app-4b855ea14675b961.js +1 -0
- package/.next/static/chunks/pages/_app-72b849fbd24ac258.js +1 -0
- package/.next/static/chunks/pages/_error-7ba65e1336b92748.js +1 -0
- package/.next/static/chunks/polyfills-42372ed130431b0a.js +1 -0
- package/.next/static/chunks/webpack-1f89b7cb1fca69c4.js +1 -0
- package/.next/static/css/a537d3e86c0f36d2.css +3 -0
- package/.next/static/css/ab3e4b0f5035257a.css +1 -0
- package/.next/static/q-HMeHYZY36qljBJhsyS6/_buildManifest.js +1 -0
- package/.next/static/q-HMeHYZY36qljBJhsyS6/_ssgManifest.js +1 -0
- package/.next/trace +22 -0
- package/.next/types/app/api/automations/existing/route.ts +343 -0
- package/.next/types/app/api/backends/route.ts +343 -0
- package/.next/types/app/api/limits/route.ts +343 -0
- package/.next/types/app/api/meetings/[id]/route.ts +343 -0
- package/.next/types/app/api/meetings/[id]/slack/route.ts +343 -0
- package/.next/types/app/api/meetings/library/route.ts +343 -0
- package/.next/types/app/api/meetings/route.ts +343 -0
- package/.next/types/app/api/models/route.ts +343 -0
- package/.next/types/app/api/notes/route.ts +343 -0
- package/.next/types/app/api/orgs/[id]/route.ts +343 -0
- package/.next/types/app/api/orgs/route.ts +343 -0
- package/.next/types/app/api/prs/inbox/route.ts +343 -0
- package/.next/types/app/api/prs/refresh/route.ts +343 -0
- package/.next/types/app/api/prs/route.ts +343 -0
- package/.next/types/app/api/session-names/route.ts +343 -0
- package/.next/types/app/api/sessions/[id]/route.ts +343 -0
- package/.next/types/app/api/sessions/route.ts +343 -0
- package/.next/types/app/api/settings/auth/route.ts +343 -0
- package/.next/types/app/api/settings/route.ts +343 -0
- package/.next/types/app/api/settings/transcription/route.ts +343 -0
- package/.next/types/app/api/skills/[name]/route.ts +343 -0
- package/.next/types/app/api/skills/marketplace/route.ts +343 -0
- package/.next/types/app/api/skills/route.ts +343 -0
- package/.next/types/app/api/skills/view/route.ts +343 -0
- package/.next/types/app/api/slack/channels/route.ts +343 -0
- package/.next/types/app/api/slack/configured/route.ts +343 -0
- package/.next/types/app/api/slack/inbox/route.ts +343 -0
- package/.next/types/app/api/usage/route.ts +343 -0
- package/.next/types/app/demo/page.ts +79 -0
- package/.next/types/app/layout.ts +79 -0
- package/.next/types/app/page.ts +79 -0
- package/.next/types/package.json +1 -0
- package/.server-dist/server.js +554 -0
- package/.server-dist/src/lib/activeOrg.js +11 -0
- package/.server-dist/src/lib/audioCapture.js +157 -0
- package/.server-dist/src/lib/backends.js +111 -0
- package/.server-dist/src/lib/claudeAuth.js +57 -0
- package/.server-dist/src/lib/configFile.js +23 -0
- package/.server-dist/src/lib/dataDir.js +7 -0
- package/.server-dist/src/lib/existingAutomations.js +132 -0
- package/.server-dist/src/lib/ghInbox.js +151 -0
- package/.server-dist/src/lib/ghPrStatus.js +86 -0
- package/.server-dist/src/lib/gitUtils.js +27 -0
- package/.server-dist/src/lib/keepAwake.js +32 -0
- package/.server-dist/src/lib/liveSessionStore.js +89 -0
- package/.server-dist/src/lib/marketplace.js +63 -0
- package/.server-dist/src/lib/meetingAssistant.js +138 -0
- package/.server-dist/src/lib/meetingConfig.js +81 -0
- package/.server-dist/src/lib/meetingContext.js +82 -0
- package/.server-dist/src/lib/meetingManager.js +246 -0
- package/.server-dist/src/lib/meetingStore.js +198 -0
- package/.server-dist/src/lib/modelCatalog.js +107 -0
- package/.server-dist/src/lib/notesStore.js +67 -0
- package/.server-dist/src/lib/orgFilter.js +19 -0
- package/.server-dist/src/lib/orgParam.js +15 -0
- package/.server-dist/src/lib/orgRegistry.js +93 -0
- package/.server-dist/src/lib/pipelineView.js +62 -0
- package/.server-dist/src/lib/pipelines.js +401 -0
- package/.server-dist/src/lib/planLimits.js +101 -0
- package/.server-dist/src/lib/prDetector.js +16 -0
- package/.server-dist/src/lib/prScanCache.js +144 -0
- package/.server-dist/src/lib/prSessionEntries.js +96 -0
- package/.server-dist/src/lib/prTypes.js +2 -0
- package/.server-dist/src/lib/ptyManager.js +428 -0
- package/.server-dist/src/lib/reminders.js +10 -0
- package/.server-dist/src/lib/requestGuard.js +29 -0
- package/.server-dist/src/lib/sessionNameStore.js +69 -0
- package/.server-dist/src/lib/sessionStore.js +215 -0
- package/.server-dist/src/lib/settingsStore.js +51 -0
- package/.server-dist/src/lib/skillsReader.js +200 -0
- package/.server-dist/src/lib/slackBridge.js +270 -0
- package/.server-dist/src/lib/slackInbox.js +96 -0
- package/.server-dist/src/lib/slackWatchers.js +210 -0
- package/.server-dist/src/lib/statusDetector.js +46 -0
- package/.server-dist/src/lib/transcriber.js +61 -0
- package/.server-dist/src/lib/usageStore.js +254 -0
- package/.server-dist/tsconfig.server.tsbuildinfo +1 -0
- package/LICENSE +21 -0
- package/README.md +99 -2
- package/bin/polyergon.js +34 -0
- package/next.config.mjs +4 -0
- package/package.json +81 -4
- package/public/.gitkeep +0 -0
- package/public/apple-touch-icon.png +0 -0
- package/public/icon-192.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/icon.svg +1 -0
- package/public/manifest.webmanifest +15 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.orgRegistry = exports.OrgRegistry = exports.DEFAULT_ORG_ID = void 0;
|
|
5
|
+
const dataDir_1 = require("./dataDir");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const crypto_1 = require("crypto");
|
|
9
|
+
exports.DEFAULT_ORG_ID = 'default';
|
|
10
|
+
const DEFAULT_PERSIST_DIR = dataDir_1.DATA_DIR;
|
|
11
|
+
const DEFAULT_PERSIST_FILE = (0, path_1.join)(DEFAULT_PERSIST_DIR, 'orgs.json');
|
|
12
|
+
class OrgRegistry {
|
|
13
|
+
// persistFile defaults to the real on-disk location; tests must pass an
|
|
14
|
+
// isolated path so they never touch the user's actual session state.
|
|
15
|
+
constructor(persistFile = DEFAULT_PERSIST_FILE) {
|
|
16
|
+
this.orgs = new Map();
|
|
17
|
+
this.persistFile = persistFile;
|
|
18
|
+
this.persistDir = (0, path_1.join)(persistFile, '..');
|
|
19
|
+
this.load();
|
|
20
|
+
}
|
|
21
|
+
// Re-read on every access: the custom server and Next's API routes hold
|
|
22
|
+
// separate module copies, so an edit made through the API must reach both.
|
|
23
|
+
load() {
|
|
24
|
+
try {
|
|
25
|
+
const saved = JSON.parse((0, fs_1.readFileSync)(this.persistFile, 'utf-8'));
|
|
26
|
+
this.orgs = new Map(saved.map(org => [org.id, org]));
|
|
27
|
+
}
|
|
28
|
+
catch (_a) { }
|
|
29
|
+
if (!this.orgs.has(exports.DEFAULT_ORG_ID)) {
|
|
30
|
+
this.orgs.set(exports.DEFAULT_ORG_ID, { id: exports.DEFAULT_ORG_ID, name: 'Default', configDir: null });
|
|
31
|
+
this.persist();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
list() {
|
|
35
|
+
this.load();
|
|
36
|
+
return Array.from(this.orgs.values());
|
|
37
|
+
}
|
|
38
|
+
// Every org's `<configDir>/projects` root, deduped (two orgs pointing at the
|
|
39
|
+
// same dir — e.g. a misconfigured entry — must not double-list sessions).
|
|
40
|
+
projectRoots() {
|
|
41
|
+
var _a;
|
|
42
|
+
const seen = new Set();
|
|
43
|
+
const roots = [];
|
|
44
|
+
for (const org of this.list()) {
|
|
45
|
+
const root = (0, path_1.join)((_a = org.configDir) !== null && _a !== void 0 ? _a : (0, path_1.join)(process.env.HOME, '.claude'), 'projects');
|
|
46
|
+
if (seen.has(root))
|
|
47
|
+
continue;
|
|
48
|
+
seen.add(root);
|
|
49
|
+
roots.push({ orgId: org.id, root });
|
|
50
|
+
}
|
|
51
|
+
return roots;
|
|
52
|
+
}
|
|
53
|
+
get(id) {
|
|
54
|
+
this.load();
|
|
55
|
+
return this.orgs.get(id);
|
|
56
|
+
}
|
|
57
|
+
add(name, configDir, model) {
|
|
58
|
+
this.load();
|
|
59
|
+
const org = { id: (0, crypto_1.randomUUID)(), name, configDir, model: model !== null && model !== void 0 ? model : null };
|
|
60
|
+
this.orgs.set(org.id, org);
|
|
61
|
+
this.persist();
|
|
62
|
+
return org;
|
|
63
|
+
}
|
|
64
|
+
update(id, patch) {
|
|
65
|
+
const org = this.get(id);
|
|
66
|
+
if (!org)
|
|
67
|
+
return undefined;
|
|
68
|
+
const next = Object.assign(Object.assign(Object.assign({}, org), patch), { id });
|
|
69
|
+
if (id === exports.DEFAULT_ORG_ID)
|
|
70
|
+
next.configDir = org.configDir; // Default keeps the CLI's own folder
|
|
71
|
+
this.orgs.set(id, next);
|
|
72
|
+
this.persist();
|
|
73
|
+
return next;
|
|
74
|
+
}
|
|
75
|
+
// Sessions and meetings of a removed org keep their orgId; the UI shows them under All.
|
|
76
|
+
remove(id) {
|
|
77
|
+
if (id === exports.DEFAULT_ORG_ID || !this.get(id))
|
|
78
|
+
return false;
|
|
79
|
+
this.orgs.delete(id);
|
|
80
|
+
this.persist();
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
persist() {
|
|
84
|
+
try {
|
|
85
|
+
if (!(0, fs_1.existsSync)(this.persistDir))
|
|
86
|
+
(0, fs_1.mkdirSync)(this.persistDir, { recursive: true });
|
|
87
|
+
(0, fs_1.writeFileSync)(this.persistFile, JSON.stringify(Array.from(this.orgs.values())));
|
|
88
|
+
}
|
|
89
|
+
catch (_a) { }
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.OrgRegistry = OrgRegistry;
|
|
93
|
+
exports.orgRegistry = (_a = global.__orgRegistry) !== null && _a !== void 0 ? _a : (global.__orgRegistry = new OrgRegistry());
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.shortPr = exports.isRunning = exports.ACTIVE_PHASES = exports.DEFAULT_AUTO = void 0;
|
|
4
|
+
exports.pipelineSummary = pipelineSummary;
|
|
5
|
+
exports.prSteps = prSteps;
|
|
6
|
+
exports.preprSteps = preprSteps;
|
|
7
|
+
exports.DEFAULT_AUTO = { openPr: true, review: true, ci: true, merge: false };
|
|
8
|
+
exports.ACTIVE_PHASES = ['waiting-for-session', 'opening-pr', 'tracking'];
|
|
9
|
+
const isRunning = (p) => !!p && exports.ACTIVE_PHASES.includes(p.phase);
|
|
10
|
+
exports.isRunning = isRunning;
|
|
11
|
+
const shortPr = (url) => url.replace(/^https:\/\/github\.com\//, '').replace('/pull/', '#');
|
|
12
|
+
exports.shortPr = shortPr;
|
|
13
|
+
// Short card label, e.g. "2 PRs · 1 ready · 1 in review"
|
|
14
|
+
function pipelineSummary(p) {
|
|
15
|
+
const waiting = (p.suggestion ? 1 : 0) + p.prs.filter(t => t.suggestion).length;
|
|
16
|
+
const prefix = waiting ? `${waiting} suggestion${waiting > 1 ? 's' : ''} for you · ` : '';
|
|
17
|
+
return prefix + summaryBody(p);
|
|
18
|
+
}
|
|
19
|
+
function summaryBody(p) {
|
|
20
|
+
if (p.phase === 'waiting-for-session')
|
|
21
|
+
return 'watching for a PR';
|
|
22
|
+
if (p.phase === 'opening-pr')
|
|
23
|
+
return 'session is opening a PR';
|
|
24
|
+
if (p.phase === 'stopped')
|
|
25
|
+
return 'stopped';
|
|
26
|
+
if (p.phase === 'needs-you' && !p.prs.length)
|
|
27
|
+
return 'needs you';
|
|
28
|
+
if (p.phase === 'done')
|
|
29
|
+
return p.prs.length > 1 ? `${p.prs.length} PRs done` : 'done';
|
|
30
|
+
const open = p.prs.filter(t => t.state !== 'done');
|
|
31
|
+
const count = (s) => open.filter(t => t.state === s).length;
|
|
32
|
+
const parts = [
|
|
33
|
+
count('needs-you') && `${count('needs-you')} needs you`,
|
|
34
|
+
count('working') && 'fixing',
|
|
35
|
+
count('ready') && `${count('ready')} ready`,
|
|
36
|
+
count('in-review') && `${count('in-review')} in review`,
|
|
37
|
+
].filter(Boolean);
|
|
38
|
+
return `${p.prs.length > 1 ? `${p.prs.length} PRs · ` : ''}${parts.join(' · ') || 'in review'}`;
|
|
39
|
+
}
|
|
40
|
+
// PR → Slack → Review → Approved → Merged, as done/current flags for one PR
|
|
41
|
+
function prSteps(t, slack) {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const merged = ((_a = t.view) === null || _a === void 0 ? void 0 : _a.state) === 'MERGED';
|
|
44
|
+
const approved = merged || ((_b = t.view) === null || _b === void 0 ? void 0 : _b.reviewDecision) === 'APPROVED' || t.state === 'ready';
|
|
45
|
+
return [
|
|
46
|
+
{ label: 'PR opened', done: true, current: false },
|
|
47
|
+
...(slack ? [{ label: 'Posted to Slack', done: !!t.slack, current: !t.slack }] : []),
|
|
48
|
+
{ label: 'In review', done: approved, current: !approved },
|
|
49
|
+
{ label: 'Approved', done: approved, current: false },
|
|
50
|
+
{ label: 'Merged', done: merged, current: approved && !merged },
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
// Before any PR exists: Watching → PR → Review → Approved → Merged
|
|
54
|
+
function preprSteps(p) {
|
|
55
|
+
return [
|
|
56
|
+
{ label: p.phase === 'opening-pr' ? 'Session is opening a PR' : p.suggestion ? 'Waiting for you to open a PR' : 'Watching for code to ship', done: false, current: true },
|
|
57
|
+
{ label: 'PR opened', done: false, current: false },
|
|
58
|
+
{ label: 'In review', done: false, current: false },
|
|
59
|
+
{ label: 'Approved', done: false, current: false },
|
|
60
|
+
{ label: 'Merged', done: false, current: false },
|
|
61
|
+
];
|
|
62
|
+
}
|
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _a;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.pipelineEngine = exports.autoOf = exports.DEFAULT_AUTO = void 0;
|
|
5
|
+
exports.hasWorkToShip = hasWorkToShip;
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const util_1 = require("util");
|
|
10
|
+
const crypto_1 = require("crypto");
|
|
11
|
+
const dataDir_1 = require("./dataDir");
|
|
12
|
+
const liveSessionStore_1 = require("./liveSessionStore");
|
|
13
|
+
const ptyManager_1 = require("./ptyManager");
|
|
14
|
+
const ghPrStatus_1 = require("./ghPrStatus");
|
|
15
|
+
const slackBridge_1 = require("./slackBridge");
|
|
16
|
+
const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
|
|
17
|
+
// Is there code to turn into a PR? A git repo with uncommitted changes, commits
|
|
18
|
+
// not pushed, or a branch that was never pushed (other than main/master).
|
|
19
|
+
async function hasWorkToShip(cwd) {
|
|
20
|
+
const git = (...args) => execFileAsync('git', ['-C', cwd, ...args], { timeout: 10000 }).then(r => r.stdout.trim());
|
|
21
|
+
try {
|
|
22
|
+
if (await git('status', '--porcelain'))
|
|
23
|
+
return true;
|
|
24
|
+
const ahead = await git('rev-list', '--count', '@{u}..HEAD').catch(() => null);
|
|
25
|
+
if (ahead !== null)
|
|
26
|
+
return Number(ahead) > 0;
|
|
27
|
+
const branch = await git('rev-parse', '--abbrev-ref', 'HEAD');
|
|
28
|
+
return !['main', 'master', 'HEAD'].includes(branch);
|
|
29
|
+
}
|
|
30
|
+
catch (_a) {
|
|
31
|
+
return false;
|
|
32
|
+
} // not a git repo
|
|
33
|
+
}
|
|
34
|
+
const pipelineView_1 = require("./pipelineView");
|
|
35
|
+
Object.defineProperty(exports, "DEFAULT_AUTO", { enumerable: true, get: function () { return pipelineView_1.DEFAULT_AUTO; } });
|
|
36
|
+
const FILE = (0, path_1.join)(dataDir_1.DATA_DIR, 'pipelines.json');
|
|
37
|
+
const POLL_MS = 2 * 60000;
|
|
38
|
+
const SETTLE_MS = 20000; // a session must be quiet this long after we sent it work
|
|
39
|
+
const SLACK_CHECK_MS = 10 * 60000;
|
|
40
|
+
const QUIET_MS = 15000; // session must stay 'waiting' this long before we type into it
|
|
41
|
+
const pipelineView_2 = require("./pipelineView");
|
|
42
|
+
const OPEN_TRACK = ['in-review', 'working', 'ready'];
|
|
43
|
+
const STEP_NAME = { openPr: 'open the PR', review: 'fix review comments', ci: 'fix CI', merge: 'merge' };
|
|
44
|
+
const autoOf = (p) => (Object.assign(Object.assign({}, pipelineView_1.DEFAULT_AUTO), p.config.auto));
|
|
45
|
+
exports.autoOf = autoOf;
|
|
46
|
+
const cleanAuto = (a) => {
|
|
47
|
+
const m = Object.assign(Object.assign({}, pipelineView_1.DEFAULT_AUTO), a);
|
|
48
|
+
return { openPr: m.openPr === true, review: m.review === true, ci: m.ci === true, merge: m.merge === true };
|
|
49
|
+
};
|
|
50
|
+
const PROMPTS = {
|
|
51
|
+
openPr: 'Your work looks finished. Commit it, push the branch, and open a pull request with a clear title and description. Print the PR URL when done.',
|
|
52
|
+
review: (url) => `There is new review feedback on ${url}. Read it with gh (reviews and comments), address each point, push the fixes, and reply on the PR to say what changed.`,
|
|
53
|
+
ci: (url) => `CI is failing on ${url}. Find the failing checks with gh, fix the cause, and push.`,
|
|
54
|
+
merge: (url) => `${url} is approved and CI is green. Merge it with gh pr merge, using the merge method this repo uses, and delete the branch. Print the result.`,
|
|
55
|
+
};
|
|
56
|
+
const pipelineView_3 = require("./pipelineView");
|
|
57
|
+
async function prSnapshot(url) {
|
|
58
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
59
|
+
try {
|
|
60
|
+
const env = Object.assign({}, process.env);
|
|
61
|
+
delete env.GITHUB_TOKEN;
|
|
62
|
+
delete env.GH_TOKEN;
|
|
63
|
+
const { stdout } = await execFileAsync('gh', ['pr', 'view', url, '--json', 'number,state,isDraft,reviewDecision,statusCheckRollup,author,reviews,latestReviews,reviewRequests,comments,title'], { timeout: 15000, env });
|
|
64
|
+
const j = JSON.parse(stdout);
|
|
65
|
+
const author = (_a = j.author) === null || _a === void 0 ? void 0 : _a.login;
|
|
66
|
+
const others = (xs = []) => xs.filter(x => { var _a; return ((_a = x.author) === null || _a === void 0 ? void 0 : _a.login) && x.author.login !== author; }).length;
|
|
67
|
+
const checks = (0, ghPrStatus_1.summarizeChecks)((_b = j.statusCheckRollup) !== null && _b !== void 0 ? _b : []);
|
|
68
|
+
const reviews = ((_c = j.latestReviews) !== null && _c !== void 0 ? _c : [])
|
|
69
|
+
.filter((r) => { var _a; return ((_a = r.author) === null || _a === void 0 ? void 0 : _a.login) && r.author.login !== author; })
|
|
70
|
+
.map((r) => { var _a; return ({ login: r.author.login, state: r.state, at: (_a = r.submittedAt) !== null && _a !== void 0 ? _a : null }); });
|
|
71
|
+
const reviewed = new Set(reviews.map((r) => r.login));
|
|
72
|
+
const requested = ((_d = j.reviewRequests) !== null && _d !== void 0 ? _d : []).map((r) => { var _a, _b, _c; return (_c = (_b = (_a = r.login) !== null && _a !== void 0 ? _a : r.name) !== null && _b !== void 0 ? _b : r.slug) !== null && _c !== void 0 ? _c : ''; }).filter((x) => x && !reviewed.has(x));
|
|
73
|
+
const view = { number: j.number, title: (_e = j.title) !== null && _e !== void 0 ? _e : '', state: j.state, isDraft: !!j.isDraft, reviewDecision: (_f = j.reviewDecision) !== null && _f !== void 0 ? _f : null, checks, requested, reviews, fetchedAt: Date.now() };
|
|
74
|
+
return { state: j.state, reviewDecision: (_g = j.reviewDecision) !== null && _g !== void 0 ? _g : null, checks, feedback: others(j.reviews) + others(j.comments), title: (_h = j.title) !== null && _h !== void 0 ? _h : '', view };
|
|
75
|
+
}
|
|
76
|
+
catch (_j) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
class PipelineEngine {
|
|
81
|
+
constructor() {
|
|
82
|
+
this.items = [];
|
|
83
|
+
this.listeners = new Set();
|
|
84
|
+
this.busy = new Set();
|
|
85
|
+
this.started = false;
|
|
86
|
+
this.quietSince = new Map(); // liveId → when it last became 'waiting'
|
|
87
|
+
}
|
|
88
|
+
start() {
|
|
89
|
+
if (this.started)
|
|
90
|
+
return;
|
|
91
|
+
this.started = true;
|
|
92
|
+
try {
|
|
93
|
+
this.items = JSON.parse((0, fs_1.readFileSync)(FILE, 'utf-8')).filter((p) => Array.isArray(p.prs));
|
|
94
|
+
}
|
|
95
|
+
catch (_a) {
|
|
96
|
+
this.items = [];
|
|
97
|
+
}
|
|
98
|
+
(0, ptyManager_1.onAnyStatusChange)((id, status) => {
|
|
99
|
+
if (status === 'waiting') {
|
|
100
|
+
if (!this.quietSince.has(id))
|
|
101
|
+
this.quietSince.set(id, Date.now());
|
|
102
|
+
}
|
|
103
|
+
else
|
|
104
|
+
this.quietSince.delete(id);
|
|
105
|
+
// You picked the session back up after it stopped on "needs you": resume watching
|
|
106
|
+
if (status === 'thinking') {
|
|
107
|
+
this.items.filter(p => p.liveId === id && p.phase === 'needs-you').forEach(p => this.update(p, { phase: p.prs.length ? 'tracking' : 'waiting-for-session', actedAt: Date.now() }, 'Session is working again; waiting for it to finish'));
|
|
108
|
+
}
|
|
109
|
+
this.forSession(id, p => this.step(p.id));
|
|
110
|
+
// re-check once the quiet period has passed
|
|
111
|
+
if (status === 'waiting')
|
|
112
|
+
setTimeout(() => this.forSession(id, p => this.step(p.id)), QUIET_MS + 1000);
|
|
113
|
+
});
|
|
114
|
+
(0, ptyManager_1.onAnyPrUrlChange)(id => this.forSession(id, p => this.step(p.id)));
|
|
115
|
+
setInterval(() => this.items.filter(p => pipelineView_2.ACTIVE_PHASES.includes(p.phase)).forEach(p => this.step(p.id, true)), POLL_MS);
|
|
116
|
+
this.items.filter(p => pipelineView_2.ACTIVE_PHASES.includes(p.phase)).forEach(p => this.step(p.id, true));
|
|
117
|
+
}
|
|
118
|
+
forSession(liveId, fn) {
|
|
119
|
+
this.items.filter(p => p.liveId === liveId && pipelineView_2.ACTIVE_PHASES.includes(p.phase)).forEach(fn);
|
|
120
|
+
}
|
|
121
|
+
on(fn) { this.listeners.add(fn); return () => { this.listeners.delete(fn); }; }
|
|
122
|
+
list() { return this.items; }
|
|
123
|
+
save(notify) {
|
|
124
|
+
(0, fs_1.mkdirSync)(dataDir_1.DATA_DIR, { recursive: true });
|
|
125
|
+
(0, fs_1.writeFileSync)(FILE, JSON.stringify(this.items, null, 2));
|
|
126
|
+
this.listeners.forEach(fn => fn({ type: 'pipelines', items: this.items, notify }));
|
|
127
|
+
}
|
|
128
|
+
update(p, patch, logText, notify) {
|
|
129
|
+
Object.assign(p, patch, { updatedAt: Date.now() });
|
|
130
|
+
if (logText)
|
|
131
|
+
p.log = [...p.log, { t: Date.now(), text: logText }].slice(-80);
|
|
132
|
+
this.save(notify);
|
|
133
|
+
}
|
|
134
|
+
patchTrack(p, t, patch, logText, notify) {
|
|
135
|
+
Object.assign(t, patch);
|
|
136
|
+
this.update(p, {}, logText, notify);
|
|
137
|
+
}
|
|
138
|
+
create(liveId, config) {
|
|
139
|
+
const s = liveSessionStore_1.liveSessionStore.get(liveId);
|
|
140
|
+
if (!s)
|
|
141
|
+
return { error: 'Session not found' };
|
|
142
|
+
if (s.backend === 'copilot')
|
|
143
|
+
return { error: 'Automations support Claude sessions only for now' };
|
|
144
|
+
if (this.items.some(p => p.liveId === liveId && pipelineView_2.ACTIVE_PHASES.includes(p.phase)))
|
|
145
|
+
return { error: 'This session already has a running automation' };
|
|
146
|
+
const p = {
|
|
147
|
+
id: (0, crypto_1.randomUUID)(), liveId, template: 'ship-it',
|
|
148
|
+
config: { slackChannel: config.slackChannel, maxRounds: Math.min(10, Math.max(1, Math.round(config.maxRounds) || 3)), auto: cleanAuto(config.auto) },
|
|
149
|
+
phase: 'waiting-for-session', prs: [], workingOn: null, actedAt: 0,
|
|
150
|
+
log: [{ t: Date.now(), text: 'Started' }],
|
|
151
|
+
createdAt: Date.now(), updatedAt: Date.now(),
|
|
152
|
+
};
|
|
153
|
+
this.items = [...this.items.filter(x => x.liveId !== liveId || pipelineView_2.ACTIVE_PHASES.includes(x.phase)).slice(-50), p];
|
|
154
|
+
if (s.prUrl)
|
|
155
|
+
this.addTrack(p, s.prUrl, 'Found existing PR');
|
|
156
|
+
this.save();
|
|
157
|
+
this.step(p.id, true);
|
|
158
|
+
return p;
|
|
159
|
+
}
|
|
160
|
+
// Track another PR on a running automation (from the dialog).
|
|
161
|
+
addPr(id, url) {
|
|
162
|
+
const p = this.items.find(x => x.id === id);
|
|
163
|
+
if (!p || !pipelineView_2.ACTIVE_PHASES.includes(p.phase))
|
|
164
|
+
return { error: 'Automation is not running' };
|
|
165
|
+
if (!(0, ghPrStatus_1.isValidPrUrl)(url))
|
|
166
|
+
return { error: 'Not a GitHub pull request URL' };
|
|
167
|
+
this.addTrack(p, url, 'You added');
|
|
168
|
+
this.step(p.id, true);
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
addTrack(p, url, why) {
|
|
172
|
+
if (p.prs.some(t => t.url === url))
|
|
173
|
+
return;
|
|
174
|
+
const t = { url, state: 'in-review', seenFeedback: -1, reviewRounds: 0, ciFixes: 0 };
|
|
175
|
+
p.prs = [...p.prs, t];
|
|
176
|
+
p.phase = 'tracking';
|
|
177
|
+
this.update(p, {}, `${why} ${(0, pipelineView_3.shortPr)(url)}`);
|
|
178
|
+
this.announce(p, t);
|
|
179
|
+
}
|
|
180
|
+
// You clicked "Send to session" on a suggestion (prUrl = which PR's; none = open-PR)
|
|
181
|
+
act(id, prUrl) {
|
|
182
|
+
var _a;
|
|
183
|
+
const p = this.items.find(x => x.id === id);
|
|
184
|
+
if (!p)
|
|
185
|
+
return { error: 'Automation not found' };
|
|
186
|
+
const t = prUrl ? p.prs.find(x => x.url === prUrl) : null;
|
|
187
|
+
const sug = prUrl ? t === null || t === void 0 ? void 0 : t.suggestion : p.suggestion;
|
|
188
|
+
if (!sug)
|
|
189
|
+
return { error: 'Nothing to send' };
|
|
190
|
+
(0, ptyManager_1.submitLine)(p.liveId, sug.text);
|
|
191
|
+
if (t) {
|
|
192
|
+
if (sug.kind === 'review')
|
|
193
|
+
t.reviewRounds++;
|
|
194
|
+
if (sug.kind === 'ci')
|
|
195
|
+
t.ciFixes++;
|
|
196
|
+
if (sug.kind === 'merge')
|
|
197
|
+
t.mergeAttempts = ((_a = t.mergeAttempts) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
198
|
+
this.patchTrack(p, t, { suggestion: null, state: 'working' });
|
|
199
|
+
this.update(p, { workingOn: t.url, actedAt: Date.now() }, `Sent the session: ${sug.kind === 'review' ? 'address review feedback' : sug.kind === 'merge' ? 'merge' : 'fix CI'} on ${(0, pipelineView_3.shortPr)(t.url)}`);
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
this.update(p, { suggestion: null, phase: 'opening-pr', actedAt: Date.now() }, 'You sent the session: open a PR');
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
// Change which steps are automatic while it runs
|
|
207
|
+
setAuto(id, auto) {
|
|
208
|
+
const p = this.items.find(x => x.id === id);
|
|
209
|
+
if (!p)
|
|
210
|
+
return;
|
|
211
|
+
const next = cleanAuto(Object.assign(Object.assign({}, (0, exports.autoOf)(p)), auto));
|
|
212
|
+
const on = Object.keys(next).filter(k => next[k]);
|
|
213
|
+
this.update(p, { config: Object.assign(Object.assign({}, p.config), { auto: next }) }, `Automatic steps: ${on.length ? on.map(k => STEP_NAME[k]).join(', ') : 'none (everything asks you)'}`);
|
|
214
|
+
this.step(p.id);
|
|
215
|
+
}
|
|
216
|
+
dismiss(id, prUrl) {
|
|
217
|
+
const p = this.items.find(x => x.id === id);
|
|
218
|
+
if (!p)
|
|
219
|
+
return;
|
|
220
|
+
const t = prUrl ? p.prs.find(x => x.url === prUrl) : null;
|
|
221
|
+
if (t)
|
|
222
|
+
this.patchTrack(p, t, { suggestion: null }, `Dismissed suggestion on ${(0, pipelineView_3.shortPr)(t.url)}`);
|
|
223
|
+
else
|
|
224
|
+
this.update(p, { suggestion: null }, 'Dismissed the open-PR suggestion');
|
|
225
|
+
}
|
|
226
|
+
stop(id) {
|
|
227
|
+
const p = this.items.find(x => x.id === id);
|
|
228
|
+
if (p && pipelineView_2.ACTIVE_PHASES.includes(p.phase))
|
|
229
|
+
this.update(p, { phase: 'stopped', workingOn: null }, 'Stopped by you');
|
|
230
|
+
}
|
|
231
|
+
// Sends one pending suggestion whose step is automatic, when the session is idle and free.
|
|
232
|
+
// Review/CI fixes stop at maxRounds per PR and then wait for you.
|
|
233
|
+
autoSend(p, quiet) {
|
|
234
|
+
var _a, _b, _c, _d;
|
|
235
|
+
if (!quiet || p.workingOn || !pipelineView_2.ACTIVE_PHASES.includes(p.phase))
|
|
236
|
+
return;
|
|
237
|
+
const auto = (0, exports.autoOf)(p);
|
|
238
|
+
if (((_a = p.suggestion) === null || _a === void 0 ? void 0 : _a.kind) === 'open-pr') {
|
|
239
|
+
if (auto.openPr) {
|
|
240
|
+
this.update(p, {}, 'Automatic: asking the session to open a PR');
|
|
241
|
+
this.act(p.id, null);
|
|
242
|
+
}
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
for (const t of p.prs) {
|
|
246
|
+
const k = (_b = t.suggestion) === null || _b === void 0 ? void 0 : _b.kind;
|
|
247
|
+
if (!k || k === 'open-pr' || !auto[k])
|
|
248
|
+
continue;
|
|
249
|
+
if (k === 'merge' && ((_c = t.mergeAttempts) !== null && _c !== void 0 ? _c : 0) >= 1)
|
|
250
|
+
continue; // auto-merge tries once; then it's yours
|
|
251
|
+
const used = k === 'review' ? t.reviewRounds : k === 'ci' ? t.ciFixes : 0;
|
|
252
|
+
if (used >= p.config.maxRounds) {
|
|
253
|
+
if (!((_d = p.log.at(-1)) === null || _d === void 0 ? void 0 : _d.text.startsWith('Fix limit')))
|
|
254
|
+
this.update(p, {}, `Fix limit reached (${p.config.maxRounds} rounds) on ${(0, pipelineView_3.shortPr)(t.url)}: click Send to continue`, { title: 'Automation needs you', body: `${(0, pipelineView_3.shortPr)(t.url)} hit ${p.config.maxRounds} fix rounds` });
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
this.update(p, {}, `Automatic: ${STEP_NAME[k]} on ${(0, pipelineView_3.shortPr)(t.url)}`);
|
|
258
|
+
this.act(p.id, t.url);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
// Advances one pipeline. Serialized per pipeline; safe to call often.
|
|
263
|
+
async step(id, poll = false) {
|
|
264
|
+
if (this.busy.has(id))
|
|
265
|
+
return;
|
|
266
|
+
this.busy.add(id);
|
|
267
|
+
try {
|
|
268
|
+
await this.advance(id, poll);
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
const p = this.items.find(x => x.id === id);
|
|
272
|
+
if (p)
|
|
273
|
+
this.update(p, { phase: 'needs-you' }, `Error: ${e.message}`, { title: 'Automation needs you', body: e.message });
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
this.busy.delete(id);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
async advance(id, poll) {
|
|
280
|
+
var _a, _b, _c;
|
|
281
|
+
const p = this.items.find(x => x.id === id);
|
|
282
|
+
if (!p || !pipelineView_2.ACTIVE_PHASES.includes(p.phase))
|
|
283
|
+
return;
|
|
284
|
+
const s = liveSessionStore_1.liveSessionStore.get(p.liveId);
|
|
285
|
+
if (!s) {
|
|
286
|
+
this.update(p, { phase: 'needs-you' }, 'Session is gone');
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const since = (_a = this.quietSince.get(p.liveId)) !== null && _a !== void 0 ? _a : (s.status === 'waiting' ? 0 : Infinity);
|
|
290
|
+
const quiet = s.status === 'waiting' && Date.now() - since >= QUIET_MS && Date.now() - p.actedAt > SETTLE_MS;
|
|
291
|
+
const suggest = (t, kind, text, logText, title, body) => {
|
|
292
|
+
const sug = { kind, text, at: Date.now() };
|
|
293
|
+
if (t)
|
|
294
|
+
this.patchTrack(p, t, { suggestion: sug }, logText, { title, body });
|
|
295
|
+
else
|
|
296
|
+
this.update(p, { suggestion: sug }, logText, { title, body });
|
|
297
|
+
};
|
|
298
|
+
// Any PR link the session printed becomes a tracked PR
|
|
299
|
+
if (s.prUrl && !p.prs.some(t => t.url === s.prUrl))
|
|
300
|
+
this.addTrack(p, s.prUrl, p.prs.length ? 'New PR' : 'PR opened');
|
|
301
|
+
if (p.phase === 'waiting-for-session') {
|
|
302
|
+
if (!quiet)
|
|
303
|
+
return;
|
|
304
|
+
if (p.suggestion) {
|
|
305
|
+
this.autoSend(p, quiet);
|
|
306
|
+
return;
|
|
307
|
+
} // proposed; sent if open-PR is automatic
|
|
308
|
+
if (await hasWorkToShip(s.cwd))
|
|
309
|
+
suggest(null, 'open-pr', PROMPTS.openPr, 'Code is ready to ship; suggested opening a PR', 'Ready to open a PR?', 'Click Send in the automation to ask the session');
|
|
310
|
+
else if (!((_b = p.log.at(-1)) === null || _b === void 0 ? void 0 : _b.text.startsWith('Waiting: no code changes')))
|
|
311
|
+
this.update(p, {}, 'Waiting: no code changes to ship yet in this folder');
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
if (p.phase === 'opening-pr') {
|
|
315
|
+
if (quiet && Date.now() - p.actedAt > 10 * 60000)
|
|
316
|
+
this.update(p, { phase: 'needs-you' }, 'The session finished but no PR link appeared', { title: 'Automation needs you', body: 'No PR was opened' });
|
|
317
|
+
return;
|
|
318
|
+
}
|
|
319
|
+
// tracking
|
|
320
|
+
const busyOn = p.workingOn ? p.prs.find(t => t.url === p.workingOn) : null;
|
|
321
|
+
if (busyOn && !quiet)
|
|
322
|
+
return; // session still on it
|
|
323
|
+
let refresh = poll;
|
|
324
|
+
if (busyOn) {
|
|
325
|
+
this.patchTrack(p, busyOn, { state: 'in-review' }, `Session finished work on ${(0, pipelineView_3.shortPr)(busyOn.url)}`);
|
|
326
|
+
this.update(p, { workingOn: null });
|
|
327
|
+
refresh = true;
|
|
328
|
+
}
|
|
329
|
+
if (!refresh)
|
|
330
|
+
return;
|
|
331
|
+
// Refresh every open PR, then pick at most one thing for the session to do
|
|
332
|
+
for (const t of p.prs.filter(t => OPEN_TRACK.includes(t.state))) {
|
|
333
|
+
const pr = await prSnapshot(t.url);
|
|
334
|
+
if (!pr)
|
|
335
|
+
continue;
|
|
336
|
+
const wasFailing = ((_c = t.view) === null || _c === void 0 ? void 0 : _c.checks) === 'failing'; // suggest CI fixes once per failure, not every poll
|
|
337
|
+
this.patchTrack(p, t, { view: pr.view });
|
|
338
|
+
this.refreshSlack(p, t);
|
|
339
|
+
if (pr.state === 'MERGED' || pr.state === 'CLOSED') {
|
|
340
|
+
this.patchTrack(p, t, { state: 'done' }, `${(0, pipelineView_3.shortPr)(t.url)} ${pr.state.toLowerCase()}`, { title: `PR ${pr.state.toLowerCase()}`, body: pr.title });
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
if (t.seenFeedback < 0) {
|
|
344
|
+
this.patchTrack(p, t, { seenFeedback: pr.feedback });
|
|
345
|
+
continue;
|
|
346
|
+
}
|
|
347
|
+
if (pr.feedback > t.seenFeedback) {
|
|
348
|
+
if (!t.suggestion) {
|
|
349
|
+
this.patchTrack(p, t, { seenFeedback: pr.feedback });
|
|
350
|
+
suggest(t, 'review', PROMPTS.review(t.url), `New review feedback on ${(0, pipelineView_3.shortPr)(t.url)}`, 'New review feedback', `${pr.title}: click Send to ask the session to address it`);
|
|
351
|
+
}
|
|
352
|
+
continue;
|
|
353
|
+
}
|
|
354
|
+
if (pr.checks === 'failing') {
|
|
355
|
+
if (!wasFailing && !t.suggestion)
|
|
356
|
+
suggest(t, 'ci', PROMPTS.ci(t.url), `CI failing on ${(0, pipelineView_3.shortPr)(t.url)}`, 'CI failing', `${pr.title}: click Send to ask the session to fix it`);
|
|
357
|
+
continue;
|
|
358
|
+
}
|
|
359
|
+
if (pr.reviewDecision === 'APPROVED' && pr.checks !== 'pending' && t.state !== 'ready') {
|
|
360
|
+
this.patchTrack(p, t, { state: 'ready', suggestion: { kind: 'merge', text: PROMPTS.merge(t.url), at: Date.now() } }, `${(0, pipelineView_3.shortPr)(t.url)} approved and CI is green. Ready to merge`, { title: 'Ready to merge', body: `${pr.title}: click Merge in the automation` });
|
|
361
|
+
}
|
|
362
|
+
else if (t.state === 'ready' && pr.reviewDecision !== 'APPROVED') {
|
|
363
|
+
this.patchTrack(p, t, { state: 'in-review' }, `${(0, pipelineView_3.shortPr)(t.url)} is no longer approved`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
this.autoSend(p, quiet);
|
|
367
|
+
if (p.prs.length && p.prs.every(t => t.state === 'done'))
|
|
368
|
+
this.update(p, { phase: 'done' }, 'All PRs are merged or closed', { title: 'Automation finished', body: `${p.prs.length} PR(s) done` });
|
|
369
|
+
}
|
|
370
|
+
async announce(p, t) {
|
|
371
|
+
var _a, _b;
|
|
372
|
+
const ch = p.config.slackChannel;
|
|
373
|
+
if (!ch)
|
|
374
|
+
return;
|
|
375
|
+
const pr = await prSnapshot(t.url);
|
|
376
|
+
if (pr)
|
|
377
|
+
this.patchTrack(p, t, { view: pr.view });
|
|
378
|
+
try {
|
|
379
|
+
const { permalink } = await (0, slackBridge_1.postToSlack)(ch, `:eyes: Ready for review: *${(_a = pr === null || pr === void 0 ? void 0 : pr.title) !== null && _a !== void 0 ? _a : 'PR'}*\n${t.url}`, (_b = liveSessionStore_1.liveSessionStore.get(p.liveId)) === null || _b === void 0 ? void 0 : _b.orgId);
|
|
380
|
+
this.patchTrack(p, t, { slack: { channel: ch.name, permalink, checkedAt: Date.now() } }, `Posted ${(0, pipelineView_3.shortPr)(t.url)} to #${ch.name}`);
|
|
381
|
+
}
|
|
382
|
+
catch (e) {
|
|
383
|
+
this.update(p, {}, `Slack post for ${(0, pipelineView_3.shortPr)(t.url)} failed: ${e.message}`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
// Who's reviewing, from the Slack post's thread and reactions (every 10 min).
|
|
387
|
+
async refreshSlack(p, t) {
|
|
388
|
+
var _a, _b;
|
|
389
|
+
if (!((_a = t.slack) === null || _a === void 0 ? void 0 : _a.permalink) || Date.now() - t.slack.checkedAt < SLACK_CHECK_MS)
|
|
390
|
+
return;
|
|
391
|
+
const slack = Object.assign(Object.assign({}, t.slack), { checkedAt: Date.now() });
|
|
392
|
+
this.patchTrack(p, t, { slack }); // claim the slot before the slow call
|
|
393
|
+
try {
|
|
394
|
+
const view = await (0, slackBridge_1.readSlackThread)(slack.permalink, (_b = liveSessionStore_1.liveSessionStore.get(p.liveId)) === null || _b === void 0 ? void 0 : _b.orgId);
|
|
395
|
+
if (view)
|
|
396
|
+
this.patchTrack(p, t, { slack: Object.assign(Object.assign({}, slack), view) });
|
|
397
|
+
}
|
|
398
|
+
catch ( /* next round */_c) { /* next round */ }
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
exports.pipelineEngine = (_a = global.__pipelineEngine) !== null && _a !== void 0 ? _a : (global.__pipelineEngine = new PipelineEngine());
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLimits = getLimits;
|
|
4
|
+
const child_process_1 = require("child_process");
|
|
5
|
+
const util_1 = require("util");
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const orgRegistry_1 = require("./orgRegistry");
|
|
8
|
+
const execFileAsync = (0, util_1.promisify)(child_process_1.execFile);
|
|
9
|
+
const USAGE_URL = 'https://api.anthropic.com/api/oauth/usage';
|
|
10
|
+
const CACHE_TTL_MS = 60000;
|
|
11
|
+
// Claude Code stores each config dir's OAuth token in the macOS keychain as
|
|
12
|
+
// "Claude Code-credentials[-<first 8 hex of sha256(configDir)>]"; the default
|
|
13
|
+
// ~/.claude dir uses the unsuffixed name.
|
|
14
|
+
function keychainService(configDir) {
|
|
15
|
+
if (!configDir)
|
|
16
|
+
return 'Claude Code-credentials';
|
|
17
|
+
return `Claude Code-credentials-${(0, crypto_1.createHash)('sha256').update(configDir).digest('hex').slice(0, 8)}`;
|
|
18
|
+
}
|
|
19
|
+
async function readToken(configDir) {
|
|
20
|
+
var _a, _b;
|
|
21
|
+
try {
|
|
22
|
+
const { stdout } = await execFileAsync('security', [
|
|
23
|
+
'find-generic-password', '-s', keychainService(configDir), '-w',
|
|
24
|
+
], { timeout: 5000 });
|
|
25
|
+
return (_b = (_a = JSON.parse(stdout.trim()).claudeAiOauth) === null || _a === void 0 ? void 0 : _a.accessToken) !== null && _b !== void 0 ? _b : null;
|
|
26
|
+
}
|
|
27
|
+
catch (_c) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function fetchOrgLimits(configDir) {
|
|
32
|
+
var _a, _b, _c, _d;
|
|
33
|
+
const none = { fiveHour: null, weekly: null, scoped: [], extraUsage: null, error: null };
|
|
34
|
+
const token = await readToken(configDir);
|
|
35
|
+
if (!token)
|
|
36
|
+
return Object.assign(Object.assign({}, none), { error: 'No login found for this org' });
|
|
37
|
+
try {
|
|
38
|
+
const res = await fetch(USAGE_URL, {
|
|
39
|
+
headers: { Authorization: `Bearer ${token}`, 'anthropic-beta': 'oauth-2025-04-20' },
|
|
40
|
+
signal: AbortSignal.timeout(15000),
|
|
41
|
+
});
|
|
42
|
+
if (res.status === 401)
|
|
43
|
+
return Object.assign(Object.assign({}, none), { error: 'Token expired — open a Claude session in this org to refresh it' });
|
|
44
|
+
if (!res.ok)
|
|
45
|
+
return Object.assign(Object.assign({}, none), { error: `Usage endpoint returned ${res.status}` });
|
|
46
|
+
const d = await res.json();
|
|
47
|
+
const limits = (_a = d.limits) !== null && _a !== void 0 ? _a : [];
|
|
48
|
+
const find = (kind) => limits.find(l => l.kind === kind);
|
|
49
|
+
const session = find('session');
|
|
50
|
+
const weekly = find('weekly_all');
|
|
51
|
+
const scoped = limits
|
|
52
|
+
.filter(l => l.kind === 'weekly_scoped')
|
|
53
|
+
.map(l => {
|
|
54
|
+
var _a, _b, _c;
|
|
55
|
+
return ({
|
|
56
|
+
name: (_c = (_b = (_a = l.scope) === null || _a === void 0 ? void 0 : _a.model) === null || _b === void 0 ? void 0 : _b.display_name) !== null && _c !== void 0 ? _c : 'scoped',
|
|
57
|
+
percent: l.percent,
|
|
58
|
+
severity: l.severity,
|
|
59
|
+
resetsAt: l.resets_at,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
const eu = d.extra_usage;
|
|
63
|
+
const scale = Math.pow(10, (_b = eu === null || eu === void 0 ? void 0 : eu.decimal_places) !== null && _b !== void 0 ? _b : 2);
|
|
64
|
+
const extraUsage = eu
|
|
65
|
+
? {
|
|
66
|
+
enabled: (_c = eu.is_enabled) !== null && _c !== void 0 ? _c : false,
|
|
67
|
+
usedUSD: eu.used_credits != null ? eu.used_credits / scale : null,
|
|
68
|
+
monthlyLimitUSD: eu.monthly_limit != null ? eu.monthly_limit / scale : null,
|
|
69
|
+
spendLimitReached: (_d = eu.spend_limit_reached) !== null && _d !== void 0 ? _d : false,
|
|
70
|
+
}
|
|
71
|
+
: null;
|
|
72
|
+
return {
|
|
73
|
+
fiveHour: session ? { percent: session.percent, resetsAt: session.resets_at, severity: session.severity } : null,
|
|
74
|
+
weekly: weekly ? { percent: weekly.percent, resetsAt: weekly.resets_at, severity: weekly.severity } : null,
|
|
75
|
+
scoped,
|
|
76
|
+
extraUsage,
|
|
77
|
+
error: null,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
return Object.assign(Object.assign({}, none), { error: e instanceof Error ? e.message : 'fetch failed' });
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
let cached = null;
|
|
85
|
+
let inFlight = null;
|
|
86
|
+
async function getLimits(force = false) {
|
|
87
|
+
if (!force && cached && Date.now() - cached.fetchedAt < CACHE_TTL_MS)
|
|
88
|
+
return cached;
|
|
89
|
+
if (!inFlight) {
|
|
90
|
+
inFlight = (async () => {
|
|
91
|
+
const orgs = {};
|
|
92
|
+
await Promise.all(orgRegistry_1.orgRegistry.list().map(async (org) => {
|
|
93
|
+
orgs[org.id] = await fetchOrgLimits(org.configDir);
|
|
94
|
+
}));
|
|
95
|
+
const report = { orgs, fetchedAt: Date.now() };
|
|
96
|
+
cached = report;
|
|
97
|
+
return report;
|
|
98
|
+
})().finally(() => { inFlight = null; });
|
|
99
|
+
}
|
|
100
|
+
return inFlight;
|
|
101
|
+
}
|