@glrs-dev/cli 0.3.1 → 1.0.1

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.
Files changed (28) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/README.md +23 -12
  3. package/dist/vendor/harness-opencode/dist/agents/prompts/pilot-builder.md +18 -3
  4. package/dist/vendor/harness-opencode/dist/agents/prompts/pilot-planner.md +19 -9
  5. package/dist/vendor/harness-opencode/dist/chunk-57EOY72Y.js +174 -0
  6. package/dist/vendor/harness-opencode/dist/chunk-5TAMY7P6.js +67 -0
  7. package/dist/vendor/harness-opencode/dist/chunk-BKTFWXLG.js +204 -0
  8. package/dist/vendor/harness-opencode/dist/chunk-KB7M7JXU.js +145 -0
  9. package/dist/vendor/harness-opencode/dist/chunk-RNRCXQ65.js +56 -0
  10. package/dist/vendor/harness-opencode/dist/cli.js +955 -1453
  11. package/dist/vendor/harness-opencode/dist/index.js +1 -1
  12. package/dist/vendor/harness-opencode/dist/paths-LT3QQKCF.js +18 -0
  13. package/dist/vendor/harness-opencode/dist/pilot/mcp/status-server.d.ts +1 -0
  14. package/dist/vendor/harness-opencode/dist/pilot/mcp/status-server.js +228 -0
  15. package/dist/vendor/harness-opencode/dist/pilot-config-7LJZ23YK.js +55 -0
  16. package/dist/vendor/harness-opencode/dist/runs-QWPL3TKV.js +18 -0
  17. package/dist/vendor/harness-opencode/dist/safety-gate-WM3EWOCY.js +10 -0
  18. package/dist/vendor/harness-opencode/dist/setup-hook-FHTXMAQL.js +88 -0
  19. package/dist/vendor/harness-opencode/dist/skills/adr/SKILL.md +328 -0
  20. package/dist/vendor/harness-opencode/dist/skills/pilot-planning/SKILL.md +40 -13
  21. package/dist/vendor/harness-opencode/dist/skills/pilot-planning/rules/decomposition.md +27 -0
  22. package/dist/vendor/harness-opencode/dist/skills/pilot-planning/rules/self-review.md +1 -1
  23. package/dist/vendor/harness-opencode/dist/skills/pilot-planning/rules/touches-scope.md +34 -0
  24. package/dist/vendor/harness-opencode/dist/skills/pilot-planning/rules/verify-design.md +78 -14
  25. package/dist/vendor/harness-opencode/dist/tasks-KJ3WN2KY.js +32 -0
  26. package/dist/vendor/harness-opencode/package.json +1 -1
  27. package/package.json +1 -1
  28. package/dist/vendor/harness-opencode/dist/skills/pilot-planning/rules/setup-authoring.md +0 -68
@@ -0,0 +1,145 @@
1
+ // src/pilot/worker/safety-gate.ts
2
+ import { execFile } from "child_process";
3
+ import { promisify } from "util";
4
+ import picomatch from "picomatch";
5
+ var execFileP = promisify(execFile);
6
+ var SAFETY_GATE_TOLERATE = [
7
+ // opencode plugin installer churn. opencode upgrades its own plugin
8
+ // dependency in the background, which bumps the pinned version in
9
+ // .opencode/package.json + .opencode/package-lock.json. Users don't
10
+ // author those edits; refusing to start pilot because of them is a
11
+ // consistent friction.
12
+ ".opencode/**",
13
+ // Next.js — `next build` regenerates this every run, often outside
14
+ // a pilot session.
15
+ "**/next-env.d.ts",
16
+ // Next.js app-router generated types.
17
+ "**/.next/types/**",
18
+ "**/.next/dev/types/**",
19
+ // TypeScript project-reference build info — tsc writes these.
20
+ "**/*.tsbuildinfo",
21
+ // Snapshot test files rewritten by `vitest -u` / `jest -u`.
22
+ "**/__snapshots__/**",
23
+ "**/*.snap"
24
+ ];
25
+ async function git(cwd, args) {
26
+ for (const a of args) {
27
+ if (a.includes("\0")) {
28
+ throw new Error(`git arg contains null byte: ${JSON.stringify(a)}`);
29
+ }
30
+ }
31
+ try {
32
+ const { stdout, stderr } = await execFileP("git", args, {
33
+ cwd,
34
+ timeout: 1e4,
35
+ maxBuffer: 1 << 20
36
+ });
37
+ return { stdout: stdout.toString(), stderr: stderr.toString(), ok: true };
38
+ } catch (err) {
39
+ const e = err;
40
+ return {
41
+ stdout: (e.stdout ?? "").toString(),
42
+ stderr: (e.stderr ?? "").toString(),
43
+ ok: false
44
+ };
45
+ }
46
+ }
47
+ async function headSha(cwd) {
48
+ const r = await git(cwd, ["rev-parse", "HEAD"]);
49
+ if (!r.ok) throw new Error(`git rev-parse HEAD failed: ${r.stderr.trim()}`);
50
+ return r.stdout.trim();
51
+ }
52
+ var FORBIDDEN_BRANCHES = /* @__PURE__ */ new Set(["main", "master"]);
53
+ function parsePorcelainPaths(stdout) {
54
+ const paths = [];
55
+ for (const line of stdout.split("\n")) {
56
+ if (line.length < 4) continue;
57
+ let rest = line.slice(3);
58
+ const arrow = rest.indexOf(" -> ");
59
+ if (arrow !== -1) rest = rest.slice(arrow + 4);
60
+ if (rest.startsWith('"') && rest.endsWith('"')) {
61
+ rest = rest.slice(1, -1);
62
+ }
63
+ paths.push(rest);
64
+ }
65
+ return paths;
66
+ }
67
+ async function checkCwdSafety(cwd) {
68
+ const inside = await git(cwd, ["rev-parse", "--is-inside-work-tree"]);
69
+ if (!inside.ok || inside.stdout.trim() !== "true") {
70
+ return {
71
+ ok: false,
72
+ reason: `not inside a git worktree: ${cwd}`
73
+ };
74
+ }
75
+ const branchRes = await git(cwd, ["rev-parse", "--abbrev-ref", "HEAD"]);
76
+ if (!branchRes.ok) {
77
+ return {
78
+ ok: false,
79
+ reason: `cannot determine current branch: ${branchRes.stderr.trim()}`
80
+ };
81
+ }
82
+ const branch = branchRes.stdout.trim();
83
+ if (FORBIDDEN_BRANCHES.has(branch)) {
84
+ return {
85
+ ok: false,
86
+ reason: `refuse to run on protected branch: ${branch}. Switch to a feature branch first.`
87
+ };
88
+ }
89
+ const defaultRes = await git(cwd, [
90
+ "symbolic-ref",
91
+ "--short",
92
+ "refs/remotes/origin/HEAD"
93
+ ]);
94
+ if (defaultRes.ok) {
95
+ const remoteDefault = defaultRes.stdout.trim().replace(/^origin\//, "");
96
+ if (remoteDefault && branch === remoteDefault) {
97
+ return {
98
+ ok: false,
99
+ reason: `refuse to run on the remote's default branch: ${branch}. Switch to a feature branch first.`
100
+ };
101
+ }
102
+ }
103
+ const statusRes = await git(cwd, ["status", "--porcelain"]);
104
+ if (!statusRes.ok) {
105
+ return {
106
+ ok: false,
107
+ reason: `git status failed: ${statusRes.stderr.trim()}`
108
+ };
109
+ }
110
+ const rawStdout = statusRes.stdout.replace(/\n$/, "");
111
+ if (rawStdout.length === 0) {
112
+ return { ok: true, warnings: [] };
113
+ }
114
+ const paths = parsePorcelainPaths(rawStdout);
115
+ const matchTolerate = picomatch([...SAFETY_GATE_TOLERATE], { dot: true });
116
+ const tolerated = [];
117
+ const genuine = [];
118
+ for (const p of paths) {
119
+ if (matchTolerate(p)) tolerated.push(p);
120
+ else genuine.push(p);
121
+ }
122
+ if (genuine.length > 0) {
123
+ const lines = rawStdout.split("\n").slice(0, 10).map((s) => " " + s).join("\n");
124
+ return {
125
+ ok: false,
126
+ reason: `working tree is dirty; pilot refuses to run on uncommitted changes.
127
+ Commit, stash, or discard them, then re-run.
128
+ First 10 lines of git status --porcelain:
129
+ ${lines}`
130
+ };
131
+ }
132
+ const preview = tolerated.slice(0, 5);
133
+ const suffix = tolerated.length > preview.length ? ` (+${tolerated.length - preview.length} more)` : "";
134
+ const warnings = [
135
+ `working tree has ${tolerated.length} modified file(s) in framework-owned paths; treating tree as clean:
136
+ ` + preview.map((p) => ` ${p}`).join("\n") + suffix
137
+ ];
138
+ return { ok: true, warnings };
139
+ }
140
+
141
+ export {
142
+ SAFETY_GATE_TOLERATE,
143
+ headSha,
144
+ checkCwdSafety
145
+ };
@@ -0,0 +1,56 @@
1
+ // src/pilot/mcp/session-registry.ts
2
+ import * as fs from "fs";
3
+ import * as path from "path";
4
+ import { promisify } from "util";
5
+ var writeFile2 = promisify(fs.writeFile);
6
+ var rename2 = promisify(fs.rename);
7
+ var unlink2 = promisify(fs.unlink);
8
+ var mkdir2 = promisify(fs.mkdir);
9
+ function getSessionsPath(runDir) {
10
+ return path.join(runDir, "sessions.json");
11
+ }
12
+ function readSessions(runDir) {
13
+ const sessionsPath = getSessionsPath(runDir);
14
+ try {
15
+ const content = fs.readFileSync(sessionsPath, "utf8");
16
+ const parsed = JSON.parse(content);
17
+ if (typeof parsed !== "object" || parsed === null) {
18
+ return {};
19
+ }
20
+ return parsed;
21
+ } catch {
22
+ return {};
23
+ }
24
+ }
25
+ async function registerSession(args) {
26
+ const { runDir, sessionId, runId, taskId } = args;
27
+ const sessionsPath = getSessionsPath(runDir);
28
+ await mkdir2(runDir, { recursive: true });
29
+ const current = readSessions(runDir);
30
+ const updated = {
31
+ ...current,
32
+ [sessionId]: { runId, taskId }
33
+ };
34
+ const tempPath = `${sessionsPath}.tmp.${process.pid}.${Math.random().toString(36).slice(2, 8)}`;
35
+ await writeFile2(tempPath, JSON.stringify(updated, null, 2), "utf8");
36
+ await rename2(tempPath, sessionsPath);
37
+ }
38
+ async function unregisterSession(args) {
39
+ const { runDir, sessionId } = args;
40
+ const sessionsPath = getSessionsPath(runDir);
41
+ const current = readSessions(runDir);
42
+ if (!(sessionId in current)) {
43
+ return;
44
+ }
45
+ const { [sessionId]: _, ...rest } = current;
46
+ const tempPath = `${sessionsPath}.tmp.${process.pid}.${Math.random().toString(36).slice(2, 8)}`;
47
+ await writeFile2(tempPath, JSON.stringify(rest, null, 2), "utf8");
48
+ await rename2(tempPath, sessionsPath);
49
+ }
50
+
51
+ export {
52
+ getSessionsPath,
53
+ readSessions,
54
+ registerSession,
55
+ unregisterSession
56
+ };