gsd-pi 2.37.1-dev.d3ace49 → 2.38.0-dev.29edcdc
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/app-paths.js +1 -1
- package/dist/cli.js +9 -0
- package/dist/extension-discovery.d.ts +5 -3
- package/dist/extension-discovery.js +14 -9
- package/dist/extension-registry.js +2 -2
- package/dist/remote-questions-config.js +2 -2
- package/dist/resource-loader.js +34 -1
- package/dist/resources/extensions/browser-tools/package.json +3 -1
- package/dist/resources/extensions/cmux/index.js +55 -1
- package/dist/resources/extensions/context7/package.json +1 -1
- package/dist/resources/extensions/env-utils.js +29 -0
- package/dist/resources/extensions/get-secrets-from-user.js +5 -24
- package/dist/resources/extensions/github-sync/cli.js +284 -0
- package/dist/resources/extensions/github-sync/index.js +73 -0
- package/dist/resources/extensions/github-sync/mapping.js +67 -0
- package/dist/resources/extensions/github-sync/sync.js +424 -0
- package/dist/resources/extensions/github-sync/templates.js +118 -0
- package/dist/resources/extensions/github-sync/types.js +7 -0
- package/dist/resources/extensions/google-search/package.json +3 -1
- package/dist/resources/extensions/gsd/auto/session.js +6 -23
- package/dist/resources/extensions/gsd/auto-dispatch.js +8 -9
- package/dist/resources/extensions/gsd/auto-loop.js +597 -588
- package/dist/resources/extensions/gsd/auto-post-unit.js +99 -70
- package/dist/resources/extensions/gsd/auto-prompts.js +23 -43
- package/dist/resources/extensions/gsd/auto-start.js +13 -2
- package/dist/resources/extensions/gsd/auto-worktree-sync.js +13 -5
- package/dist/resources/extensions/gsd/auto-worktree.js +3 -3
- package/dist/resources/extensions/gsd/auto.js +143 -96
- package/dist/resources/extensions/gsd/captures.js +9 -1
- package/dist/resources/extensions/gsd/commands-extensions.js +3 -2
- package/dist/resources/extensions/gsd/commands-handlers.js +16 -3
- package/dist/resources/extensions/gsd/commands-prefs-wizard.js +1 -1
- package/dist/resources/extensions/gsd/commands.js +24 -3
- package/dist/resources/extensions/gsd/context-budget.js +2 -10
- package/dist/resources/extensions/gsd/detection.js +1 -2
- package/dist/resources/extensions/gsd/docs/preferences-reference.md +0 -2
- package/dist/resources/extensions/gsd/doctor-checks.js +82 -0
- package/dist/resources/extensions/gsd/doctor-environment.js +78 -0
- package/dist/resources/extensions/gsd/doctor-format.js +15 -0
- package/dist/resources/extensions/gsd/doctor-providers.js +27 -11
- package/dist/resources/extensions/gsd/doctor.js +204 -12
- package/dist/resources/extensions/gsd/exit-command.js +2 -1
- package/dist/resources/extensions/gsd/export.js +1 -1
- package/dist/resources/extensions/gsd/files.js +6 -2
- package/dist/resources/extensions/gsd/forensics.js +1 -1
- package/dist/resources/extensions/gsd/git-service.js +15 -12
- package/dist/resources/extensions/gsd/guided-flow.js +82 -32
- package/dist/resources/extensions/gsd/index.js +24 -20
- package/dist/resources/extensions/gsd/migrate/parsers.js +1 -1
- package/dist/resources/extensions/gsd/native-git-bridge.js +37 -0
- package/dist/resources/extensions/gsd/package.json +1 -1
- package/dist/resources/extensions/gsd/preferences-models.js +0 -12
- package/dist/resources/extensions/gsd/preferences-types.js +1 -1
- package/dist/resources/extensions/gsd/preferences-validation.js +59 -11
- package/dist/resources/extensions/gsd/preferences.js +8 -5
- package/dist/resources/extensions/gsd/prompts/discuss.md +11 -14
- package/dist/resources/extensions/gsd/prompts/execute-task.md +2 -2
- package/dist/resources/extensions/gsd/prompts/guided-discuss-milestone.md +11 -12
- package/dist/resources/extensions/gsd/prompts/guided-discuss-slice.md +8 -10
- package/dist/resources/extensions/gsd/prompts/guided-resume-task.md +1 -1
- package/dist/resources/extensions/gsd/prompts/queue.md +4 -8
- package/dist/resources/extensions/gsd/prompts/reactive-execute.md +11 -8
- package/dist/resources/extensions/gsd/prompts/run-uat.md +27 -10
- package/dist/resources/extensions/gsd/prompts/workflow-start.md +2 -2
- package/dist/resources/extensions/gsd/repo-identity.js +21 -4
- package/dist/resources/extensions/gsd/resource-version.js +2 -1
- package/dist/resources/extensions/gsd/roadmap-mutations.js +24 -0
- package/dist/resources/extensions/gsd/state.js +1 -1
- package/dist/resources/extensions/gsd/visualizer-data.js +1 -1
- package/dist/resources/extensions/gsd/worktree.js +35 -16
- package/dist/resources/extensions/mcp-client/index.js +14 -1
- package/dist/resources/extensions/remote-questions/status.js +2 -1
- package/dist/resources/extensions/remote-questions/store.js +2 -1
- package/dist/resources/extensions/search-the-web/provider.js +2 -1
- package/dist/resources/extensions/subagent/index.js +12 -3
- package/dist/resources/extensions/subagent/isolation.js +2 -1
- package/dist/resources/extensions/ttsr/rule-loader.js +2 -1
- package/dist/resources/extensions/universal-config/package.json +1 -1
- package/dist/welcome-screen.d.ts +12 -0
- package/dist/welcome-screen.js +53 -0
- package/package.json +1 -1
- package/packages/pi-ai/dist/utils/oauth/anthropic.js +2 -2
- package/packages/pi-ai/dist/utils/oauth/anthropic.js.map +1 -1
- package/packages/pi-ai/src/utils/oauth/anthropic.ts +2 -2
- package/packages/pi-coding-agent/dist/core/extensions/loader.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/extensions/loader.js +205 -7
- package/packages/pi-coding-agent/dist/core/extensions/loader.js.map +1 -1
- package/packages/pi-coding-agent/dist/core/package-manager.d.ts.map +1 -1
- package/packages/pi-coding-agent/dist/core/package-manager.js +8 -4
- package/packages/pi-coding-agent/dist/core/package-manager.js.map +1 -1
- package/packages/pi-coding-agent/package.json +1 -1
- package/packages/pi-coding-agent/src/core/extensions/loader.ts +223 -7
- package/packages/pi-coding-agent/src/core/package-manager.ts +8 -4
- package/pkg/package.json +1 -1
- package/src/resources/extensions/cmux/index.ts +57 -1
- package/src/resources/extensions/env-utils.ts +31 -0
- package/src/resources/extensions/get-secrets-from-user.ts +5 -24
- package/src/resources/extensions/github-sync/cli.ts +364 -0
- package/src/resources/extensions/github-sync/index.ts +93 -0
- package/src/resources/extensions/github-sync/mapping.ts +81 -0
- package/src/resources/extensions/github-sync/sync.ts +556 -0
- package/src/resources/extensions/github-sync/templates.ts +183 -0
- package/src/resources/extensions/github-sync/tests/cli.test.ts +20 -0
- package/src/resources/extensions/github-sync/tests/commit-linking.test.ts +39 -0
- package/src/resources/extensions/github-sync/tests/mapping.test.ts +104 -0
- package/src/resources/extensions/github-sync/tests/templates.test.ts +110 -0
- package/src/resources/extensions/github-sync/types.ts +47 -0
- package/src/resources/extensions/gsd/auto/session.ts +7 -25
- package/src/resources/extensions/gsd/auto-dispatch.ts +7 -9
- package/src/resources/extensions/gsd/auto-loop.ts +484 -546
- package/src/resources/extensions/gsd/auto-post-unit.ts +80 -44
- package/src/resources/extensions/gsd/auto-prompts.ts +25 -45
- package/src/resources/extensions/gsd/auto-start.ts +18 -2
- package/src/resources/extensions/gsd/auto-worktree-sync.ts +15 -4
- package/src/resources/extensions/gsd/auto-worktree.ts +3 -3
- package/src/resources/extensions/gsd/auto.ts +139 -101
- package/src/resources/extensions/gsd/captures.ts +10 -1
- package/src/resources/extensions/gsd/commands-extensions.ts +4 -2
- package/src/resources/extensions/gsd/commands-handlers.ts +17 -2
- package/src/resources/extensions/gsd/commands-prefs-wizard.ts +1 -1
- package/src/resources/extensions/gsd/commands.ts +26 -4
- package/src/resources/extensions/gsd/context-budget.ts +2 -12
- package/src/resources/extensions/gsd/detection.ts +2 -2
- package/src/resources/extensions/gsd/docs/preferences-reference.md +0 -2
- package/src/resources/extensions/gsd/doctor-checks.ts +75 -0
- package/src/resources/extensions/gsd/doctor-environment.ts +82 -1
- package/src/resources/extensions/gsd/doctor-format.ts +20 -0
- package/src/resources/extensions/gsd/doctor-providers.ts +26 -9
- package/src/resources/extensions/gsd/doctor-types.ts +16 -1
- package/src/resources/extensions/gsd/doctor.ts +199 -14
- package/src/resources/extensions/gsd/exit-command.ts +2 -2
- package/src/resources/extensions/gsd/export.ts +1 -1
- package/src/resources/extensions/gsd/files.ts +5 -3
- package/src/resources/extensions/gsd/forensics.ts +1 -1
- package/src/resources/extensions/gsd/git-service.ts +20 -10
- package/src/resources/extensions/gsd/guided-flow.ts +110 -38
- package/src/resources/extensions/gsd/index.ts +24 -17
- package/src/resources/extensions/gsd/migrate/parsers.ts +1 -1
- package/src/resources/extensions/gsd/native-git-bridge.ts +37 -0
- package/src/resources/extensions/gsd/preferences-models.ts +0 -12
- package/src/resources/extensions/gsd/preferences-types.ts +4 -4
- package/src/resources/extensions/gsd/preferences-validation.ts +51 -11
- package/src/resources/extensions/gsd/preferences.ts +8 -5
- package/src/resources/extensions/gsd/prompts/discuss.md +11 -14
- package/src/resources/extensions/gsd/prompts/execute-task.md +2 -2
- package/src/resources/extensions/gsd/prompts/guided-discuss-milestone.md +11 -12
- package/src/resources/extensions/gsd/prompts/guided-discuss-slice.md +8 -10
- package/src/resources/extensions/gsd/prompts/guided-resume-task.md +1 -1
- package/src/resources/extensions/gsd/prompts/queue.md +4 -8
- package/src/resources/extensions/gsd/prompts/reactive-execute.md +11 -8
- package/src/resources/extensions/gsd/prompts/run-uat.md +27 -10
- package/src/resources/extensions/gsd/prompts/workflow-start.md +2 -2
- package/src/resources/extensions/gsd/repo-identity.ts +23 -4
- package/src/resources/extensions/gsd/resource-version.ts +3 -1
- package/src/resources/extensions/gsd/roadmap-mutations.ts +29 -0
- package/src/resources/extensions/gsd/state.ts +1 -1
- package/src/resources/extensions/gsd/tests/agent-end-retry.test.ts +21 -18
- package/src/resources/extensions/gsd/tests/auto-loop.test.ts +122 -68
- package/src/resources/extensions/gsd/tests/cmux.test.ts +93 -0
- package/src/resources/extensions/gsd/tests/doctor-enhancements.test.ts +266 -0
- package/src/resources/extensions/gsd/tests/doctor-providers.test.ts +86 -3
- package/src/resources/extensions/gsd/tests/preferences.test.ts +2 -7
- package/src/resources/extensions/gsd/tests/prompt-contracts.test.ts +59 -0
- package/src/resources/extensions/gsd/tests/repo-identity-worktree.test.ts +21 -1
- package/src/resources/extensions/gsd/tests/run-uat.test.ts +11 -3
- package/src/resources/extensions/gsd/tests/worktree.test.ts +47 -0
- package/src/resources/extensions/gsd/types.ts +0 -1
- package/src/resources/extensions/gsd/visualizer-data.ts +1 -1
- package/src/resources/extensions/gsd/worktree.ts +35 -15
- package/src/resources/extensions/mcp-client/index.ts +17 -1
- package/src/resources/extensions/remote-questions/status.ts +3 -1
- package/src/resources/extensions/remote-questions/store.ts +3 -1
- package/src/resources/extensions/search-the-web/provider.ts +2 -1
- package/src/resources/extensions/subagent/index.ts +12 -3
- package/src/resources/extensions/subagent/isolation.ts +3 -1
- package/src/resources/extensions/ttsr/rule-loader.ts +3 -1
- package/dist/resources/extensions/gsd/prompt-compressor.js +0 -393
- package/dist/resources/extensions/gsd/semantic-chunker.js +0 -254
- package/dist/resources/extensions/gsd/summary-distiller.js +0 -212
- package/src/resources/extensions/gsd/prompt-compressor.ts +0 -508
- package/src/resources/extensions/gsd/semantic-chunker.ts +0 -336
- package/src/resources/extensions/gsd/summary-distiller.ts +0 -258
- package/src/resources/extensions/gsd/tests/context-compression.test.ts +0 -193
- package/src/resources/extensions/gsd/tests/prompt-compressor.test.ts +0 -529
- package/src/resources/extensions/gsd/tests/semantic-chunker.test.ts +0 -426
- package/src/resources/extensions/gsd/tests/summary-distiller.test.ts +0 -323
- package/src/resources/extensions/gsd/tests/token-optimization-benchmark.test.ts +0 -1272
- package/src/resources/extensions/gsd/tests/token-optimization-prefs.test.ts +0 -164
package/dist/app-paths.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { homedir } from 'os';
|
|
2
2
|
import { join } from 'path';
|
|
3
|
-
export const appRoot = join(homedir(), '.gsd');
|
|
3
|
+
export const appRoot = process.env.GSD_HOME || join(homedir(), '.gsd');
|
|
4
4
|
export const agentDir = join(appRoot, 'agent');
|
|
5
5
|
export const sessionsDir = join(appRoot, 'sessions');
|
|
6
6
|
export const authFilePath = join(agentDir, 'auth.json');
|
package/dist/cli.js
CHANGED
|
@@ -505,6 +505,15 @@ if (enabledModelPatterns && enabledModelPatterns.length > 0) {
|
|
|
505
505
|
session.setScopedModels(scopedModels);
|
|
506
506
|
}
|
|
507
507
|
}
|
|
508
|
+
// Welcome screen — shown on every fresh interactive session before TUI takes over
|
|
509
|
+
{
|
|
510
|
+
const { printWelcomeScreen } = await import('./welcome-screen.js');
|
|
511
|
+
printWelcomeScreen({
|
|
512
|
+
version: process.env.GSD_VERSION || '0.0.0',
|
|
513
|
+
modelName: settingsManager.getDefaultModel() || undefined,
|
|
514
|
+
provider: settingsManager.getDefaultProvider() || undefined,
|
|
515
|
+
});
|
|
516
|
+
}
|
|
508
517
|
const interactiveMode = new InteractiveMode(session);
|
|
509
518
|
markStartup('InteractiveMode');
|
|
510
519
|
printStartupTimings();
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Resolves the entry-point file(s) for a single extension directory.
|
|
3
3
|
*
|
|
4
|
-
* 1. If the directory contains a package.json with a `pi
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* 1. If the directory contains a package.json with a `pi` manifest object,
|
|
5
|
+
* the manifest is authoritative:
|
|
6
|
+
* - `pi.extensions` array → resolve each entry relative to the directory.
|
|
7
|
+
* - `pi: {}` (no extensions) → return empty (library opt-out, e.g. cmux).
|
|
8
|
+
* 2. Only when no `pi` manifest exists does it fall back to `index.ts` → `index.js`.
|
|
7
9
|
*/
|
|
8
10
|
export declare function resolveExtensionEntries(dir: string): string[];
|
|
9
11
|
/**
|
|
@@ -6,24 +6,29 @@ function isExtensionFile(name) {
|
|
|
6
6
|
/**
|
|
7
7
|
* Resolves the entry-point file(s) for a single extension directory.
|
|
8
8
|
*
|
|
9
|
-
* 1. If the directory contains a package.json with a `pi
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* 1. If the directory contains a package.json with a `pi` manifest object,
|
|
10
|
+
* the manifest is authoritative:
|
|
11
|
+
* - `pi.extensions` array → resolve each entry relative to the directory.
|
|
12
|
+
* - `pi: {}` (no extensions) → return empty (library opt-out, e.g. cmux).
|
|
13
|
+
* 2. Only when no `pi` manifest exists does it fall back to `index.ts` → `index.js`.
|
|
12
14
|
*/
|
|
13
15
|
export function resolveExtensionEntries(dir) {
|
|
14
16
|
const packageJsonPath = join(dir, 'package.json');
|
|
15
17
|
if (existsSync(packageJsonPath)) {
|
|
16
18
|
try {
|
|
17
19
|
const pkg = JSON.parse(readFileSync(packageJsonPath, 'utf-8'));
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
if (pkg?.pi && typeof pkg.pi === 'object') {
|
|
21
|
+
// When a pi manifest exists, it is authoritative — don't fall through
|
|
22
|
+
// to index.ts/index.js auto-detection. This allows library directories
|
|
23
|
+
// (like cmux) to opt out by declaring "pi": {} with no extensions.
|
|
24
|
+
const declared = pkg.pi.extensions;
|
|
25
|
+
if (!Array.isArray(declared) || declared.length === 0) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
return declared
|
|
21
29
|
.filter((entry) => typeof entry === 'string')
|
|
22
30
|
.map((entry) => resolve(dir, entry))
|
|
23
31
|
.filter((entry) => existsSync(entry));
|
|
24
|
-
if (resolved.length > 0) {
|
|
25
|
-
return resolved;
|
|
26
|
-
}
|
|
27
32
|
}
|
|
28
33
|
}
|
|
29
34
|
catch {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* The only way an extension stops loading is an explicit `gsd extensions disable <id>`.
|
|
7
7
|
*/
|
|
8
8
|
import { existsSync, mkdirSync, readFileSync, readdirSync, renameSync, writeFileSync } from "node:fs";
|
|
9
|
-
import {
|
|
9
|
+
import { appRoot } from "./app-paths.js";
|
|
10
10
|
import { dirname, join } from "node:path";
|
|
11
11
|
// ─── Validation ─────────────────────────────────────────────────────────────
|
|
12
12
|
function isRegistry(data) {
|
|
@@ -26,7 +26,7 @@ function isManifest(data) {
|
|
|
26
26
|
}
|
|
27
27
|
// ─── Registry Path ──────────────────────────────────────────────────────────
|
|
28
28
|
export function getRegistryPath() {
|
|
29
|
-
return join(
|
|
29
|
+
return join(appRoot, "extensions", "registry.json");
|
|
30
30
|
}
|
|
31
31
|
// ─── Registry I/O ───────────────────────────────────────────────────────────
|
|
32
32
|
function defaultRegistry() {
|
|
@@ -9,12 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "node:fs";
|
|
11
11
|
import { dirname, join } from "node:path";
|
|
12
|
-
import {
|
|
12
|
+
import { appRoot } from "./app-paths.js";
|
|
13
13
|
// Inlined from preferences.ts to avoid crossing the compiled/uncompiled
|
|
14
14
|
// boundary — this file is compiled by tsc, but preferences.ts is loaded
|
|
15
15
|
// via jiti at runtime. Importing it as .js fails because no .js exists
|
|
16
16
|
// in dist/. See #592, #1110.
|
|
17
|
-
const GLOBAL_PREFERENCES_PATH = join(
|
|
17
|
+
const GLOBAL_PREFERENCES_PATH = join(appRoot, "preferences.md");
|
|
18
18
|
export function saveRemoteQuestionsConfig(channel, channelId) {
|
|
19
19
|
const prefsPath = GLOBAL_PREFERENCES_PATH;
|
|
20
20
|
const block = [
|
package/dist/resource-loader.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefaultResourceLoader } from '@gsd/pi-coding-agent';
|
|
2
2
|
import { createHash } from 'node:crypto';
|
|
3
3
|
import { homedir } from 'node:os';
|
|
4
|
-
import { chmodSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { chmodSync, copyFileSync, cpSync, existsSync, lstatSync, mkdirSync, readFileSync, readlinkSync, readdirSync, rmSync, statSync, symlinkSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
5
5
|
import { dirname, join, relative, resolve } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { compareSemver } from './update-check.js';
|
|
@@ -217,6 +217,35 @@ function copyDirRecursive(src, dest) {
|
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
}
|
|
220
|
+
/**
|
|
221
|
+
* Creates (or updates) a symlink at agentDir/node_modules pointing to GSD's
|
|
222
|
+
* own node_modules directory.
|
|
223
|
+
*
|
|
224
|
+
* Native ESM `import()` ignores NODE_PATH — it resolves packages by walking
|
|
225
|
+
* up the directory tree from the importing file. Extension files synced to
|
|
226
|
+
* ~/.gsd/agent/extensions/ have no ancestor node_modules, so imports of
|
|
227
|
+
* @gsd/* packages fail. The symlink makes Node's standard resolution find
|
|
228
|
+
* them without requiring every call site to use jiti.
|
|
229
|
+
*/
|
|
230
|
+
function ensureNodeModulesSymlink(agentDir) {
|
|
231
|
+
const agentNodeModules = join(agentDir, 'node_modules');
|
|
232
|
+
const gsdNodeModules = join(packageRoot, 'node_modules');
|
|
233
|
+
try {
|
|
234
|
+
const existing = readlinkSync(agentNodeModules);
|
|
235
|
+
if (existing === gsdNodeModules)
|
|
236
|
+
return; // already correct
|
|
237
|
+
unlinkSync(agentNodeModules);
|
|
238
|
+
}
|
|
239
|
+
catch {
|
|
240
|
+
// readlinkSync throws if path doesn't exist or isn't a symlink — both are fine
|
|
241
|
+
}
|
|
242
|
+
try {
|
|
243
|
+
symlinkSync(gsdNodeModules, agentNodeModules, 'junction');
|
|
244
|
+
}
|
|
245
|
+
catch {
|
|
246
|
+
// Non-fatal — worst case, extensions fall back to NODE_PATH via jiti
|
|
247
|
+
}
|
|
248
|
+
}
|
|
220
249
|
/**
|
|
221
250
|
* Syncs all bundled resources to agentDir (~/.gsd/agent/) on every launch.
|
|
222
251
|
*
|
|
@@ -262,6 +291,10 @@ export function initResources(agentDir) {
|
|
|
262
291
|
// Ensure all newly copied files are owner-writable so the next run can
|
|
263
292
|
// overwrite them (covers extensions, agents, and skills in one walk).
|
|
264
293
|
makeTreeWritable(agentDir);
|
|
294
|
+
// Ensure ~/.gsd/agent/node_modules symlinks to GSD's node_modules so that
|
|
295
|
+
// native ESM import() calls from synced extension files can resolve @gsd/*
|
|
296
|
+
// packages via ancestor directory lookup. NODE_PATH only applies to CJS/jiti.
|
|
297
|
+
ensureNodeModulesSymlink(agentDir);
|
|
265
298
|
writeManagedResourceManifest(agentDir);
|
|
266
299
|
ensureRegistryEntries(join(agentDir, 'extensions'));
|
|
267
300
|
}
|
|
@@ -237,11 +237,14 @@ export class CmuxClient {
|
|
|
237
237
|
return extractSurfaceIds(parsed);
|
|
238
238
|
}
|
|
239
239
|
async createSplit(direction) {
|
|
240
|
+
return this.createSplitFrom(this.config.surfaceId, direction);
|
|
241
|
+
}
|
|
242
|
+
async createSplitFrom(sourceSurfaceId, direction) {
|
|
240
243
|
if (!this.config.splits)
|
|
241
244
|
return null;
|
|
242
245
|
const before = new Set(await this.listSurfaceIds());
|
|
243
246
|
const args = ["new-split", direction];
|
|
244
|
-
const scopedArgs = this.appendSurface(this.appendWorkspace(args),
|
|
247
|
+
const scopedArgs = this.appendSurface(this.appendWorkspace(args), sourceSurfaceId);
|
|
245
248
|
await this.runAsync(scopedArgs);
|
|
246
249
|
const after = await this.listSurfaceIds();
|
|
247
250
|
for (const id of after) {
|
|
@@ -250,6 +253,57 @@ export class CmuxClient {
|
|
|
250
253
|
}
|
|
251
254
|
return null;
|
|
252
255
|
}
|
|
256
|
+
/**
|
|
257
|
+
* Create a grid of surfaces for parallel agent execution.
|
|
258
|
+
*
|
|
259
|
+
* Layout strategy (gsd stays in the original surface):
|
|
260
|
+
* 1 agent: [gsd | A]
|
|
261
|
+
* 2 agents: [gsd | A]
|
|
262
|
+
* [ | B]
|
|
263
|
+
* 3 agents: [gsd | A]
|
|
264
|
+
* [ C | B]
|
|
265
|
+
* 4 agents: [gsd | A]
|
|
266
|
+
* [ C | B] (D splits from B downward)
|
|
267
|
+
* [ | D]
|
|
268
|
+
*
|
|
269
|
+
* Returns surface IDs in order, or empty array on failure.
|
|
270
|
+
*/
|
|
271
|
+
async createGridLayout(count) {
|
|
272
|
+
if (!this.config.splits || count <= 0)
|
|
273
|
+
return [];
|
|
274
|
+
const surfaces = [];
|
|
275
|
+
// First split: create right column from the gsd surface
|
|
276
|
+
const rightCol = await this.createSplitFrom(this.config.surfaceId, "right");
|
|
277
|
+
if (!rightCol)
|
|
278
|
+
return [];
|
|
279
|
+
surfaces.push(rightCol);
|
|
280
|
+
if (count === 1)
|
|
281
|
+
return surfaces;
|
|
282
|
+
// Second split: split right column down → bottom-right
|
|
283
|
+
const bottomRight = await this.createSplitFrom(rightCol, "down");
|
|
284
|
+
if (!bottomRight)
|
|
285
|
+
return surfaces;
|
|
286
|
+
surfaces.push(bottomRight);
|
|
287
|
+
if (count === 2)
|
|
288
|
+
return surfaces;
|
|
289
|
+
// Third split: split gsd surface down → bottom-left
|
|
290
|
+
const bottomLeft = await this.createSplitFrom(this.config.surfaceId, "down");
|
|
291
|
+
if (!bottomLeft)
|
|
292
|
+
return surfaces;
|
|
293
|
+
surfaces.push(bottomLeft);
|
|
294
|
+
if (count === 3)
|
|
295
|
+
return surfaces;
|
|
296
|
+
// Fourth+: split subsequent surfaces down from the last created
|
|
297
|
+
let lastSurface = bottomRight;
|
|
298
|
+
for (let i = 3; i < count; i++) {
|
|
299
|
+
const next = await this.createSplitFrom(lastSurface, "down");
|
|
300
|
+
if (!next)
|
|
301
|
+
break;
|
|
302
|
+
surfaces.push(next);
|
|
303
|
+
lastSurface = next;
|
|
304
|
+
}
|
|
305
|
+
return surfaces;
|
|
306
|
+
}
|
|
253
307
|
async sendSurface(surfaceId, text) {
|
|
254
308
|
const payload = text.endsWith("\n") ? text : `${text}\n`;
|
|
255
309
|
const stdout = await this.runAsync(["send-surface", "--surface", surfaceId, payload]);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// GSD Extension — Environment variable utilities
|
|
2
|
+
// Copyright (c) 2026 Jeremy McSpadden <jeremy@fluxlabs.net>
|
|
3
|
+
//
|
|
4
|
+
// Pure utility for checking existing env keys in .env files and process.env.
|
|
5
|
+
// Extracted from get-secrets-from-user.ts to avoid pulling in @gsd/pi-tui
|
|
6
|
+
// when only env-checking is needed (e.g. from files.ts during report generation).
|
|
7
|
+
import { readFile } from "node:fs/promises";
|
|
8
|
+
/**
|
|
9
|
+
* Check which keys already exist in a .env file or process.env.
|
|
10
|
+
* Returns the subset of `keys` that are already set.
|
|
11
|
+
*/
|
|
12
|
+
export async function checkExistingEnvKeys(keys, envFilePath) {
|
|
13
|
+
let fileContent = "";
|
|
14
|
+
try {
|
|
15
|
+
fileContent = await readFile(envFilePath, "utf8");
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// ENOENT or other read error — proceed with empty content
|
|
19
|
+
}
|
|
20
|
+
const existing = [];
|
|
21
|
+
for (const key of keys) {
|
|
22
|
+
const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
23
|
+
const regex = new RegExp(`^${escaped}\\s*=`, "m");
|
|
24
|
+
if (regex.test(fileContent) || key in process.env) {
|
|
25
|
+
existing.push(key);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return existing;
|
|
29
|
+
}
|
|
@@ -46,30 +46,11 @@ async function writeEnvKey(filePath, key, value) {
|
|
|
46
46
|
await writeFile(filePath, content, "utf8");
|
|
47
47
|
}
|
|
48
48
|
// ─── Exported utilities ───────────────────────────────────────────────────────
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*/
|
|
55
|
-
export async function checkExistingEnvKeys(keys, envFilePath) {
|
|
56
|
-
let fileContent = "";
|
|
57
|
-
try {
|
|
58
|
-
fileContent = await readFile(envFilePath, "utf8");
|
|
59
|
-
}
|
|
60
|
-
catch {
|
|
61
|
-
// ENOENT or other read error — proceed with empty content
|
|
62
|
-
}
|
|
63
|
-
const existing = [];
|
|
64
|
-
for (const key of keys) {
|
|
65
|
-
const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
66
|
-
const regex = new RegExp(`^${escaped}\\s*=`, "m");
|
|
67
|
-
if (regex.test(fileContent) || key in process.env) {
|
|
68
|
-
existing.push(key);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return existing;
|
|
72
|
-
}
|
|
49
|
+
// Re-export from env-utils.ts so existing consumers still work.
|
|
50
|
+
// The implementation lives in env-utils.ts to avoid pulling @gsd/pi-tui
|
|
51
|
+
// into modules that only need env-checking (e.g. files.ts during reports).
|
|
52
|
+
import { checkExistingEnvKeys } from "./env-utils.js";
|
|
53
|
+
export { checkExistingEnvKeys };
|
|
73
54
|
/**
|
|
74
55
|
* Detect the write destination based on project files in basePath.
|
|
75
56
|
* Priority: vercel.json → convex/ dir → fallback "dotenv".
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Thin wrapper around the `gh` CLI.
|
|
3
|
+
*
|
|
4
|
+
* Every public function returns `GhResult<T>` — never throws.
|
|
5
|
+
* Uses `execFileSync` (not `execSync`) for safety.
|
|
6
|
+
*/
|
|
7
|
+
import { execFileSync } from "node:child_process";
|
|
8
|
+
function ok(data) {
|
|
9
|
+
return { ok: true, data };
|
|
10
|
+
}
|
|
11
|
+
function fail(error) {
|
|
12
|
+
return { ok: false, error };
|
|
13
|
+
}
|
|
14
|
+
// ─── gh Availability ────────────────────────────────────────────────────────
|
|
15
|
+
let _ghAvailable = null;
|
|
16
|
+
export function ghIsAvailable() {
|
|
17
|
+
if (_ghAvailable !== null)
|
|
18
|
+
return _ghAvailable;
|
|
19
|
+
try {
|
|
20
|
+
execFileSync("gh", ["--version"], {
|
|
21
|
+
encoding: "utf-8",
|
|
22
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
23
|
+
timeout: 5_000,
|
|
24
|
+
});
|
|
25
|
+
_ghAvailable = true;
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
_ghAvailable = false;
|
|
29
|
+
}
|
|
30
|
+
return _ghAvailable;
|
|
31
|
+
}
|
|
32
|
+
/** Reset cached availability (for testing). */
|
|
33
|
+
export function _resetGhCache() {
|
|
34
|
+
_ghAvailable = null;
|
|
35
|
+
}
|
|
36
|
+
// ─── Rate Limit Check ───────────────────────────────────────────────────────
|
|
37
|
+
let _rateLimitCheckedAt = 0;
|
|
38
|
+
let _rateLimitOk = true;
|
|
39
|
+
const RATE_LIMIT_CHECK_INTERVAL_MS = 300_000; // 5 minutes
|
|
40
|
+
export function ghHasRateLimit(cwd) {
|
|
41
|
+
const now = Date.now();
|
|
42
|
+
if (now - _rateLimitCheckedAt < RATE_LIMIT_CHECK_INTERVAL_MS)
|
|
43
|
+
return _rateLimitOk;
|
|
44
|
+
_rateLimitCheckedAt = now;
|
|
45
|
+
try {
|
|
46
|
+
const raw = execFileSync("gh", ["api", "rate_limit", "--jq", ".rate.remaining"], {
|
|
47
|
+
cwd,
|
|
48
|
+
encoding: "utf-8",
|
|
49
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
50
|
+
timeout: 10_000,
|
|
51
|
+
}).trim();
|
|
52
|
+
const remaining = parseInt(raw, 10);
|
|
53
|
+
_rateLimitOk = Number.isFinite(remaining) && remaining >= 100;
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
// Can't check — assume OK so we don't silently disable sync
|
|
57
|
+
_rateLimitOk = true;
|
|
58
|
+
}
|
|
59
|
+
return _rateLimitOk;
|
|
60
|
+
}
|
|
61
|
+
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
62
|
+
const GH_TIMEOUT = 15_000;
|
|
63
|
+
const MAX_BODY_LENGTH = 65_000;
|
|
64
|
+
function truncateBody(body) {
|
|
65
|
+
if (body.length <= MAX_BODY_LENGTH)
|
|
66
|
+
return body;
|
|
67
|
+
return body.slice(0, MAX_BODY_LENGTH) + "\n\n---\n*Body truncated (exceeded 65K characters)*";
|
|
68
|
+
}
|
|
69
|
+
function runGh(args, cwd) {
|
|
70
|
+
try {
|
|
71
|
+
const stdout = execFileSync("gh", args, {
|
|
72
|
+
cwd,
|
|
73
|
+
encoding: "utf-8",
|
|
74
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
75
|
+
timeout: GH_TIMEOUT,
|
|
76
|
+
}).trim();
|
|
77
|
+
return ok(stdout);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
81
|
+
return fail(msg);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
function runGhJson(args, cwd) {
|
|
85
|
+
const result = runGh(args, cwd);
|
|
86
|
+
if (!result.ok)
|
|
87
|
+
return fail(result.error);
|
|
88
|
+
try {
|
|
89
|
+
return ok(JSON.parse(result.data));
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
return fail(`Failed to parse JSON: ${result.data}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// ─── Repo Detection ─────────────────────────────────────────────────────────
|
|
96
|
+
export function ghDetectRepo(cwd) {
|
|
97
|
+
const result = runGh(["repo", "view", "--json", "nameWithOwner", "--jq", ".nameWithOwner"], cwd);
|
|
98
|
+
if (!result.ok)
|
|
99
|
+
return fail(result.error);
|
|
100
|
+
const repo = result.data.trim();
|
|
101
|
+
if (!repo || !repo.includes("/"))
|
|
102
|
+
return fail("Could not detect repo");
|
|
103
|
+
return ok(repo);
|
|
104
|
+
}
|
|
105
|
+
export function ghCreateIssue(cwd, opts) {
|
|
106
|
+
const args = [
|
|
107
|
+
"issue", "create",
|
|
108
|
+
"--repo", opts.repo,
|
|
109
|
+
"--title", opts.title,
|
|
110
|
+
"--body", truncateBody(opts.body),
|
|
111
|
+
];
|
|
112
|
+
if (opts.labels?.length) {
|
|
113
|
+
args.push("--label", opts.labels.join(","));
|
|
114
|
+
}
|
|
115
|
+
if (opts.milestone) {
|
|
116
|
+
args.push("--milestone", String(opts.milestone));
|
|
117
|
+
}
|
|
118
|
+
const result = runGh(args, cwd);
|
|
119
|
+
if (!result.ok)
|
|
120
|
+
return fail(result.error);
|
|
121
|
+
// gh issue create returns the URL; extract issue number
|
|
122
|
+
const match = result.data.match(/\/issues\/(\d+)/);
|
|
123
|
+
if (!match)
|
|
124
|
+
return fail(`Could not parse issue number from: ${result.data}`);
|
|
125
|
+
const issueNumber = parseInt(match[1], 10);
|
|
126
|
+
// If parent specified, add as sub-issue via GraphQL
|
|
127
|
+
if (opts.parentIssue) {
|
|
128
|
+
ghAddSubIssue(cwd, opts.repo, opts.parentIssue, issueNumber);
|
|
129
|
+
}
|
|
130
|
+
return ok(issueNumber);
|
|
131
|
+
}
|
|
132
|
+
export function ghCloseIssue(cwd, repo, issueNumber, comment) {
|
|
133
|
+
if (comment) {
|
|
134
|
+
ghAddComment(cwd, repo, issueNumber, comment);
|
|
135
|
+
}
|
|
136
|
+
const result = runGh(["issue", "close", String(issueNumber), "--repo", repo], cwd);
|
|
137
|
+
if (!result.ok)
|
|
138
|
+
return fail(result.error);
|
|
139
|
+
return ok(undefined);
|
|
140
|
+
}
|
|
141
|
+
export function ghAddComment(cwd, repo, issueNumber, body) {
|
|
142
|
+
const result = runGh(["issue", "comment", String(issueNumber), "--repo", repo, "--body", truncateBody(body)], cwd);
|
|
143
|
+
if (!result.ok)
|
|
144
|
+
return fail(result.error);
|
|
145
|
+
return ok(undefined);
|
|
146
|
+
}
|
|
147
|
+
// ─── Sub-Issues (GraphQL) ───────────────────────────────────────────────────
|
|
148
|
+
function ghAddSubIssue(cwd, repo, parentNumber, childNumber) {
|
|
149
|
+
// Get node IDs for both issues
|
|
150
|
+
const parentResult = runGhJson(["api", `repos/${repo}/issues/${parentNumber}`, "--jq", "{id: .node_id}"], cwd);
|
|
151
|
+
const childResult = runGhJson(["api", `repos/${repo}/issues/${childNumber}`, "--jq", "{id: .node_id}"], cwd);
|
|
152
|
+
if (!parentResult.ok || !childResult.ok) {
|
|
153
|
+
return fail("Could not resolve issue node IDs for sub-issue linking");
|
|
154
|
+
}
|
|
155
|
+
const mutation = `mutation { addSubIssue(input: { issueId: "${parentResult.data.id}", subIssueId: "${childResult.data.id}" }) { issue { id } } }`;
|
|
156
|
+
return runGh(["api", "graphql", "-f", `query=${mutation}`], cwd);
|
|
157
|
+
}
|
|
158
|
+
// ─── Milestones ─────────────────────────────────────────────────────────────
|
|
159
|
+
export function ghCreateMilestone(cwd, repo, title, description) {
|
|
160
|
+
const result = runGhJson([
|
|
161
|
+
"api", `repos/${repo}/milestones`,
|
|
162
|
+
"-X", "POST",
|
|
163
|
+
"-f", `title=${title}`,
|
|
164
|
+
"-f", `description=${truncateBody(description)}`,
|
|
165
|
+
"-f", "state=open",
|
|
166
|
+
"--jq", "{number: .number}",
|
|
167
|
+
], cwd);
|
|
168
|
+
if (!result.ok)
|
|
169
|
+
return fail(result.error);
|
|
170
|
+
return ok(result.data.number);
|
|
171
|
+
}
|
|
172
|
+
export function ghCloseMilestone(cwd, repo, milestoneNumber) {
|
|
173
|
+
const result = runGh([
|
|
174
|
+
"api", `repos/${repo}/milestones/${milestoneNumber}`,
|
|
175
|
+
"-X", "PATCH",
|
|
176
|
+
"-f", "state=closed",
|
|
177
|
+
], cwd);
|
|
178
|
+
if (!result.ok)
|
|
179
|
+
return fail(result.error);
|
|
180
|
+
return ok(undefined);
|
|
181
|
+
}
|
|
182
|
+
export function ghCreatePR(cwd, opts) {
|
|
183
|
+
const args = [
|
|
184
|
+
"pr", "create",
|
|
185
|
+
"--repo", opts.repo,
|
|
186
|
+
"--base", opts.base,
|
|
187
|
+
"--head", opts.head,
|
|
188
|
+
"--title", opts.title,
|
|
189
|
+
"--body", truncateBody(opts.body),
|
|
190
|
+
];
|
|
191
|
+
if (opts.draft)
|
|
192
|
+
args.push("--draft");
|
|
193
|
+
const result = runGh(args, cwd);
|
|
194
|
+
if (!result.ok)
|
|
195
|
+
return fail(result.error);
|
|
196
|
+
const match = result.data.match(/\/pull\/(\d+)/);
|
|
197
|
+
if (!match)
|
|
198
|
+
return fail(`Could not parse PR number from: ${result.data}`);
|
|
199
|
+
return ok(parseInt(match[1], 10));
|
|
200
|
+
}
|
|
201
|
+
export function ghMarkPRReady(cwd, repo, prNumber) {
|
|
202
|
+
const result = runGh(["pr", "ready", String(prNumber), "--repo", repo], cwd);
|
|
203
|
+
if (!result.ok)
|
|
204
|
+
return fail(result.error);
|
|
205
|
+
return ok(undefined);
|
|
206
|
+
}
|
|
207
|
+
export function ghMergePR(cwd, repo, prNumber, strategy = "squash") {
|
|
208
|
+
const args = [
|
|
209
|
+
"pr", "merge", String(prNumber),
|
|
210
|
+
"--repo", repo,
|
|
211
|
+
strategy === "squash" ? "--squash" : "--merge",
|
|
212
|
+
"--delete-branch",
|
|
213
|
+
];
|
|
214
|
+
const result = runGh(args, cwd);
|
|
215
|
+
if (!result.ok)
|
|
216
|
+
return fail(result.error);
|
|
217
|
+
return ok(undefined);
|
|
218
|
+
}
|
|
219
|
+
// ─── Projects v2 ────────────────────────────────────────────────────────────
|
|
220
|
+
export function ghAddToProject(cwd, repo, projectNumber, issueNumber) {
|
|
221
|
+
// Get the issue's node ID first
|
|
222
|
+
const issueResult = runGhJson(["api", `repos/${repo}/issues/${issueNumber}`, "--jq", "{id: .node_id}"], cwd);
|
|
223
|
+
if (!issueResult.ok)
|
|
224
|
+
return fail(issueResult.error);
|
|
225
|
+
// Get the project's node ID
|
|
226
|
+
const [owner] = repo.split("/");
|
|
227
|
+
const projectResult = runGhJson([
|
|
228
|
+
"api", "graphql",
|
|
229
|
+
"-f", `query=query { user(login: "${owner}") { projectV2(number: ${projectNumber}) { id } } }`,
|
|
230
|
+
"--jq", ".data.user.projectV2.id",
|
|
231
|
+
], cwd);
|
|
232
|
+
// Try org if user fails
|
|
233
|
+
let projectId;
|
|
234
|
+
if (projectResult.ok && projectResult.data?.id) {
|
|
235
|
+
projectId = projectResult.data.id;
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
const orgResult = runGhJson([
|
|
239
|
+
"api", "graphql",
|
|
240
|
+
"-f", `query=query { organization(login: "${owner}") { projectV2(number: ${projectNumber}) { id } } }`,
|
|
241
|
+
"--jq", ".data.organization.projectV2.id",
|
|
242
|
+
], cwd);
|
|
243
|
+
if (orgResult.ok)
|
|
244
|
+
projectId = orgResult.data?.id;
|
|
245
|
+
}
|
|
246
|
+
if (!projectId)
|
|
247
|
+
return fail("Could not find project");
|
|
248
|
+
const mutation = `mutation { addProjectV2ItemById(input: { projectId: "${projectId}", contentId: "${issueResult.data.id}" }) { item { id } } }`;
|
|
249
|
+
return runGh(["api", "graphql", "-f", `query=${mutation}`], cwd);
|
|
250
|
+
}
|
|
251
|
+
// ─── Branch Operations ──────────────────────────────────────────────────────
|
|
252
|
+
export function ghPushBranch(cwd, branch, setUpstream = true) {
|
|
253
|
+
const args = ["git", "push"];
|
|
254
|
+
if (setUpstream)
|
|
255
|
+
args.push("-u", "origin", branch);
|
|
256
|
+
else
|
|
257
|
+
args.push("origin", branch);
|
|
258
|
+
try {
|
|
259
|
+
execFileSync(args[0], args.slice(1), {
|
|
260
|
+
cwd,
|
|
261
|
+
encoding: "utf-8",
|
|
262
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
263
|
+
timeout: 30_000,
|
|
264
|
+
});
|
|
265
|
+
return ok(undefined);
|
|
266
|
+
}
|
|
267
|
+
catch (err) {
|
|
268
|
+
return fail(err instanceof Error ? err.message : String(err));
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export function ghCreateBranch(cwd, branch, from) {
|
|
272
|
+
try {
|
|
273
|
+
execFileSync("git", ["branch", branch, from], {
|
|
274
|
+
cwd,
|
|
275
|
+
encoding: "utf-8",
|
|
276
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
277
|
+
timeout: 10_000,
|
|
278
|
+
});
|
|
279
|
+
return ok(undefined);
|
|
280
|
+
}
|
|
281
|
+
catch (err) {
|
|
282
|
+
return fail(err instanceof Error ? err.message : String(err));
|
|
283
|
+
}
|
|
284
|
+
}
|