@brainervirus/workit-mcp 8.1.0 → 8.3.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.
Files changed (2) hide show
  1. package/dist/index.js +110 -51
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -16574,7 +16574,7 @@ class StdioServerTransport {
16574
16574
  import { fileURLToPath as fileURLToPath2 } from "node:url";
16575
16575
 
16576
16576
  // packages/workit-core/src/core.ts
16577
- import { spawnSync as spawnSync13 } from "node:child_process";
16577
+ import { spawnSync as spawnSync14 } from "node:child_process";
16578
16578
  import { existsSync as existsSync7, realpathSync as realpathSync5 } from "node:fs";
16579
16579
  import path19 from "node:path";
16580
16580
 
@@ -18436,6 +18436,35 @@ function acquireFileLockSync(targetPath, options) {
18436
18436
  }
18437
18437
  }
18438
18438
  }
18439
+ // packages/workit-core/src/host-session.ts
18440
+ var HOST_SESSION_VARS = [
18441
+ ["OPENCODE_SESSION_ID", () => "opencode"],
18442
+ ["PI_SESSION_ID", () => "pi"],
18443
+ [
18444
+ "CODEX_THREAD_ID",
18445
+ (env) => env.CODEX_INTERNAL_ORIGINATOR_OVERRIDE === "Codex Desktop" || env.CODEX_ELECTRON_RESOURCES_PATH ? "codex_desktop" : "codex_cli"
18446
+ ]
18447
+ ];
18448
+ var family = (host) => host?.replace(/_(?:cli|desktop)$/, "") ?? null;
18449
+ function hostSessionFromEnv(env) {
18450
+ const value = (key) => env[key]?.trim() || null;
18451
+ let inner = null;
18452
+ for (const [key, host] of HOST_SESSION_VARS) {
18453
+ const session = value(key);
18454
+ if (session) {
18455
+ inner = { host: host(env), session };
18456
+ break;
18457
+ }
18458
+ }
18459
+ const declared = value("WORKIT_HOST");
18460
+ if (env.WORKIT_SESSION_ID !== undefined) {
18461
+ const inherited = inner !== null && declared !== null && family(declared) !== family(inner.host);
18462
+ if (!inherited)
18463
+ return { host: declared, session: value("WORKIT_SESSION_ID") };
18464
+ }
18465
+ return inner ? { host: inner.host, session: inner.session } : { host: declared, session: null };
18466
+ }
18467
+
18439
18468
  // packages/workit-core/src/core/package-root.ts
18440
18469
  import { existsSync } from "node:fs";
18441
18470
  import path3 from "node:path";
@@ -19400,9 +19429,10 @@ var drop = (lock) => {
19400
19429
  };
19401
19430
  var envActor = () => {
19402
19431
  const value = (key) => process.env[key]?.trim() || null;
19432
+ const acting = hostSessionFromEnv(process.env);
19403
19433
  return {
19404
- host: value("WORKIT_HOST") ?? "runtime",
19405
- session: value("WORKIT_SESSION_ID"),
19434
+ host: acting.host ?? "runtime",
19435
+ session: acting.session,
19406
19436
  agentId: value("WORKIT_AGENT_ID")
19407
19437
  };
19408
19438
  };
@@ -23032,6 +23062,7 @@ var gitContext = (workspaceRoot, paths = []) => {
23032
23062
  };
23033
23063
 
23034
23064
  // packages/workit-core/src/core/workspaces.ts
23065
+ import { spawnSync as spawnSync8 } from "node:child_process";
23035
23066
  import { createHash as createHash8 } from "node:crypto";
23036
23067
  import { readFileSync as readFileSync4, realpathSync as realpathSync3 } from "node:fs";
23037
23068
  import path13 from "node:path";
@@ -23276,6 +23307,53 @@ var validateWorkspaceGlob = (glob) => {
23276
23307
  }
23277
23308
  return { ok: true };
23278
23309
  };
23310
+
23311
+ class WorkspaceConfigError extends Error {
23312
+ name = "WorkspaceConfigError";
23313
+ }
23314
+ var mainCheckouts = new Map;
23315
+ var mainCheckoutOf = (cwd) => {
23316
+ const cached = mainCheckouts.get(cwd);
23317
+ if (cached !== undefined)
23318
+ return cached;
23319
+ const env = { ...process.env };
23320
+ for (const name of ["GIT_DIR", "GIT_WORK_TREE", "GIT_COMMON_DIR", "GIT_INDEX_FILE"])
23321
+ delete env[name];
23322
+ const git = (args) => {
23323
+ const run = spawnSync8("git", args, {
23324
+ cwd,
23325
+ env,
23326
+ encoding: "utf8",
23327
+ timeout: 5000,
23328
+ windowsHide: true
23329
+ });
23330
+ return run.status === 0 ? run.stdout : null;
23331
+ };
23332
+ let main = null;
23333
+ const dirs = git(["rev-parse", "--path-format=absolute", "--git-dir", "--git-common-dir"]);
23334
+ const [gitDir, common] = (dirs ?? "").trim().split(/\r?\n/u);
23335
+ if (gitDir && common && path13.resolve(gitDir) !== path13.resolve(common)) {
23336
+ const listed = /^worktree (.+)$/mu.exec(git(["worktree", "list", "--porcelain"]) ?? "")?.[1];
23337
+ main = listed?.trim() || (path13.basename(common) === ".git" ? path13.dirname(common) : common);
23338
+ }
23339
+ mainCheckouts.set(cwd, main);
23340
+ return main;
23341
+ };
23342
+ var matchingEntries = (cwd, entries) => {
23343
+ const match = (where) => {
23344
+ const targets = [where, realpathOf(where)].map((value) => value.replaceAll("\\", "/"));
23345
+ return entries.filter((entry) => {
23346
+ const glob = entry.glob.replaceAll("\\", "/");
23347
+ const canonical = canonicalGlob(glob);
23348
+ return targets.some((target) => matchWorkspace(glob, target) || canonical !== glob && matchWorkspace(canonical, target));
23349
+ });
23350
+ };
23351
+ const direct = match(cwd);
23352
+ if (direct.length)
23353
+ return direct;
23354
+ const main = mainCheckoutOf(cwd);
23355
+ return main ? match(main) : direct;
23356
+ };
23279
23357
  var realpathOf = (p) => {
23280
23358
  const real = realpathSync3.native ?? realpathSync3;
23281
23359
  try {
@@ -23300,43 +23378,29 @@ var selectWorkspaceMatch = (matches, cwd, workspaceName) => {
23300
23378
  if (named.length === 1)
23301
23379
  return named[0];
23302
23380
  if (named.length > 1)
23303
- throw new Error(`ambiguous workspace ${JSON.stringify(workspaceName)} for ${cwd}`);
23381
+ throw new WorkspaceConfigError(`ambiguous workspace ${JSON.stringify(workspaceName)} for ${cwd}`);
23304
23382
  if (matches.length > 0) {
23305
- throw new Error(`workspace ${JSON.stringify(workspaceName)} does not match ${cwd}; matching choices: ${matches.map((entry) => entry.name).join(", ")}`);
23383
+ throw new WorkspaceConfigError(`workspace ${JSON.stringify(workspaceName)} does not match ${cwd}; matching choices: ${matches.map((entry) => entry.name).join(", ")}`);
23306
23384
  }
23307
- throw new Error(`workspace ${JSON.stringify(workspaceName)} does not match ${cwd}`);
23385
+ throw new WorkspaceConfigError(`workspace ${JSON.stringify(workspaceName)} does not match ${cwd}`);
23308
23386
  }
23309
23387
  if (matches.length < 2)
23310
23388
  return matches[0];
23311
23389
  const highestSpecificity = Math.max(...matches.map((entry) => globSpecificity(entry.glob)));
23312
23390
  const mostSpecific = matches.filter((entry) => globSpecificity(entry.glob) === highestSpecificity);
23313
23391
  if (mostSpecific.length > 1) {
23314
- throw new Error(`ambiguous workspace for ${cwd}; choose one of: ${mostSpecific.map((entry) => entry.name).join(", ")}`);
23392
+ throw new WorkspaceConfigError(`ambiguous workspace for ${cwd}; choose one of: ${mostSpecific.map((entry) => entry.name).join(", ")}`);
23315
23393
  }
23316
23394
  return mostSpecific[0];
23317
23395
  };
23318
23396
  var resolveWorkspaceFromEntries = (cwd, entries, workspaceName) => {
23319
- const targets = [cwd, realpathOf(cwd)].map((p) => p.replaceAll("\\", "/"));
23320
- const matches = [];
23321
- for (const ws of entries) {
23322
- const glob = ws.glob.replaceAll("\\", "/");
23323
- const canonical = canonicalGlob(glob);
23324
- let matched = false;
23325
- for (const target of targets) {
23326
- if (matchWorkspace(glob, target) || canonical !== glob && matchWorkspace(canonical, target)) {
23327
- matched = true;
23328
- break;
23329
- }
23330
- }
23331
- if (matched)
23332
- matches.push(ws);
23333
- }
23397
+ const matches = matchingEntries(cwd, entries);
23334
23398
  return selectWorkspaceMatch(matches, cwd, workspaceName) ?? null;
23335
23399
  };
23336
23400
  var resolveWorkspaceFrom = (cwd, dir, workspaceName) => {
23337
23401
  const result = readWorkspacesResult(dir);
23338
23402
  if (result.status === "malformed" || result.status === "invalid")
23339
- throw new Error(result.error);
23403
+ throw new WorkspaceConfigError(result.error);
23340
23404
  return resolveWorkspaceFromEntries(cwd, result.entries, workspaceName);
23341
23405
  };
23342
23406
  var runtimeWorkspacePolicySchema = (kind) => {
@@ -23368,31 +23432,26 @@ var matchRuntimeWorkspace = (cwd) => {
23368
23432
  } catch (error) {
23369
23433
  if (error.code === "ENOENT")
23370
23434
  return null;
23371
- throw new Error(`${file} could not be read: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
23435
+ throw new WorkspaceConfigError(`${file} could not be read: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
23372
23436
  }
23373
23437
  let parsed;
23374
23438
  try {
23375
23439
  parsed = JSON.parse(raw);
23376
23440
  } catch {
23377
- throw new Error(`${file} is not valid JSON`);
23441
+ throw new WorkspaceConfigError(`${file} is not valid JSON`);
23378
23442
  }
23379
23443
  const validated = runtimeWorkspaceIndexSchema.safeParse(parsed);
23380
23444
  if (!validated.success) {
23381
23445
  const detail = validated.error.issues.map((issue) => `${issue.path.map(String).join(".") || "workspaces"}: ${issue.message}`).join("; ");
23382
- throw new Error(`${file} has invalid workspace matching data: ${detail}`);
23446
+ throw new WorkspaceConfigError(`${file} has invalid workspace matching data: ${detail}`);
23383
23447
  }
23384
23448
  const entries = validated.data.workspaces;
23385
23449
  for (const entry of entries ?? []) {
23386
23450
  const glob = validateWorkspaceGlob(entry.glob);
23387
23451
  if (!glob.ok)
23388
- throw new Error(`${file} workspace ${entry.name}: ${glob.error}`);
23452
+ throw new WorkspaceConfigError(`${file} workspace ${entry.name}: ${glob.error}`);
23389
23453
  }
23390
- const targets = [cwd, realpathOf(cwd)].map((value) => value.replaceAll("\\", "/"));
23391
- const matches = (entries ?? []).filter((entry) => {
23392
- const glob = entry.glob.replaceAll("\\", "/");
23393
- const canonical = canonicalGlob(glob);
23394
- return targets.some((target) => matchWorkspace(glob, target) || canonical !== glob && matchWorkspace(canonical, target));
23395
- });
23454
+ const matches = matchingEntries(cwd, entries ?? []);
23396
23455
  const workspaceName = process.env.WORKFLOW_WORKSPACE_NAME?.trim() || undefined;
23397
23456
  const selected = selectWorkspaceMatch(matches, cwd, workspaceName);
23398
23457
  return selected ? { file, selected } : null;
@@ -23409,7 +23468,7 @@ var resolveRuntimeWorkspaceCandidate = (cwd, kind) => {
23409
23468
  const policy = runtimeWorkspacePolicySchema(kind).safeParse(selected);
23410
23469
  if (!policy.success) {
23411
23470
  const detail = policy.error.issues.map((issue) => `${issue.path.map(String).join(".") || "workspace"}: ${issue.message}`).join("; ");
23412
- throw new Error(`${file} has invalid ${kind} policy configuration: ${detail}`);
23471
+ throw new WorkspaceConfigError(`${file} has invalid ${kind} policy configuration: ${detail}`);
23413
23472
  }
23414
23473
  return policy.data;
23415
23474
  };
@@ -23420,10 +23479,10 @@ var resolveRuntimeWorkspacePolicy = (cwd, kind, requestedProfile) => {
23420
23479
  const key = kind === "branch" ? "branchPolicy" : "commitPolicy";
23421
23480
  const profileName = requestedProfile?.trim() || candidate.defaultProfile;
23422
23481
  if (candidate.defaultProfile && !Object.hasOwn(candidate.profiles ?? {}, candidate.defaultProfile))
23423
- throw new Error(`workspace ${JSON.stringify(candidate.name)} has no profile ${JSON.stringify(candidate.defaultProfile)}`);
23482
+ throw new WorkspaceConfigError(`workspace ${JSON.stringify(candidate.name)} has no profile ${JSON.stringify(candidate.defaultProfile)}`);
23424
23483
  const profile = profileName ? candidate.profiles?.[profileName] : undefined;
23425
23484
  if (profileName && !profile)
23426
- throw new Error(`workspace ${JSON.stringify(candidate.name)} has no profile ${JSON.stringify(profileName)}`);
23485
+ throw new WorkspaceConfigError(`workspace ${JSON.stringify(candidate.name)} has no profile ${JSON.stringify(profileName)}`);
23427
23486
  const profilePolicy = profile?.[key];
23428
23487
  const workspacePolicy = candidate[key];
23429
23488
  return {
@@ -23443,11 +23502,11 @@ function workspaceDefaultTarget(cwd, globalDefault) {
23443
23502
  // packages/workit-core/src/core/vcs-config.ts
23444
23503
  import fs12 from "node:fs";
23445
23504
  import path14 from "node:path";
23446
- import { spawnSync as spawnSync9 } from "node:child_process";
23505
+ import { spawnSync as spawnSync10 } from "node:child_process";
23447
23506
 
23448
23507
  // packages/workit-core/src/core/release-tracks.ts
23449
23508
  import { createHash as createHash9 } from "node:crypto";
23450
- import { spawnSync as spawnSync8 } from "node:child_process";
23509
+ import { spawnSync as spawnSync9 } from "node:child_process";
23451
23510
  var KNOWN_FIELDS = new Set([
23452
23511
  "strategy",
23453
23512
  "productionBranch",
@@ -23719,7 +23778,7 @@ function resolveReleaseTrack(input) {
23719
23778
  return fallback(`${branch} has the same or unrelated fork points with ${[...new Set(newest.map((fork) => `${fork.ref} (${fork.track.name === IMPLICIT ? "workspace default" : fork.track.name})`))].join(" and ")}`);
23720
23779
  }
23721
23780
  var git4 = (cwd, args) => {
23722
- const run = spawnSync8("git", args, {
23781
+ const run = spawnSync9("git", args, {
23723
23782
  cwd,
23724
23783
  encoding: "utf8",
23725
23784
  timeout: 20000,
@@ -23834,7 +23893,7 @@ function resolveTrackFor(cwd, options) {
23834
23893
  var workspacesPath = () => path14.join(configDir(), "workspaces.json");
23835
23894
  var vcsCwd = (cwd) => cwd ?? process.env.WORKFLOW_WORKSPACE_ROOT ?? process.cwd();
23836
23895
  var remoteProvider = (cwd) => {
23837
- const r = spawnSync9("git", ["remote", "get-url", "origin"], { cwd, encoding: "utf8" });
23896
+ const r = spawnSync10("git", ["remote", "get-url", "origin"], { cwd, encoding: "utf8" });
23838
23897
  if (r.status !== 0)
23839
23898
  return null;
23840
23899
  const url = (r.stdout ?? "").trim();
@@ -23871,7 +23930,7 @@ var remoteEndpoint = (remote) => {
23871
23930
  var configuredSshEndpoint = (host) => {
23872
23931
  if (host.startsWith("-"))
23873
23932
  return null;
23874
- const resolved = spawnSync9("ssh", ["-G", host], {
23933
+ const resolved = spawnSync10("ssh", ["-G", host], {
23875
23934
  encoding: "utf8",
23876
23935
  timeout: 5000,
23877
23936
  maxBuffer: 1024 * 1024,
@@ -24044,7 +24103,7 @@ function mergedPrStyle(limit = 6, cwd) {
24044
24103
  `).filter((l) => l.startsWith("## ")).map((l) => l.trim()),
24045
24104
  descriptionPreview: desc.slice(0, 600)
24046
24105
  });
24047
- const remoteResult = spawnSync9("git", ["remote", "get-url", "--push", "--all", "origin"], {
24106
+ const remoteResult = spawnSync10("git", ["remote", "get-url", "--push", "--all", "origin"], {
24048
24107
  cwd,
24049
24108
  encoding: "utf8"
24050
24109
  });
@@ -24060,7 +24119,7 @@ function mergedPrStyle(limit = 6, cwd) {
24060
24119
  if (!hostingApiHostMatches(remote, host))
24061
24120
  return { ok: false, error: "PR style target does not match the provider host" };
24062
24121
  if (provider === "gitlab") {
24063
- const run = (args) => spawnSync9("glab", ["api", ...args], {
24122
+ const run = (args) => spawnSync10("glab", ["api", ...args], {
24064
24123
  cwd,
24065
24124
  encoding: "utf8",
24066
24125
  env
@@ -24080,7 +24139,7 @@ function mergedPrStyle(limit = 6, cwd) {
24080
24139
  });
24081
24140
  }
24082
24141
  } else if (provider === "github") {
24083
- const r = spawnSync9("gh", [
24142
+ const r = spawnSync10("gh", [
24084
24143
  "pr",
24085
24144
  "list",
24086
24145
  "--repo",
@@ -26017,7 +26076,7 @@ class WorkitCore {
26017
26076
  }
26018
26077
  }
26019
26078
  // packages/workit-core/src/core/repo-context.ts
26020
- import { spawnSync as spawnSync10 } from "node:child_process";
26079
+ import { spawnSync as spawnSync11 } from "node:child_process";
26021
26080
  import { existsSync as existsSync6, readFileSync as readFileSync5, readdirSync as readdirSync4 } from "node:fs";
26022
26081
  import path16 from "node:path";
26023
26082
  var isSafeContextRange = (value) => value.length <= 4096 && (() => {
@@ -26046,7 +26105,7 @@ var invalidRange = (cwd) => ({
26046
26105
  cwd
26047
26106
  });
26048
26107
  var runGit = (cwd, args) => {
26049
- const result = spawnSync10("git", args, { cwd, encoding: "utf8" });
26108
+ const result = spawnSync11("git", args, { cwd, encoding: "utf8" });
26050
26109
  return {
26051
26110
  stdout: (result.stdout ?? "").trimEnd(),
26052
26111
  stderr: (result.stderr ?? "").trimEnd(),
@@ -26487,12 +26546,12 @@ function releaseNotesContext(root, rangeOrTag) {
26487
26546
  }
26488
26547
 
26489
26548
  // packages/workit-core/src/core/tracker-issues.ts
26490
- import { spawnSync as spawnSync12 } from "node:child_process";
26549
+ import { spawnSync as spawnSync13 } from "node:child_process";
26491
26550
 
26492
26551
  // packages/workit-core/src/core/pr-create.ts
26493
26552
  import fs13 from "node:fs";
26494
26553
  import path17 from "node:path";
26495
- import { spawnSync as spawnSync11 } from "node:child_process";
26554
+ import { spawnSync as spawnSync12 } from "node:child_process";
26496
26555
  // packages/workit-core/src/forge/pr-body.ts
26497
26556
  function parseGhIssue(value) {
26498
26557
  const m = /issues\/(\d+)/.exec(value);
@@ -26517,7 +26576,7 @@ function whichOnPath(tool) {
26517
26576
  }
26518
26577
  var hostingCliAvailable = (provider) => whichOnPath(provider === "gitlab" ? "glab" : "gh") !== null;
26519
26578
  var pushRemote = (cwd) => {
26520
- const result = spawnSync11("git", ["remote", "get-url", "--push", "--all", "origin"], {
26579
+ const result = spawnSync12("git", ["remote", "get-url", "--push", "--all", "origin"], {
26521
26580
  cwd,
26522
26581
  encoding: "utf8"
26523
26582
  });
@@ -26548,7 +26607,7 @@ var defaultCli = (bin, available) => {
26548
26607
  if (!available)
26549
26608
  return null;
26550
26609
  return (args, root) => {
26551
- const out = spawnSync12(bin, args, {
26610
+ const out = spawnSync13(bin, args, {
26552
26611
  cwd: root,
26553
26612
  encoding: "utf8",
26554
26613
  env: { ...process.env, PATH: process.env.PATH ?? "" }
@@ -27066,7 +27125,7 @@ function resolveInside(root, candidate) {
27066
27125
  }
27067
27126
  function run2(root, executable, args, env = {}) {
27068
27127
  const cwd = realpathSync5(root);
27069
- const result = spawnSync13(executable, args, {
27128
+ const result = spawnSync14(executable, args, {
27070
27129
  cwd,
27071
27130
  encoding: "utf8",
27072
27131
  env: { ...process.env, ...env }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brainervirus/workit-mcp",
3
- "version": "8.1.0",
3
+ "version": "8.3.0",
4
4
  "private": false,
5
5
  "description": "Workit shared MCP transport for the eight task and policy operation families",
6
6
  "keywords": [
@@ -42,7 +42,7 @@
42
42
  "build": "bun scripts/build.ts"
43
43
  },
44
44
  "dependencies": {
45
- "@brainervirus/workit-core": "^8.1.0",
45
+ "@brainervirus/workit-core": "^8.3.0",
46
46
  "@modelcontextprotocol/sdk": "1.32.0",
47
47
  "zod": "4.6.5"
48
48
  },