@workit-dev/opencode 2.14.0 → 2.15.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/dist/plugin.js +341 -172
- package/package.json +2 -2
package/dist/plugin.js
CHANGED
|
@@ -28249,11 +28249,12 @@ var FLAGS = {
|
|
|
28249
28249
|
var CLAUDE_CODE_DESCRIPTOR = {
|
|
28250
28250
|
host: "claude_code",
|
|
28251
28251
|
label: "Claude Code",
|
|
28252
|
-
verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary)",
|
|
28252
|
+
verifiedAgainst: "claude 2.1.288 (hook zod schemas in the binary; SessionEnd: 2.1.327)",
|
|
28253
28253
|
docs: ["https://code.claude.com/docs/en/hooks"],
|
|
28254
28254
|
transport: "hook-process",
|
|
28255
28255
|
events: {
|
|
28256
28256
|
"session.start": { support: "native", native: "SessionStart" },
|
|
28257
|
+
"session.end": { support: "native", native: "SessionEnd" },
|
|
28257
28258
|
"context.turn": { support: "native", native: "UserPromptSubmit" },
|
|
28258
28259
|
"shell.pre": { support: "native", native: "PreToolUse" },
|
|
28259
28260
|
"tool.pre": { support: "native", native: "PreToolUse" },
|
|
@@ -28363,6 +28364,7 @@ var CODEX_DESCRIPTOR = {
|
|
|
28363
28364
|
transport: "hook-process",
|
|
28364
28365
|
events: {
|
|
28365
28366
|
"session.start": { support: "native", native: "SessionStart" },
|
|
28367
|
+
"session.end": { support: "none", native: null },
|
|
28366
28368
|
"context.turn": { support: "native", native: "UserPromptSubmit" },
|
|
28367
28369
|
"shell.pre": { support: "native", native: "PreToolUse" },
|
|
28368
28370
|
"tool.pre": { support: "native", native: "PreToolUse" },
|
|
@@ -28473,6 +28475,7 @@ var CURSOR_DESCRIPTOR = {
|
|
|
28473
28475
|
transport: "hook-process",
|
|
28474
28476
|
events: {
|
|
28475
28477
|
"session.start": { support: "native", native: "sessionStart" },
|
|
28478
|
+
"session.end": { support: "native", native: "sessionEnd" },
|
|
28476
28479
|
"context.turn": none,
|
|
28477
28480
|
"shell.pre": { support: "native", native: "beforeShellExecution" },
|
|
28478
28481
|
"tool.pre": { support: "native", native: "preToolUse" },
|
|
@@ -28579,6 +28582,7 @@ var OPENCODE_DESCRIPTOR = {
|
|
|
28579
28582
|
transport: "in-process-plugin",
|
|
28580
28583
|
events: {
|
|
28581
28584
|
"session.start": { support: "none", native: null },
|
|
28585
|
+
"session.end": { support: "partial", native: 'event("session.deleted")' },
|
|
28582
28586
|
"context.turn": { support: "native", native: 'session.hook("context")' },
|
|
28583
28587
|
"shell.pre": { support: "native", native: 'permission.hook("evaluate")' },
|
|
28584
28588
|
"tool.pre": { support: "native", native: 'tool.hook("execute.before")' },
|
|
@@ -28648,6 +28652,7 @@ var PI_DESCRIPTOR = {
|
|
|
28648
28652
|
transport: "in-process-plugin",
|
|
28649
28653
|
events: {
|
|
28650
28654
|
"session.start": { support: "native", native: "session_start" },
|
|
28655
|
+
"session.end": { support: "native", native: "session_shutdown" },
|
|
28651
28656
|
"context.turn": { support: "native", native: "before_agent_start" },
|
|
28652
28657
|
"shell.pre": { support: "native", native: "tool_call" },
|
|
28653
28658
|
"tool.pre": { support: "native", native: "tool_call" },
|
|
@@ -29100,6 +29105,239 @@ function takeProcNotice(session, env = process.env) {
|
|
|
29100
29105
|
}
|
|
29101
29106
|
}
|
|
29102
29107
|
|
|
29108
|
+
// packages/workit-core/src/hooks/teardown.ts
|
|
29109
|
+
import { spawn } from "node:child_process";
|
|
29110
|
+
import fs31 from "node:fs";
|
|
29111
|
+
import path46 from "node:path";
|
|
29112
|
+
|
|
29113
|
+
// packages/workit-core/src/core/cli-locate.ts
|
|
29114
|
+
import { closeSync as closeSync3, existsSync as existsSync16, openSync as openSync3, readSync } from "node:fs";
|
|
29115
|
+
import path45 from "node:path";
|
|
29116
|
+
var LAUNCHER_MARKER = "workit-owned-launcher";
|
|
29117
|
+
var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
|
|
29118
|
+
var installRoot = (env, platform = process.platform) => {
|
|
29119
|
+
if (env.WORKIT_INSTALL_ROOT)
|
|
29120
|
+
return env.WORKIT_INSTALL_ROOT;
|
|
29121
|
+
const data = dataDir(env, platform);
|
|
29122
|
+
return platform === "win32" ? path45.join(data, "install") : data;
|
|
29123
|
+
};
|
|
29124
|
+
var ownedLauncherPath = (env, platform = process.platform) => path45.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
|
|
29125
|
+
var ownedCurrentEntry = (env, platform = process.platform) => path45.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
|
|
29126
|
+
var head = (file) => {
|
|
29127
|
+
let fd;
|
|
29128
|
+
try {
|
|
29129
|
+
fd = openSync3(file, "r");
|
|
29130
|
+
const buffer = Buffer.alloc(256);
|
|
29131
|
+
const read = readSync(fd, buffer, 0, buffer.length, 0);
|
|
29132
|
+
return buffer.subarray(0, read).toString("utf8");
|
|
29133
|
+
} catch {
|
|
29134
|
+
return "";
|
|
29135
|
+
} finally {
|
|
29136
|
+
if (fd !== undefined)
|
|
29137
|
+
closeSync3(fd);
|
|
29138
|
+
}
|
|
29139
|
+
};
|
|
29140
|
+
var locateWorkitCli = (options = {}) => {
|
|
29141
|
+
const env = options.env ?? process.env;
|
|
29142
|
+
const platform = options.platform ?? process.platform;
|
|
29143
|
+
const exists = options.exists ?? existsSync16;
|
|
29144
|
+
const read = options.read ?? head;
|
|
29145
|
+
const node = options.node ?? process.execPath;
|
|
29146
|
+
const launcher = ownedLauncherPath(env, platform);
|
|
29147
|
+
if (exists(launcher) && read(launcher).includes(LAUNCHER_MARKER))
|
|
29148
|
+
return {
|
|
29149
|
+
source: "owned-launcher",
|
|
29150
|
+
command: launcher,
|
|
29151
|
+
args: [],
|
|
29152
|
+
binDir: path45.dirname(launcher)
|
|
29153
|
+
};
|
|
29154
|
+
const current = ownedCurrentEntry(env, platform);
|
|
29155
|
+
if (exists(current))
|
|
29156
|
+
return {
|
|
29157
|
+
source: "owned-current",
|
|
29158
|
+
command: node,
|
|
29159
|
+
args: [current],
|
|
29160
|
+
binDir: null
|
|
29161
|
+
};
|
|
29162
|
+
if (options.bundled && exists(options.bundled))
|
|
29163
|
+
return {
|
|
29164
|
+
source: "bundled",
|
|
29165
|
+
command: node,
|
|
29166
|
+
args: [options.bundled],
|
|
29167
|
+
binDir: null
|
|
29168
|
+
};
|
|
29169
|
+
return { source: "path", command: "workit", args: [], binDir: null };
|
|
29170
|
+
};
|
|
29171
|
+
var pathKey = (env) => Object.keys(env).find((key) => key.toUpperCase() === "PATH") ?? "PATH";
|
|
29172
|
+
var workitCliEnv = (located, env = process.env, platform = process.platform) => {
|
|
29173
|
+
if (located.source === "path")
|
|
29174
|
+
return {};
|
|
29175
|
+
const patch = {
|
|
29176
|
+
WORKIT_CLI: [located.command, ...located.args].join(" ")
|
|
29177
|
+
};
|
|
29178
|
+
if (located.binDir) {
|
|
29179
|
+
const key = pathKey(env);
|
|
29180
|
+
const delimiter = platform === "win32" ? ";" : ":";
|
|
29181
|
+
const same = (dir) => platform === "win32" ? path45.win32.normalize(dir).toLowerCase() === path45.win32.normalize(located.binDir).toLowerCase() : path45.posix.normalize(dir) === path45.posix.normalize(located.binDir);
|
|
29182
|
+
const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
|
|
29183
|
+
patch[key] = [located.binDir, ...rest].join(delimiter);
|
|
29184
|
+
}
|
|
29185
|
+
return patch;
|
|
29186
|
+
};
|
|
29187
|
+
var useOwnedWorkitCli = (options = {}) => {
|
|
29188
|
+
const env = options.env ?? process.env;
|
|
29189
|
+
const located = locateWorkitCli({ ...options, env });
|
|
29190
|
+
Object.assign(env, workitCliEnv(located, env, options.platform));
|
|
29191
|
+
return located;
|
|
29192
|
+
};
|
|
29193
|
+
|
|
29194
|
+
// packages/workit-core/src/hooks/teardown.ts
|
|
29195
|
+
var REAP_INTERVAL_MS = 10 * 60000;
|
|
29196
|
+
var LOG_MAX_BYTES = 1 << 20;
|
|
29197
|
+
var ENDS = {
|
|
29198
|
+
claude_code: new Set(["logout", "prompt_input_exit", "other"]),
|
|
29199
|
+
cursor: new Set(["completed", "aborted", "error", "window_close", "user_close"]),
|
|
29200
|
+
pi: new Set(["quit"]),
|
|
29201
|
+
opencode: new Set(["deleted"])
|
|
29202
|
+
};
|
|
29203
|
+
var SAFE_SESSION = /^[\w.@+][\w.:@/+-]{0,127}$/u;
|
|
29204
|
+
var HOST_SESSION_VARS2 = ["OPENCODE_SESSION_ID", "PI_SESSION_ID", "CODEX_THREAD_ID"];
|
|
29205
|
+
var teardownDir = (env) => path46.join(stateDir(env), "procs");
|
|
29206
|
+
var teardownLog = (env) => path46.join(teardownDir(env), "teardown.log");
|
|
29207
|
+
var reapStamp = (env) => path46.join(teardownDir(env), "reap-at-start.stamp");
|
|
29208
|
+
function spawnDetached(request) {
|
|
29209
|
+
try {
|
|
29210
|
+
const shell = process.platform === "win32" && !/\.exe$/iu.test(request.command);
|
|
29211
|
+
const line = [`"${request.command}"`, ...request.args].join(" ");
|
|
29212
|
+
const child = spawn(shell ? line : request.command, shell ? [] : request.args, {
|
|
29213
|
+
cwd: request.cwd,
|
|
29214
|
+
env: request.env,
|
|
29215
|
+
detached: true,
|
|
29216
|
+
shell,
|
|
29217
|
+
stdio: ["ignore", request.log ?? "ignore", request.log ?? "ignore"],
|
|
29218
|
+
windowsHide: true
|
|
29219
|
+
});
|
|
29220
|
+
child.on("error", () => {});
|
|
29221
|
+
child.unref();
|
|
29222
|
+
return child.pid !== undefined;
|
|
29223
|
+
} catch {
|
|
29224
|
+
return false;
|
|
29225
|
+
}
|
|
29226
|
+
}
|
|
29227
|
+
var teardownDeps = {
|
|
29228
|
+
spawn: (request) => request.env.WORKIT_TEST_RUN === undefined && spawnDetached(request),
|
|
29229
|
+
now: () => Date.now()
|
|
29230
|
+
};
|
|
29231
|
+
var openLog = (env, args) => {
|
|
29232
|
+
try {
|
|
29233
|
+
const file = teardownLog(env);
|
|
29234
|
+
fs31.mkdirSync(path46.dirname(file), { recursive: true });
|
|
29235
|
+
let size = 0;
|
|
29236
|
+
try {
|
|
29237
|
+
size = fs31.statSync(file).size;
|
|
29238
|
+
} catch {}
|
|
29239
|
+
const fd = fs31.openSync(file, size > LOG_MAX_BYTES ? "w" : "a", 384);
|
|
29240
|
+
fs31.writeSync(fd, `${new Date(teardownDeps.now()).toISOString()} workit ${args.join(" ")}
|
|
29241
|
+
`);
|
|
29242
|
+
return fd;
|
|
29243
|
+
} catch {
|
|
29244
|
+
return null;
|
|
29245
|
+
}
|
|
29246
|
+
};
|
|
29247
|
+
function runCli(args, env, cwd) {
|
|
29248
|
+
let log = null;
|
|
29249
|
+
try {
|
|
29250
|
+
const cli = locateWorkitCli({ env });
|
|
29251
|
+
log = openLog(env, args);
|
|
29252
|
+
const started = teardownDeps.spawn({
|
|
29253
|
+
command: cli.command,
|
|
29254
|
+
args: [...cli.args, ...args],
|
|
29255
|
+
env,
|
|
29256
|
+
cwd: fs31.existsSync(cwd) ? cwd : teardownDir(env),
|
|
29257
|
+
log
|
|
29258
|
+
});
|
|
29259
|
+
if (!started && log !== null)
|
|
29260
|
+
fs31.writeSync(log, ` not started
|
|
29261
|
+
`);
|
|
29262
|
+
return started;
|
|
29263
|
+
} catch {
|
|
29264
|
+
return false;
|
|
29265
|
+
} finally {
|
|
29266
|
+
if (log !== null)
|
|
29267
|
+
try {
|
|
29268
|
+
fs31.closeSync(log);
|
|
29269
|
+
} catch {}
|
|
29270
|
+
}
|
|
29271
|
+
}
|
|
29272
|
+
function endSession(end, env = process.env) {
|
|
29273
|
+
const session = end.session?.trim() ?? "";
|
|
29274
|
+
if (!SAFE_SESSION.test(session) || !ENDS[end.host]?.has(end.reason ?? ""))
|
|
29275
|
+
return false;
|
|
29276
|
+
const outer = env.WORKIT_SESSION_ID?.trim();
|
|
29277
|
+
if (end.agentId || env.WORKIT_PI_WORKER_SESSION || leadOf(session) !== session || outer && leadOf(outer) !== outer)
|
|
29278
|
+
return false;
|
|
29279
|
+
const child = { ...env, WORKIT_SESSION_ID: session, WORKIT_HOST: end.host };
|
|
29280
|
+
for (const key of HOST_SESSION_VARS2)
|
|
29281
|
+
delete child[key];
|
|
29282
|
+
return runCli(["stop", "--session", session, "--reason", "session-end"], child, end.cwd);
|
|
29283
|
+
}
|
|
29284
|
+
var claim2 = (file, now) => {
|
|
29285
|
+
for (let attempt = 0;attempt < 2; attempt += 1)
|
|
29286
|
+
try {
|
|
29287
|
+
fs31.writeFileSync(file, String(now), { flag: "wx", mode: 384 });
|
|
29288
|
+
return true;
|
|
29289
|
+
} catch (error) {
|
|
29290
|
+
if (error.code !== "EEXIST")
|
|
29291
|
+
return false;
|
|
29292
|
+
let held = Number.NaN;
|
|
29293
|
+
try {
|
|
29294
|
+
held = Number(fs31.readFileSync(file, "utf8"));
|
|
29295
|
+
} catch {}
|
|
29296
|
+
if (now - held < REAP_INTERVAL_MS)
|
|
29297
|
+
return false;
|
|
29298
|
+
fs31.rmSync(file, { force: true });
|
|
29299
|
+
}
|
|
29300
|
+
return false;
|
|
29301
|
+
};
|
|
29302
|
+
var fresh = (stamp, now) => {
|
|
29303
|
+
try {
|
|
29304
|
+
const last = Number(fs31.readFileSync(stamp, "utf8"));
|
|
29305
|
+
return now - last < REAP_INTERVAL_MS && last <= now;
|
|
29306
|
+
} catch {
|
|
29307
|
+
return false;
|
|
29308
|
+
}
|
|
29309
|
+
};
|
|
29310
|
+
function reapAtStart(cwd, env = process.env) {
|
|
29311
|
+
const stamp = reapStamp(env);
|
|
29312
|
+
const lock = `${stamp}.claim`;
|
|
29313
|
+
const now = teardownDeps.now();
|
|
29314
|
+
try {
|
|
29315
|
+
if (fresh(stamp, now))
|
|
29316
|
+
return false;
|
|
29317
|
+
fs31.mkdirSync(path46.dirname(stamp), { recursive: true });
|
|
29318
|
+
if (!claim2(lock, now))
|
|
29319
|
+
return false;
|
|
29320
|
+
} catch {
|
|
29321
|
+
return false;
|
|
29322
|
+
}
|
|
29323
|
+
let started = false;
|
|
29324
|
+
try {
|
|
29325
|
+
if (fresh(stamp, now))
|
|
29326
|
+
return false;
|
|
29327
|
+
started = runCli(["stop", "--orphans", "--reason", "session-start"], env, cwd);
|
|
29328
|
+
if (started) {
|
|
29329
|
+
const temp = `${stamp}.${process.pid}`;
|
|
29330
|
+
fs31.writeFileSync(temp, String(now), { mode: 384 });
|
|
29331
|
+
fs31.renameSync(temp, stamp);
|
|
29332
|
+
}
|
|
29333
|
+
} catch {} finally {
|
|
29334
|
+
try {
|
|
29335
|
+
fs31.rmSync(lock, { force: true });
|
|
29336
|
+
} catch {}
|
|
29337
|
+
}
|
|
29338
|
+
return started;
|
|
29339
|
+
}
|
|
29340
|
+
|
|
29103
29341
|
// packages/workit-core/src/hooks/ytrack-word.ts
|
|
29104
29342
|
var YTRACK_WORD = /ytrack(?![\w/-]|\.(?!exe|cmd))/i;
|
|
29105
29343
|
var namesYtrack = (text) => {
|
|
@@ -29606,11 +29844,11 @@ var PROCESS_START = performance.timeOrigin;
|
|
|
29606
29844
|
// packages/workit-core/src/hooks/run.ts
|
|
29607
29845
|
if (false) {}
|
|
29608
29846
|
// packages/workit-opencode/src/shared/init-apply.ts
|
|
29609
|
-
import
|
|
29847
|
+
import path51 from "node:path";
|
|
29610
29848
|
|
|
29611
29849
|
// packages/workit-core/src/core/gitignore.ts
|
|
29612
|
-
import { existsSync as
|
|
29613
|
-
import
|
|
29850
|
+
import { existsSync as existsSync17, readFileSync as readFileSync13, writeFileSync as writeFileSync5 } from "node:fs";
|
|
29851
|
+
import path47 from "node:path";
|
|
29614
29852
|
var GITIGNORE_ENTRIES = [
|
|
29615
29853
|
"# workit: SDD working state (never commit)",
|
|
29616
29854
|
"docs/*/sdd/",
|
|
@@ -29630,8 +29868,8 @@ var GITIGNORE_ENTRIES = [
|
|
|
29630
29868
|
var ensureProjectGitignore = (workspaceRoot, confirmed) => {
|
|
29631
29869
|
if (!confirmed)
|
|
29632
29870
|
return { ok: false, error: "confirmed: true required" };
|
|
29633
|
-
const file =
|
|
29634
|
-
const existing =
|
|
29871
|
+
const file = path47.join(workspaceRoot, ".gitignore");
|
|
29872
|
+
const existing = existsSync17(file) ? readFileSync13(file, "utf8") : "";
|
|
29635
29873
|
const existingLines = new Set(existing.split(`
|
|
29636
29874
|
`).map((l) => l.trim()).filter(Boolean));
|
|
29637
29875
|
const added = [];
|
|
@@ -29650,33 +29888,33 @@ var ensureProjectGitignore = (workspaceRoot, confirmed) => {
|
|
|
29650
29888
|
` : "") + append.join(`
|
|
29651
29889
|
`) + `
|
|
29652
29890
|
`, "utf8");
|
|
29653
|
-
} else if (!
|
|
29891
|
+
} else if (!existsSync17(file)) {
|
|
29654
29892
|
writeFileSync5(file, "", "utf8");
|
|
29655
29893
|
}
|
|
29656
29894
|
return { ok: true, path: file, added };
|
|
29657
29895
|
};
|
|
29658
29896
|
|
|
29659
29897
|
// packages/workit-core/src/core/hygiene.ts
|
|
29660
|
-
import { existsSync as
|
|
29661
|
-
import
|
|
29898
|
+
import { existsSync as existsSync18, readFileSync as readFileSync14, readdirSync as readdirSync6, writeFileSync as writeFileSync6 } from "node:fs";
|
|
29899
|
+
import path48 from "node:path";
|
|
29662
29900
|
var repoRoot3 = assetRoot();
|
|
29663
|
-
var templatesDir = () =>
|
|
29901
|
+
var templatesDir = () => path48.join(repoRoot3, "templates", "hygiene");
|
|
29664
29902
|
var packageJson = (root) => {
|
|
29665
|
-
if (!
|
|
29903
|
+
if (!existsSync18(path48.join(root, "package.json")))
|
|
29666
29904
|
return null;
|
|
29667
29905
|
try {
|
|
29668
|
-
return JSON.parse(readFileSync14(
|
|
29906
|
+
return JSON.parse(readFileSync14(path48.join(root, "package.json"), "utf8"));
|
|
29669
29907
|
} catch {
|
|
29670
29908
|
return null;
|
|
29671
29909
|
}
|
|
29672
29910
|
};
|
|
29673
29911
|
var isOpenSource = (root) => {
|
|
29674
|
-
if (
|
|
29912
|
+
if (existsSync18(path48.join(root, "LICENSE")))
|
|
29675
29913
|
return true;
|
|
29676
29914
|
const pkg = packageJson(root);
|
|
29677
29915
|
if (pkg && !pkg.private)
|
|
29678
29916
|
return true;
|
|
29679
|
-
return
|
|
29917
|
+
return path48.basename(root) === "workit";
|
|
29680
29918
|
};
|
|
29681
29919
|
var licenseHolder = (root) => {
|
|
29682
29920
|
const pkg = packageJson(root);
|
|
@@ -29699,13 +29937,13 @@ var planHygieneFiles = (root, opts = {}) => {
|
|
|
29699
29937
|
files.push("LICENSE", "CONTRIBUTING.md");
|
|
29700
29938
|
const planned = [];
|
|
29701
29939
|
for (const file of files) {
|
|
29702
|
-
if (
|
|
29940
|
+
if (existsSync18(path48.join(root, file)))
|
|
29703
29941
|
continue;
|
|
29704
|
-
const tpl =
|
|
29705
|
-
if (!
|
|
29942
|
+
const tpl = path48.join(templatesDir(), file);
|
|
29943
|
+
if (!existsSync18(tpl))
|
|
29706
29944
|
continue;
|
|
29707
|
-
const content = readFileSync14(tpl, "utf8").replace(/<PROJECT>/g,
|
|
29708
|
-
planned.push({ path:
|
|
29945
|
+
const content = readFileSync14(tpl, "utf8").replace(/<PROJECT>/g, path48.basename(root)).replace(/<YEAR>/g, String(new Date().getFullYear())).replace(/<HOLDER>\s*/g, licenseHolder(root));
|
|
29946
|
+
planned.push({ path: path48.join(root, file), content });
|
|
29709
29947
|
}
|
|
29710
29948
|
return planned;
|
|
29711
29949
|
};
|
|
@@ -29715,19 +29953,19 @@ var ensureHygieneFiles = (root, opts) => {
|
|
|
29715
29953
|
const created = [];
|
|
29716
29954
|
for (const planned of planHygieneFiles(root, opts)) {
|
|
29717
29955
|
writeFileSync6(planned.path, planned.content, "utf8");
|
|
29718
|
-
created.push(
|
|
29956
|
+
created.push(path48.basename(planned.path));
|
|
29719
29957
|
}
|
|
29720
29958
|
return { ok: true, created };
|
|
29721
29959
|
};
|
|
29722
29960
|
|
|
29723
29961
|
// packages/workit-core/src/core/init.ts
|
|
29724
|
-
import
|
|
29725
|
-
import
|
|
29962
|
+
import fs32 from "node:fs";
|
|
29963
|
+
import path50 from "node:path";
|
|
29726
29964
|
import { spawnSync as spawnSync25 } from "node:child_process";
|
|
29727
29965
|
|
|
29728
29966
|
// packages/workit-core/src/core/workspace-branch-policy.ts
|
|
29729
29967
|
import { mkdirSync as mkdirSync5, readFileSync as readFileSync15, renameSync as renameSync4, rmSync as rmSync3, writeFileSync as writeFileSync7 } from "node:fs";
|
|
29730
|
-
import
|
|
29968
|
+
import path49 from "node:path";
|
|
29731
29969
|
import { isDeepStrictEqual } from "node:util";
|
|
29732
29970
|
var readFileSafe = (p) => {
|
|
29733
29971
|
try {
|
|
@@ -29738,7 +29976,7 @@ var readFileSafe = (p) => {
|
|
|
29738
29976
|
};
|
|
29739
29977
|
function applyWorkspaceBranchPolicy(opts) {
|
|
29740
29978
|
const { workspace_root, env = process.env } = opts;
|
|
29741
|
-
const dir =
|
|
29979
|
+
const dir = path49.join(env.WORKIT_CONFIG ?? configDir2());
|
|
29742
29980
|
const {
|
|
29743
29981
|
status,
|
|
29744
29982
|
path: wsPath,
|
|
@@ -29750,7 +29988,7 @@ function applyWorkspaceBranchPolicy(opts) {
|
|
|
29750
29988
|
if (status === "malformed" || status === "invalid")
|
|
29751
29989
|
return { ok: false, error: workspacesError ?? `invalid workspaces.json: ${wsPath}` };
|
|
29752
29990
|
const detection = detectBranchPolicy(workspace_root);
|
|
29753
|
-
const name = String(env.WORKIT_BP_NAME ??
|
|
29991
|
+
const name = String(env.WORKIT_BP_NAME ?? path49.basename(workspace_root));
|
|
29754
29992
|
const integration = env.WORKIT_BP_INTEGRATION ?? detection.integration;
|
|
29755
29993
|
const policy = {
|
|
29756
29994
|
preset: detection.preset,
|
|
@@ -29799,7 +30037,7 @@ function applyWorkspaceBranchPolicy(opts) {
|
|
|
29799
30037
|
ok: false,
|
|
29800
30038
|
error: `workspaces.json changed while applying the branch policy: ${wsPath}`
|
|
29801
30039
|
};
|
|
29802
|
-
mkdirSync5(
|
|
30040
|
+
mkdirSync5(path49.dirname(wsPath), { recursive: true });
|
|
29803
30041
|
const tmp = `${wsPath}.${process.pid}.tmp`;
|
|
29804
30042
|
try {
|
|
29805
30043
|
writeFileSync7(tmp, JSON.stringify({ ...document, workspaces: next }, null, 2) + `
|
|
@@ -29833,7 +30071,7 @@ function applyWorkspaceBranchPolicy(opts) {
|
|
|
29833
30071
|
// packages/workit-core/src/core/init.ts
|
|
29834
30072
|
var readJson3 = (p) => {
|
|
29835
30073
|
try {
|
|
29836
|
-
const parsed = JSON.parse(
|
|
30074
|
+
const parsed = JSON.parse(fs32.readFileSync(p, "utf8"));
|
|
29837
30075
|
return isConfigObject(parsed) ? parsed : null;
|
|
29838
30076
|
} catch {
|
|
29839
30077
|
return null;
|
|
@@ -29896,11 +30134,11 @@ var vcsJsonContent = () => {
|
|
|
29896
30134
|
};
|
|
29897
30135
|
function initApplyData(action, env = process.env) {
|
|
29898
30136
|
const dir = String(env.WORKIT_CONFIG ?? configDir2());
|
|
29899
|
-
|
|
30137
|
+
fs32.mkdirSync(dir, { recursive: true });
|
|
29900
30138
|
switch (action) {
|
|
29901
30139
|
case "youtrack_json": {
|
|
29902
|
-
const out =
|
|
29903
|
-
|
|
30140
|
+
const out = path50.join(dir, "youtrack.json");
|
|
30141
|
+
fs32.writeFileSync(out, JSON.stringify(youtrackJsonContent(), null, 2) + `
|
|
29904
30142
|
`, "utf8");
|
|
29905
30143
|
return { action, ok: true, path: out };
|
|
29906
30144
|
}
|
|
@@ -29913,10 +30151,10 @@ function initApplyData(action, env = process.env) {
|
|
|
29913
30151
|
};
|
|
29914
30152
|
}
|
|
29915
30153
|
case "youtrack_scaffold": {
|
|
29916
|
-
const jsonOut =
|
|
29917
|
-
|
|
30154
|
+
const jsonOut = path50.join(dir, "youtrack.json");
|
|
30155
|
+
fs32.writeFileSync(jsonOut, JSON.stringify(youtrackJsonContent(), null, 2) + `
|
|
29918
30156
|
`, "utf8");
|
|
29919
|
-
const configPath =
|
|
30157
|
+
const configPath = path50.resolve(jsonOut);
|
|
29920
30158
|
const cfg = readJson3(configPath) ?? {};
|
|
29921
30159
|
const base = String(cfg.baseUrl ?? "").replace(/\/+$/, "");
|
|
29922
30160
|
const meeting = String(cfg.meetingIssue ?? "");
|
|
@@ -29952,10 +30190,10 @@ function initApplyData(action, env = process.env) {
|
|
|
29952
30190
|
};
|
|
29953
30191
|
}
|
|
29954
30192
|
case "vcs_scaffold": {
|
|
29955
|
-
const jsonOut =
|
|
29956
|
-
|
|
30193
|
+
const jsonOut = path50.join(dir, "vcs.json");
|
|
30194
|
+
fs32.writeFileSync(jsonOut, JSON.stringify(vcsJsonContent(), null, 2) + `
|
|
29957
30195
|
`, "utf8");
|
|
29958
|
-
const configPath =
|
|
30196
|
+
const configPath = path50.resolve(jsonOut);
|
|
29959
30197
|
const prev = process.env.WORKIT_VCS_CONFIG;
|
|
29960
30198
|
process.env.WORKIT_VCS_CONFIG = configPath;
|
|
29961
30199
|
try {
|
|
@@ -30074,7 +30312,7 @@ var executeInitApply = (args, directory, runtime) => {
|
|
|
30074
30312
|
protectedNames: args.branch_policy_protected
|
|
30075
30313
|
}, current);
|
|
30076
30314
|
writeConfig(next);
|
|
30077
|
-
return output(ok({ action: "config", path:
|
|
30315
|
+
return output(ok({ action: "config", path: path51.join(configDir2(), "config.json"), ...next }));
|
|
30078
30316
|
}
|
|
30079
30317
|
const env = Object.fromEntries(Object.entries({
|
|
30080
30318
|
WORKIT_YT_BASE_URL: args.base_url,
|
|
@@ -30091,14 +30329,14 @@ var executeInitApply = (args, directory, runtime) => {
|
|
|
30091
30329
|
|
|
30092
30330
|
// packages/workit-opencode/src/shared/session.ts
|
|
30093
30331
|
import { realpathSync as realpathSync11 } from "node:fs";
|
|
30094
|
-
import
|
|
30332
|
+
import path52 from "node:path";
|
|
30095
30333
|
var sameWorkspace = (expected, observed) => {
|
|
30096
30334
|
if (typeof observed !== "string" || !observed)
|
|
30097
30335
|
return false;
|
|
30098
30336
|
try {
|
|
30099
30337
|
return realpathSync11(expected) === realpathSync11(observed);
|
|
30100
30338
|
} catch {
|
|
30101
|
-
return
|
|
30339
|
+
return path52.resolve(expected) === path52.resolve(observed);
|
|
30102
30340
|
}
|
|
30103
30341
|
};
|
|
30104
30342
|
|
|
@@ -30170,7 +30408,7 @@ var workitFamilyOf = (toolName) => {
|
|
|
30170
30408
|
|
|
30171
30409
|
// packages/workit-opencode/src/tools/context.ts
|
|
30172
30410
|
import { realpathSync as realpathSync12 } from "node:fs";
|
|
30173
|
-
import
|
|
30411
|
+
import path53 from "node:path";
|
|
30174
30412
|
var createContextTool = () => ({
|
|
30175
30413
|
description: "Read Git, pull request, YouTrack, issue, changelog, release, or affected-file context.",
|
|
30176
30414
|
execute: async (args, context) => {
|
|
@@ -30180,7 +30418,7 @@ var createContextTool = () => ({
|
|
|
30180
30418
|
let root;
|
|
30181
30419
|
try {
|
|
30182
30420
|
const cwd = parsed.data.cwd;
|
|
30183
|
-
root = realpathSync12(cwd ?
|
|
30421
|
+
root = realpathSync12(cwd ? path53.resolve(context.directory, cwd) : context.directory);
|
|
30184
30422
|
} catch {
|
|
30185
30423
|
return JSON.stringify(failure2("invalid_input", "context target directory cannot be resolved"), null, 2);
|
|
30186
30424
|
}
|
|
@@ -30212,8 +30450,8 @@ var workerCoordinatorFor = (task, worker) => {
|
|
|
30212
30450
|
// packages/workit-core/src/fanout.ts
|
|
30213
30451
|
import { spawnSync as spawnSync29 } from "node:child_process";
|
|
30214
30452
|
import { createHash as createHash20 } from "node:crypto";
|
|
30215
|
-
import
|
|
30216
|
-
import
|
|
30453
|
+
import fs34 from "node:fs";
|
|
30454
|
+
import path56 from "node:path";
|
|
30217
30455
|
|
|
30218
30456
|
// packages/workit-core/src/fanout-landed.ts
|
|
30219
30457
|
import { spawnSync as spawnSync26 } from "node:child_process";
|
|
@@ -30446,13 +30684,13 @@ var NOTICE_TTL_MS = 7 * 86400000;
|
|
|
30446
30684
|
// packages/workit-core/src/stack.ts
|
|
30447
30685
|
import { spawnSync as spawnSync28 } from "node:child_process";
|
|
30448
30686
|
import { createHash as createHash19, randomBytes as randomBytes4 } from "node:crypto";
|
|
30449
|
-
import
|
|
30450
|
-
import
|
|
30687
|
+
import fs33 from "node:fs";
|
|
30688
|
+
import path55 from "node:path";
|
|
30451
30689
|
|
|
30452
30690
|
// packages/workit-core/src/git/ops.ts
|
|
30453
30691
|
import { spawnSync as spawnSync27 } from "node:child_process";
|
|
30454
|
-
import { copyFileSync as copyFileSync3, existsSync as
|
|
30455
|
-
import
|
|
30692
|
+
import { copyFileSync as copyFileSync3, existsSync as existsSync19, readdirSync as readdirSync7, readFileSync as readFileSync16, rmSync as rmSync4 } from "node:fs";
|
|
30693
|
+
import path54 from "node:path";
|
|
30456
30694
|
var COMMIT_TIMEOUT_MS = 10 * 60000;
|
|
30457
30695
|
var git5 = (cwd, args, options = {}) => {
|
|
30458
30696
|
const result = spawnSync27("git", args, {
|
|
@@ -30485,18 +30723,18 @@ function operationInProgress(cwd) {
|
|
|
30485
30723
|
if (!run.ok)
|
|
30486
30724
|
return null;
|
|
30487
30725
|
const found = run.stdout.split(`
|
|
30488
|
-
`).map((line) =>
|
|
30726
|
+
`).map((line) => path54.resolve(cwd, line.trim()));
|
|
30489
30727
|
const conflicted = () => git5(cwd, ["ls-files", "-u"]).stdout.trim() !== "";
|
|
30490
30728
|
for (const [index, [, operation]] of markers.entries()) {
|
|
30491
30729
|
const marker = found[index];
|
|
30492
|
-
if (!marker || !
|
|
30730
|
+
if (!marker || !existsSync19(marker))
|
|
30493
30731
|
continue;
|
|
30494
|
-
if (index === 1 &&
|
|
30732
|
+
if (index === 1 && existsSync19(path54.join(marker, "applying")))
|
|
30495
30733
|
return { operation: "am", commitAllowed: false, branch: null };
|
|
30496
|
-
if (index === 0 &&
|
|
30734
|
+
if (index === 0 && existsSync19(path54.join(marker, "amend")) && !conflicted()) {
|
|
30497
30735
|
let headName = "";
|
|
30498
30736
|
try {
|
|
30499
|
-
headName = readFileSync16(
|
|
30737
|
+
headName = readFileSync16(path54.join(marker, "head-name"), "utf8").trim();
|
|
30500
30738
|
} catch {}
|
|
30501
30739
|
const branch = headName.startsWith("refs/heads/") ? headName.slice("refs/heads/".length) : null;
|
|
30502
30740
|
return { operation, commitAllowed: branch !== null, branch };
|
|
@@ -30609,7 +30847,7 @@ function rebasingBranch2(dir) {
|
|
|
30609
30847
|
if (!found.ok)
|
|
30610
30848
|
continue;
|
|
30611
30849
|
try {
|
|
30612
|
-
return
|
|
30850
|
+
return fs33.readFileSync(found.stdout.trim(), "utf8").trim();
|
|
30613
30851
|
} catch {}
|
|
30614
30852
|
}
|
|
30615
30853
|
return null;
|
|
@@ -30617,14 +30855,14 @@ function rebasingBranch2(dir) {
|
|
|
30617
30855
|
function rebaseInProgress(dir) {
|
|
30618
30856
|
for (const name of ["rebase-merge", "rebase-apply"]) {
|
|
30619
30857
|
const found = gitRun4(dir, ["rev-parse", "--path-format=absolute", "--git-path", name]);
|
|
30620
|
-
if (found.ok &&
|
|
30858
|
+
if (found.ok && fs33.existsSync(found.stdout.trim()))
|
|
30621
30859
|
return true;
|
|
30622
30860
|
}
|
|
30623
30861
|
return false;
|
|
30624
30862
|
}
|
|
30625
30863
|
var scratchDir = (cwd) => {
|
|
30626
30864
|
const dir = stacksDir(cwd);
|
|
30627
|
-
return dir.ok ?
|
|
30865
|
+
return dir.ok ? path55.join(dir.data, "worktrees") : null;
|
|
30628
30866
|
};
|
|
30629
30867
|
function gitRestack(cwd, input) {
|
|
30630
30868
|
const owner = worktreeOf(cwd, input.branch);
|
|
@@ -30638,8 +30876,8 @@ function gitRestack(cwd, input) {
|
|
|
30638
30876
|
worktree: cwd,
|
|
30639
30877
|
error: "no store root"
|
|
30640
30878
|
};
|
|
30641
|
-
|
|
30642
|
-
dir =
|
|
30879
|
+
fs33.mkdirSync(scratch, { recursive: true });
|
|
30880
|
+
dir = path55.join(scratch, `${input.branch.replace(/[^A-Za-z0-9._-]+/gu, "_").slice(0, 40)}-${randomBytes4(4).toString("hex")}`);
|
|
30643
30881
|
const added = gitRun4(cwd, ["worktree", "add", "-q", dir, input.branch], GIT_TIMEOUTS.worktree);
|
|
30644
30882
|
if (!added.ok)
|
|
30645
30883
|
return {
|
|
@@ -30698,7 +30936,7 @@ function stacksDir(cwd) {
|
|
|
30698
30936
|
const root = storeRoot(cwd);
|
|
30699
30937
|
if (!root.ok)
|
|
30700
30938
|
return stackFail(root.code, root.error, root.unblock);
|
|
30701
|
-
return { ok: true, data:
|
|
30939
|
+
return { ok: true, data: path55.join(root.value.root, "stacks") };
|
|
30702
30940
|
}
|
|
30703
30941
|
var HEARTBEAT_STALE_MS = 2 * 60000;
|
|
30704
30942
|
var SETTLED_BY_RESTACK = new Set(["checks_pending", "behind_base_required"]);
|
|
@@ -30845,7 +31083,7 @@ function fanoutsDir(cwd) {
|
|
|
30845
31083
|
const root = storeRoot(cwd);
|
|
30846
31084
|
if (!root.ok)
|
|
30847
31085
|
return fanoutFail(root.code, root.error, root.unblock);
|
|
30848
|
-
return { ok: true, data:
|
|
31086
|
+
return { ok: true, data: path56.join(root.value.root, "fanouts") };
|
|
30849
31087
|
}
|
|
30850
31088
|
function parseStored(raw) {
|
|
30851
31089
|
if (!isRecord8(raw) || typeof raw.name !== "string" || typeof raw.trunk !== "string")
|
|
@@ -30913,10 +31151,10 @@ function readFanout(cwd, name) {
|
|
|
30913
31151
|
const dir = fanoutsDir(cwd);
|
|
30914
31152
|
if (!dir.ok)
|
|
30915
31153
|
return dir;
|
|
30916
|
-
const file =
|
|
31154
|
+
const file = path56.join(dir.data, stackFileName(name));
|
|
30917
31155
|
let parsed = null;
|
|
30918
31156
|
try {
|
|
30919
|
-
parsed = parseStored(JSON.parse(
|
|
31157
|
+
parsed = parseStored(JSON.parse(fs34.readFileSync(file, "utf8")));
|
|
30920
31158
|
} catch (error) {
|
|
30921
31159
|
if (error.code === "ENOENT")
|
|
30922
31160
|
return { ok: true, data: null };
|
|
@@ -30930,7 +31168,7 @@ function listFanouts(cwd) {
|
|
|
30930
31168
|
return dir;
|
|
30931
31169
|
let names = [];
|
|
30932
31170
|
try {
|
|
30933
|
-
names =
|
|
31171
|
+
names = fs34.readdirSync(dir.data).filter((entry) => entry.endsWith(".json"));
|
|
30934
31172
|
} catch {
|
|
30935
31173
|
return { ok: true, data: [] };
|
|
30936
31174
|
}
|
|
@@ -30938,7 +31176,7 @@ function listFanouts(cwd) {
|
|
|
30938
31176
|
for (const entry of names) {
|
|
30939
31177
|
let parsed = null;
|
|
30940
31178
|
try {
|
|
30941
|
-
parsed = parseStored(JSON.parse(
|
|
31179
|
+
parsed = parseStored(JSON.parse(fs34.readFileSync(path56.join(dir.data, entry), "utf8")));
|
|
30942
31180
|
} catch {
|
|
30943
31181
|
parsed = null;
|
|
30944
31182
|
}
|
|
@@ -31522,10 +31760,15 @@ var createV2Lifecycle = (deps) => {
|
|
|
31522
31760
|
commitDispatchStart(data.parentID, live, data.sessionID);
|
|
31523
31761
|
}
|
|
31524
31762
|
};
|
|
31763
|
+
let reaped = false;
|
|
31525
31764
|
const handleEvent = async (event) => {
|
|
31526
31765
|
const type = event.type;
|
|
31527
31766
|
if (typeof type !== "string")
|
|
31528
31767
|
return;
|
|
31768
|
+
if (!reaped) {
|
|
31769
|
+
reaped = true;
|
|
31770
|
+
reapAtStart(root);
|
|
31771
|
+
}
|
|
31529
31772
|
if (type === "session.created") {
|
|
31530
31773
|
const data = record2(event.data);
|
|
31531
31774
|
const sessionID = sessionIDOf(data.sessionID);
|
|
@@ -31548,6 +31791,13 @@ var createV2Lifecycle = (deps) => {
|
|
|
31548
31791
|
const directory = event.location?.directory;
|
|
31549
31792
|
if (typeof directory === "string" && !sameWorkspace(root, directory))
|
|
31550
31793
|
return;
|
|
31794
|
+
endSession({
|
|
31795
|
+
host: "opencode",
|
|
31796
|
+
session: sessionID,
|
|
31797
|
+
agentId: null,
|
|
31798
|
+
reason: "deleted",
|
|
31799
|
+
cwd: root
|
|
31800
|
+
});
|
|
31551
31801
|
await observeLifecycle(sessionID, binding?.parentID ?? "", "stopped", binding, true);
|
|
31552
31802
|
return;
|
|
31553
31803
|
}
|
|
@@ -31797,7 +32047,7 @@ var childTaskMissing = (store, input) => {
|
|
|
31797
32047
|
var childDenial = (identity) => `OpenCode child session has no validated Workit worker: as ${identity} it may only inspect the task summary (workit_task action "inspect") or record evidence or findings (workit_evidence/workit_finding action "record") on an existing task; for anything else the lead assigns it a worker with workit_worker before launching it`;
|
|
31798
32048
|
|
|
31799
32049
|
// packages/workit-opencode/src/v2/shell.ts
|
|
31800
|
-
import
|
|
32050
|
+
import path57 from "node:path";
|
|
31801
32051
|
|
|
31802
32052
|
// packages/workit-core/src/hooks/repeat-failure.ts
|
|
31803
32053
|
import { createHash as createHash21 } from "node:crypto";
|
|
@@ -31860,7 +32110,7 @@ var commandOf = (input) => {
|
|
|
31860
32110
|
};
|
|
31861
32111
|
var hookInput = (root, sessionID, id, shell) => ({
|
|
31862
32112
|
host: "opencode",
|
|
31863
|
-
cwd: shell.workdir ?
|
|
32113
|
+
cwd: shell.workdir ? path57.resolve(root, shell.workdir) : root,
|
|
31864
32114
|
session: { id: sessionID, agentId: null, agentType: null, parentId: null },
|
|
31865
32115
|
permissionMode: null,
|
|
31866
32116
|
transcriptPath: null,
|
|
@@ -32374,38 +32624,38 @@ var createStopControl = (root, port) => {
|
|
|
32374
32624
|
};
|
|
32375
32625
|
|
|
32376
32626
|
// packages/workit-opencode/src/v2/registry.ts
|
|
32377
|
-
import { existsSync as
|
|
32378
|
-
import
|
|
32627
|
+
import { existsSync as existsSync21, readFileSync as readFileSync17 } from "node:fs";
|
|
32628
|
+
import path59 from "node:path";
|
|
32379
32629
|
|
|
32380
32630
|
// packages/workit-opencode/src/shared/assets.ts
|
|
32381
|
-
import { existsSync as
|
|
32382
|
-
import
|
|
32631
|
+
import { existsSync as existsSync20, realpathSync as realpathSync13 } from "node:fs";
|
|
32632
|
+
import path58 from "node:path";
|
|
32383
32633
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
32384
32634
|
var moduleDir = () => {
|
|
32385
32635
|
try {
|
|
32386
|
-
return realpathSync13(
|
|
32636
|
+
return realpathSync13(path58.dirname(fileURLToPath2(import.meta.url)));
|
|
32387
32637
|
} catch {
|
|
32388
|
-
return
|
|
32638
|
+
return path58.dirname(fileURLToPath2(import.meta.url));
|
|
32389
32639
|
}
|
|
32390
32640
|
};
|
|
32391
32641
|
var packageRoot2 = () => {
|
|
32392
32642
|
const dir = moduleDir();
|
|
32393
32643
|
for (const candidate of [
|
|
32394
|
-
|
|
32395
|
-
|
|
32396
|
-
|
|
32644
|
+
path58.resolve(dir, ".."),
|
|
32645
|
+
path58.resolve(dir, "..", ".."),
|
|
32646
|
+
path58.resolve(dir, "..", "..", "..")
|
|
32397
32647
|
]) {
|
|
32398
|
-
if (
|
|
32648
|
+
if (existsSync20(path58.join(candidate, "package.json")))
|
|
32399
32649
|
return candidate;
|
|
32400
32650
|
}
|
|
32401
|
-
return
|
|
32651
|
+
return path58.resolve(dir, "..");
|
|
32402
32652
|
};
|
|
32403
32653
|
var skillsRoot = () => {
|
|
32404
32654
|
const root = packageRoot2();
|
|
32405
|
-
const canonical =
|
|
32406
|
-
if (
|
|
32655
|
+
const canonical = path58.resolve(root, "..", "workit-core", "skills");
|
|
32656
|
+
if (existsSync20(path58.join(root, "src")) && existsSync20(canonical))
|
|
32407
32657
|
return canonical;
|
|
32408
|
-
return
|
|
32658
|
+
return path58.join(root, "assets", "skills");
|
|
32409
32659
|
};
|
|
32410
32660
|
|
|
32411
32661
|
// packages/workit-opencode/src/v2/registry.ts
|
|
@@ -32429,15 +32679,15 @@ var parseFrontmatter = (markdown) => {
|
|
|
32429
32679
|
};
|
|
32430
32680
|
var registerSkills = async (ctx) => {
|
|
32431
32681
|
const skillsDir = skillsRoot();
|
|
32432
|
-
if (!
|
|
32682
|
+
if (!existsSync21(skillsDir))
|
|
32433
32683
|
return new Set;
|
|
32434
32684
|
const listed = await ctx.skill.list().catch(() => ({ data: [] }));
|
|
32435
|
-
const own = (skill) => typeof skill.path === "string" &&
|
|
32685
|
+
const own = (skill) => typeof skill.path === "string" && path59.resolve(skill.path).startsWith(skillsDir + path59.sep);
|
|
32436
32686
|
const userSkills = new Set((listed?.data ?? []).filter((skill) => !own(skill)).map((skill) => skill.id));
|
|
32437
32687
|
const packaged = new Map;
|
|
32438
32688
|
for (const id of WORKIT_METHOD_SKILLS) {
|
|
32439
|
-
const file =
|
|
32440
|
-
if (!userSkills.has(id) &&
|
|
32689
|
+
const file = path59.join(skillsDir, id, "SKILL.md");
|
|
32690
|
+
if (!userSkills.has(id) && existsSync21(file))
|
|
32441
32691
|
packaged.set(id, file);
|
|
32442
32692
|
}
|
|
32443
32693
|
await ctx.skill.transform((editor) => {
|
|
@@ -32483,106 +32733,25 @@ var registerCommands = async (ctx, registeredSkills) => {
|
|
|
32483
32733
|
};
|
|
32484
32734
|
|
|
32485
32735
|
// packages/workit-opencode/src/stale-sources.ts
|
|
32486
|
-
import { existsSync as
|
|
32487
|
-
import
|
|
32736
|
+
import { existsSync as existsSync22, readdirSync as readdirSync8 } from "node:fs";
|
|
32737
|
+
import path60 from "node:path";
|
|
32488
32738
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
32489
32739
|
var typescriptFiles = (directory) => {
|
|
32490
|
-
if (!
|
|
32740
|
+
if (!existsSync22(directory))
|
|
32491
32741
|
return [];
|
|
32492
32742
|
return readdirSync8(directory, { withFileTypes: true }).flatMap((entry) => {
|
|
32493
|
-
const file =
|
|
32743
|
+
const file = path60.join(directory, entry.name);
|
|
32494
32744
|
return entry.isDirectory() ? typescriptFiles(file) : entry.isFile() && file.endsWith(".ts") ? [file] : [];
|
|
32495
32745
|
});
|
|
32496
32746
|
};
|
|
32497
32747
|
var pluginSourceFiles = [
|
|
32498
32748
|
...new Set([
|
|
32499
32749
|
fileURLToPath3(import.meta.url),
|
|
32500
|
-
...typescriptFiles(
|
|
32501
|
-
|
|
32502
|
-
...typescriptFiles(
|
|
32750
|
+
...typescriptFiles(path60.join(packageRoot2(), "src")),
|
|
32751
|
+
path60.join(packageRoot2(), "..", "workit-core", "src", "core.ts"),
|
|
32752
|
+
...typescriptFiles(path60.join(packageRoot2(), "..", "workit-core", "src", "core"))
|
|
32503
32753
|
])
|
|
32504
|
-
].filter((file) =>
|
|
32505
|
-
|
|
32506
|
-
// packages/workit-core/src/core/cli-locate.ts
|
|
32507
|
-
import { closeSync as closeSync3, existsSync as existsSync22, openSync as openSync3, readSync } from "node:fs";
|
|
32508
|
-
import path59 from "node:path";
|
|
32509
|
-
var LAUNCHER_MARKER = "workit-owned-launcher";
|
|
32510
|
-
var CLI_PACKAGE_PATH = ["node_modules", "@workit-dev", "cli"];
|
|
32511
|
-
var installRoot = (env, platform = process.platform) => {
|
|
32512
|
-
if (env.WORKIT_INSTALL_ROOT)
|
|
32513
|
-
return env.WORKIT_INSTALL_ROOT;
|
|
32514
|
-
const data = dataDir(env, platform);
|
|
32515
|
-
return platform === "win32" ? path59.join(data, "install") : data;
|
|
32516
|
-
};
|
|
32517
|
-
var ownedLauncherPath = (env, platform = process.platform) => path59.join(installRoot(env, platform), "bin", platform === "win32" ? "workit.cmd" : "workit");
|
|
32518
|
-
var ownedCurrentEntry = (env, platform = process.platform) => path59.join(installRoot(env, platform), "current", ...CLI_PACKAGE_PATH, "dist", "index.js");
|
|
32519
|
-
var head = (file) => {
|
|
32520
|
-
let fd;
|
|
32521
|
-
try {
|
|
32522
|
-
fd = openSync3(file, "r");
|
|
32523
|
-
const buffer = Buffer.alloc(256);
|
|
32524
|
-
const read = readSync(fd, buffer, 0, buffer.length, 0);
|
|
32525
|
-
return buffer.subarray(0, read).toString("utf8");
|
|
32526
|
-
} catch {
|
|
32527
|
-
return "";
|
|
32528
|
-
} finally {
|
|
32529
|
-
if (fd !== undefined)
|
|
32530
|
-
closeSync3(fd);
|
|
32531
|
-
}
|
|
32532
|
-
};
|
|
32533
|
-
var locateWorkitCli = (options = {}) => {
|
|
32534
|
-
const env = options.env ?? process.env;
|
|
32535
|
-
const platform = options.platform ?? process.platform;
|
|
32536
|
-
const exists = options.exists ?? existsSync22;
|
|
32537
|
-
const read = options.read ?? head;
|
|
32538
|
-
const node = options.node ?? process.execPath;
|
|
32539
|
-
const launcher = ownedLauncherPath(env, platform);
|
|
32540
|
-
if (exists(launcher) && read(launcher).includes(LAUNCHER_MARKER))
|
|
32541
|
-
return {
|
|
32542
|
-
source: "owned-launcher",
|
|
32543
|
-
command: launcher,
|
|
32544
|
-
args: [],
|
|
32545
|
-
binDir: path59.dirname(launcher)
|
|
32546
|
-
};
|
|
32547
|
-
const current = ownedCurrentEntry(env, platform);
|
|
32548
|
-
if (exists(current))
|
|
32549
|
-
return {
|
|
32550
|
-
source: "owned-current",
|
|
32551
|
-
command: node,
|
|
32552
|
-
args: [current],
|
|
32553
|
-
binDir: null
|
|
32554
|
-
};
|
|
32555
|
-
if (options.bundled && exists(options.bundled))
|
|
32556
|
-
return {
|
|
32557
|
-
source: "bundled",
|
|
32558
|
-
command: node,
|
|
32559
|
-
args: [options.bundled],
|
|
32560
|
-
binDir: null
|
|
32561
|
-
};
|
|
32562
|
-
return { source: "path", command: "workit", args: [], binDir: null };
|
|
32563
|
-
};
|
|
32564
|
-
var pathKey = (env) => Object.keys(env).find((key) => key.toUpperCase() === "PATH") ?? "PATH";
|
|
32565
|
-
var workitCliEnv = (located, env = process.env, platform = process.platform) => {
|
|
32566
|
-
if (located.source === "path")
|
|
32567
|
-
return {};
|
|
32568
|
-
const patch = {
|
|
32569
|
-
WORKIT_CLI: [located.command, ...located.args].join(" ")
|
|
32570
|
-
};
|
|
32571
|
-
if (located.binDir) {
|
|
32572
|
-
const key = pathKey(env);
|
|
32573
|
-
const delimiter = platform === "win32" ? ";" : ":";
|
|
32574
|
-
const same = (dir) => platform === "win32" ? path59.win32.normalize(dir).toLowerCase() === path59.win32.normalize(located.binDir).toLowerCase() : path59.posix.normalize(dir) === path59.posix.normalize(located.binDir);
|
|
32575
|
-
const rest = (env[key] ?? "").split(delimiter).filter((dir) => dir && !same(dir));
|
|
32576
|
-
patch[key] = [located.binDir, ...rest].join(delimiter);
|
|
32577
|
-
}
|
|
32578
|
-
return patch;
|
|
32579
|
-
};
|
|
32580
|
-
var useOwnedWorkitCli = (options = {}) => {
|
|
32581
|
-
const env = options.env ?? process.env;
|
|
32582
|
-
const located = locateWorkitCli({ ...options, env });
|
|
32583
|
-
Object.assign(env, workitCliEnv(located, env, options.platform));
|
|
32584
|
-
return located;
|
|
32585
|
-
};
|
|
32754
|
+
].filter((file) => existsSync22(file)).toSorted();
|
|
32586
32755
|
|
|
32587
32756
|
// packages/workit-opencode/src/cli-path.ts
|
|
32588
32757
|
var useOwnedCliInOpencode = (env = process.env) => useOwnedWorkitCli({ env });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@workit-dev/opencode",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.15.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Workit OpenCode plugin — native tools, adaptive policy, and sixteen method skills",
|
|
6
6
|
"keywords": [
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@opencode/plugin": "2.0.18",
|
|
44
|
-
"@workit-dev/core": "^2.
|
|
44
|
+
"@workit-dev/core": "^2.15.0"
|
|
45
45
|
},
|
|
46
46
|
"engines": {
|
|
47
47
|
"node": ">=24"
|