@workit-dev/pi 1.14.3 → 2.0.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/worker.js CHANGED
@@ -8902,6 +8902,8 @@ var SEAL_COMMAND = "workit workspace seal";
8902
8902
 
8903
8903
  // packages/workit-core/src/autonomy.ts
8904
8904
  var SEAL_UNBLOCK = `if the user made this change, ask them to run, in their own terminal: ${SEAL_COMMAND}`;
8905
+ var NO_SEAL_UNBLOCK = `ask the user to review and seal the grants, in their own terminal: ${SEAL_COMMAND}`;
8906
+ var NO_SEAL_NOTE = `workspaces.json has no seal yet (${SEAL_COMMAND} has never run), so grants, endpoint, verification and youtrack.writes stay at or below the D4 defaults; ${NO_SEAL_UNBLOCK}`;
8905
8907
  var DEFAULT_GRANTS = Object.freeze({
8906
8908
  push: true,
8907
8909
  pr: true,
@@ -8909,6 +8911,13 @@ var DEFAULT_GRANTS = Object.freeze({
8909
8911
  release: false,
8910
8912
  rerun: true
8911
8913
  });
8914
+ var SCOPE_FIELDS = new Set([
8915
+ "autonomy",
8916
+ "autoApprove",
8917
+ "defaultEndpoint",
8918
+ "verification",
8919
+ "youtrack"
8920
+ ]);
8912
8921
 
8913
8922
  // packages/workit-core/src/hooks/raw-git.ts
8914
8923
  var SHELLS = new Set(["sh", "bash", "zsh", "dash", "ksh", "ash", "mksh", "yash", "fish"]);
package/dist/workit.js CHANGED
@@ -8765,6 +8765,7 @@ var accountHome = (platform = process.platform, io = hostIo) => {
8765
8765
  return null;
8766
8766
  }
8767
8767
  };
8768
+ var grantsHome = { resolve: () => accountHome() };
8768
8769
 
8769
8770
  // packages/workit-core/src/core/remotes.ts
8770
8771
  var FORGE_SCHEMES = new Set(["ssh", "git", "http", "https", "git+ssh", "ssh+git"]);
@@ -18387,64 +18388,7 @@ var evalWorldEntry = (cwd) => {
18387
18388
  // packages/workit-core/src/core/grant-seal.ts
18388
18389
  import { createHash as createHash14 } from "node:crypto";
18389
18390
  import { readFileSync as readFileSync10 } from "node:fs";
18390
- import path25 from "node:path";
18391
- var SEAL_FILE = "workspaces.json.seal";
18392
- var SEAL_VERSION = 1;
18393
- var SEAL_COMMAND = "workit workspace seal";
18394
- var pick2 = (value, keys) => {
18395
- if (!value || typeof value !== "object" || Array.isArray(value))
18396
- return;
18397
- const out = Object.fromEntries(keys.flatMap((key) => {
18398
- const item = value[key];
18399
- return item === undefined ? [] : [[key, item]];
18400
- }));
18401
- return Object.keys(out).length > 0 ? out : undefined;
18402
- };
18403
- var ENTRY_KEYS = [
18404
- "name",
18405
- "glob",
18406
- "remotes",
18407
- "vcs",
18408
- "autonomy",
18409
- "autoApprove",
18410
- "defaultEndpoint",
18411
- "verification",
18412
- "youtrack"
18413
- ];
18414
- var sealProjection = (entries) => entries.map((entry) => {
18415
- const all = pick2(entry, ENTRY_KEYS) ?? {};
18416
- return pick2({
18417
- ...all,
18418
- vcs: pick2(all.vcs, ["provider", "account"]),
18419
- youtrack: pick2(all.youtrack, ["writes"])
18420
- }, ENTRY_KEYS);
18421
- });
18422
- var canonical3 = (value) => JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : item);
18423
- var sealDigest = (projection) => createHash14("sha256").update(canonical3(projection)).digest("hex");
18424
- var broken = (reason, sealed = null) => ({
18425
- state: "broken",
18426
- reason,
18427
- sealed
18428
- });
18429
- function checkSeal(dir) {
18430
- const file = path25.join(dir, SEAL_FILE);
18431
- let seal;
18432
- try {
18433
- seal = JSON.parse(readFileSync10(file, "utf8"));
18434
- } catch (error) {
18435
- if (error.code === "ENOENT")
18436
- return { state: "none" };
18437
- return broken(`${SEAL_FILE} cannot be read`);
18438
- }
18439
- if (seal?.version !== SEAL_VERSION || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
18440
- return broken(`${SEAL_FILE} is malformed`);
18441
- const sealed = validateWorkspacesDocument({ workspaces: seal.projection }, file);
18442
- if (sealed.status !== "valid")
18443
- return broken(`${SEAL_FILE} is malformed`);
18444
- const current = readWorkspacesResult(dir);
18445
- const ok = current.status === "valid" || current.status === "missing";
18446
- return ok && sealDigest(sealProjection(current.entries)) === seal.sha256 ? { state: "valid" } : broken("workspaces.json changed since it was sealed", sealed.entries);
18447
- }
18391
+ import path26 from "node:path";
18448
18392
 
18449
18393
  // packages/workit-core/src/core/safe-write.ts
18450
18394
  import { randomUUID as randomUUID4 } from "node:crypto";
@@ -18459,11 +18403,11 @@ import {
18459
18403
  unlinkSync,
18460
18404
  writeFileSync as writeFileSync5
18461
18405
  } from "node:fs";
18462
- import path26 from "node:path";
18406
+ import path25 from "node:path";
18463
18407
  function writeFileAtomic(file, content, mode) {
18464
- const absolute = path26.resolve(file);
18465
- let parent = path26.dirname(absolute);
18466
- const root = path26.parse(parent).root;
18408
+ const absolute = path25.resolve(file);
18409
+ let parent = path25.dirname(absolute);
18410
+ const root = path25.parse(parent).root;
18467
18411
  for (;; ) {
18468
18412
  try {
18469
18413
  if (lstatSync6(parent).isSymbolicLink())
@@ -18472,12 +18416,12 @@ function writeFileAtomic(file, content, mode) {
18472
18416
  if (error.code !== "ENOENT")
18473
18417
  throw error;
18474
18418
  }
18475
- const next = path26.dirname(parent);
18419
+ const next = path25.dirname(parent);
18476
18420
  if (parent === root || next === parent)
18477
18421
  break;
18478
18422
  parent = next;
18479
18423
  }
18480
- const directory = path26.dirname(absolute);
18424
+ const directory = path25.dirname(absolute);
18481
18425
  mkdirSync5(directory, { recursive: true });
18482
18426
  let existing = null;
18483
18427
  try {
@@ -18513,8 +18457,67 @@ function writeFileAtomic(file, content, mode) {
18513
18457
  }
18514
18458
  }
18515
18459
 
18460
+ // packages/workit-core/src/core/grant-seal.ts
18461
+ var SEAL_FILE = "workspaces.json.seal";
18462
+ var SEAL_VERSION = 1;
18463
+ var SEAL_COMMAND = "workit workspace seal";
18464
+ var pick2 = (value, keys) => {
18465
+ if (!value || typeof value !== "object" || Array.isArray(value))
18466
+ return;
18467
+ const out = Object.fromEntries(keys.flatMap((key) => {
18468
+ const item = value[key];
18469
+ return item === undefined ? [] : [[key, item]];
18470
+ }));
18471
+ return Object.keys(out).length > 0 ? out : undefined;
18472
+ };
18473
+ var ENTRY_KEYS = [
18474
+ "name",
18475
+ "glob",
18476
+ "remotes",
18477
+ "vcs",
18478
+ "autonomy",
18479
+ "autoApprove",
18480
+ "defaultEndpoint",
18481
+ "verification",
18482
+ "youtrack"
18483
+ ];
18484
+ var IDENTITY_KEYS = ["provider", "account", "tokenFile", "host"];
18485
+ var sealProjection = (entries) => entries.map((entry) => {
18486
+ const all = pick2(entry, ENTRY_KEYS) ?? {};
18487
+ return pick2({
18488
+ ...all,
18489
+ vcs: pick2(all.vcs, IDENTITY_KEYS),
18490
+ youtrack: pick2(all.youtrack, ["writes"])
18491
+ }, ENTRY_KEYS);
18492
+ });
18493
+ var canonical3 = (value) => JSON.stringify(value, (_key, item) => item && typeof item === "object" && !Array.isArray(item) ? Object.fromEntries(Object.entries(item).toSorted(([a], [b]) => a < b ? -1 : a > b ? 1 : 0)) : item);
18494
+ var sealDigest = (projection) => createHash14("sha256").update(canonical3(projection)).digest("hex");
18495
+ var broken = (reason, sealed = null) => ({
18496
+ state: "broken",
18497
+ reason,
18498
+ sealed
18499
+ });
18500
+ function checkSeal(dir) {
18501
+ const file = path26.join(dir, SEAL_FILE);
18502
+ let seal;
18503
+ try {
18504
+ seal = JSON.parse(readFileSync10(file, "utf8"));
18505
+ } catch (error) {
18506
+ if (error.code === "ENOENT")
18507
+ return { state: "none" };
18508
+ return broken(`${SEAL_FILE} cannot be read`);
18509
+ }
18510
+ if (seal?.version !== SEAL_VERSION || !Array.isArray(seal.projection) || seal.sha256 !== sealDigest(seal.projection))
18511
+ return broken(`${SEAL_FILE} is malformed`);
18512
+ const sealed = validateWorkspacesDocument({ workspaces: seal.projection }, file);
18513
+ if (sealed.status !== "valid")
18514
+ return broken(`${SEAL_FILE} is malformed`);
18515
+ const current = readWorkspacesResult(dir);
18516
+ const ok = current.status === "valid" || current.status === "missing";
18517
+ return ok && sealDigest(sealProjection(current.entries)) === seal.sha256 ? { state: "valid" } : broken("workspaces.json changed since it was sealed", sealed.entries);
18518
+ }
18519
+
18516
18520
  // packages/workit-core/src/autonomy.ts
18517
- var grantsHome = { resolve: accountHome };
18518
18521
  var accountDir = () => {
18519
18522
  const home = grantsHome.resolve();
18520
18523
  return home === null ? null : configDir({ HOME: home });
@@ -18535,11 +18538,26 @@ var sealOf = () => {
18535
18538
  return dir === null ? { state: "none" } : checkSeal(dir);
18536
18539
  };
18537
18540
  var SEAL_UNBLOCK = `if the user made this change, ask them to run, in their own terminal: ${SEAL_COMMAND}`;
18541
+ var NO_SEAL_UNBLOCK = `ask the user to review and seal the grants, in their own terminal: ${SEAL_COMMAND}`;
18542
+ var NO_SEAL_NOTE = `workspaces.json has no seal yet (${SEAL_COMMAND} has never run), so grants, endpoint, verification and youtrack.writes stay at or below the D4 defaults; ${NO_SEAL_UNBLOCK}`;
18538
18543
  var sealNote = (seal = sealOf()) => seal.state === "broken" ? `workspaces.json does not match its seal (${seal.reason}), so grants, endpoint, verification and youtrack.writes are the stricter of their current and last sealed values; ${SEAL_UNBLOCK}` : null;
18539
18544
  var youTrackWritesMode = (cwd) => {
18540
- const youtrack = resolveRuntimeWorkspaceVcs(cwd)?.youtrack;
18541
- return youtrack && typeof youtrack === "object" && youtrack.writes === "auto" && !sealNote() ? "auto" : "ask";
18545
+ try {
18546
+ const dir = accountDir();
18547
+ if (dir === null || redirected(dir) || evalWorld(cwd))
18548
+ return "ask";
18549
+ if (checkSeal(dir).state !== "valid")
18550
+ return "ask";
18551
+ const auto = (entry) => entry?.youtrack?.writes === "auto";
18552
+ const name = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
18553
+ if (!auto(resolveWorkspaceFrom(cwd, dir, name)))
18554
+ return "ask";
18555
+ return !name || auto(resolveWorkspaceFrom(cwd, dir)) ? "auto" : "ask";
18556
+ } catch {
18557
+ return "ask";
18558
+ }
18542
18559
  };
18560
+ var redirected = (dir) => path27.resolve(resolveConfigDir()) !== path27.resolve(dir);
18543
18561
  var shownGrantsDir = () => {
18544
18562
  const world = evalWorld(process.cwd());
18545
18563
  return world ? path27.join(world, "config") : accountDir();
@@ -18567,8 +18585,9 @@ var grantsOverride = () => {
18567
18585
  if (shown === null)
18568
18586
  return NO_ACCOUNT;
18569
18587
  const configured = path27.resolve(resolveConfigDir());
18570
- return configured === path27.resolve(shown) ? null : `the config directory is redirected to ${configured} (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), but that override does not apply to grants: grants are read only from ${path27.join(grantsDir(), "workspaces.json")}, so the D4 defaults apply until grants are set there`;
18588
+ return configured === path27.resolve(shown) ? null : `the config directory is redirected to ${configured} (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), but that override does not apply to grants: grants are read only from ${path27.join(grantsDir(), "workspaces.json")}, and under a redirect they never exceed the D4 defaults`;
18571
18589
  };
18590
+ var redirectUnblock = () => `ask the user: grants above the D4 defaults apply only without a config redirect (WORKIT_CONFIG, WORKIT_CONFIG_DIR or XDG_CONFIG_HOME), and are read from ${path27.join(grantsDir(), "workspaces.json")}`;
18572
18591
  var GRANT_KINDS = ["push", "pr", "merge", "release", "rerun"];
18573
18592
  var DEFAULT_GRANTS = Object.freeze({
18574
18593
  push: true,
@@ -18734,23 +18753,39 @@ function capAt(source, named, where, by, why, main = false) {
18734
18753
  function resolveAutonomy(cwd, target) {
18735
18754
  const world = benchWorld(cwd);
18736
18755
  const override = world ? null : grantsOverride();
18737
- if (override)
18756
+ if (override === NO_ACCOUNT)
18738
18757
  return { ...autonomyOf(null), note: override };
18739
18758
  let resolved;
18740
18759
  const once = typeof target === "function" ? () => resolved ??= target() : target;
18741
- const current = resolveWith(fileSource(), cwd, world, once);
18760
+ const account = accountAuthority(cwd, world, once);
18761
+ return override ? stricter(account, autonomyOf(null), override, redirectUnblock()) : account;
18762
+ }
18763
+ function accountAuthority(cwd, world, target) {
18764
+ const current = resolveWith(fileSource(), cwd, world, target);
18742
18765
  const seal = sealOf();
18743
- if (seal.state !== "broken")
18744
- return current;
18766
+ if (seal.state !== "broken") {
18767
+ if (seal.state === "valid" || current.world)
18768
+ return current;
18769
+ const capped = stricter(current, autonomyOf(null), NO_SEAL_NOTE, NO_SEAL_UNBLOCK);
18770
+ return authorityKey(capped) === authorityKey(current) ? current : capped;
18771
+ }
18745
18772
  let sealed = autonomyOf(null);
18746
18773
  try {
18747
18774
  if (seal.sealed)
18748
- sealed = resolveWith(sealedSource(seal.sealed), cwd, world, once);
18775
+ sealed = resolveWith(sealedSource(seal.sealed), cwd, world, target);
18749
18776
  } catch {
18750
18777
  sealed = null;
18751
18778
  }
18752
- return stricter(current, sealed, sealNote(seal));
18779
+ return stricter(current, sealed, sealNote(seal), SEAL_UNBLOCK);
18753
18780
  }
18781
+ var authorityKey = (autonomy) => JSON.stringify([
18782
+ autonomy.grants,
18783
+ autonomy.configured,
18784
+ autonomy.accountConfigured,
18785
+ autonomy.defaultEndpoint,
18786
+ autonomy.effectiveEndpoint,
18787
+ autonomy.verification
18788
+ ]);
18754
18789
  function resolveWith(source, cwd, world, target) {
18755
18790
  const name = process.env.WORKIT_WORKSPACE_NAME?.trim() || undefined;
18756
18791
  const real = source.resolve(cwd, name);
@@ -18765,7 +18800,7 @@ function resolveWith(source, cwd, world, target) {
18765
18800
  return capAtRemotes(source, autonomy, cwd, target);
18766
18801
  }
18767
18802
  var needsAccount = (autonomy) => autonomy.configured.length > 0 && !autonomy.accountConfigured;
18768
- function stricter(current, sealed, note) {
18803
+ function stricter(current, sealed, note, unblock) {
18769
18804
  const grants = { ...current.grants };
18770
18805
  const unblocks = { ...current.unblocks };
18771
18806
  for (const kind of GRANT_KINDS) {
@@ -18773,7 +18808,7 @@ function stricter(current, sealed, note) {
18773
18808
  if (!raises(kind, floor, grants[kind]))
18774
18809
  continue;
18775
18810
  grants[kind] = floor;
18776
- unblocks[kind] = SEAL_UNBLOCK;
18811
+ unblocks[kind] = unblock;
18777
18812
  }
18778
18813
  const configured = GRANT_KINDS.filter((kind) => current.configured.includes(kind) || sealed?.configured.includes(kind));
18779
18814
  const accountConfigured = !needsAccount(current) && !(sealed && needsAccount(sealed)) && (current.accountConfigured || Boolean(sealed?.accountConfigured));
@@ -18795,9 +18830,9 @@ function stricter(current, sealed, note) {
18795
18830
  accountConfigured,
18796
18831
  defaultEndpoint,
18797
18832
  effectiveEndpoint: endpoint,
18798
- endpointReason: endpoint === current.effectiveEndpoint ? current.endpointReason : SEAL_UNBLOCK,
18833
+ endpointReason: endpoint === current.effectiveEndpoint ? current.endpointReason : unblock,
18799
18834
  verification: looser ? strict : current.verification,
18800
- unblocks,
18835
+ unblocks: Object.keys(unblocks).length > 0 ? unblocks : current.unblocks,
18801
18836
  note: current.note ? `${current.note}; ${note}` : note
18802
18837
  };
18803
18838
  }
@@ -18818,14 +18853,17 @@ function capAtRemotes(source, autonomy, cwd, target) {
18818
18853
  return capped;
18819
18854
  }
18820
18855
  var grantsMatter = (kind) => {
18821
- if (grantsOverride())
18856
+ const override = grantsOverride();
18857
+ if (override === NO_ACCOUNT)
18822
18858
  return false;
18823
- const matters = entriesIn(accountDir()).some((entry) => {
18859
+ const entries = entriesIn(accountDir());
18860
+ const matters = entries.some((entry) => {
18824
18861
  const autonomy = autonomyOf(entry);
18825
18862
  return entry.remotes?.length || autonomy.grants[kind] === false || needsAccount(autonomy);
18826
18863
  });
18827
18864
  const seal = sealOf();
18828
- return matters || seal.state === "broken" && (seal.sealed ? seal.sealed.length > 0 : DEFAULT_GRANTS[kind] === false);
18865
+ const defaults = entries.length > 0 && DEFAULT_GRANTS[kind] === false;
18866
+ return matters || (seal.state === "none" || override !== null) && defaults || seal.state === "broken" && (seal.sealed ? seal.sealed.length > 0 : DEFAULT_GRANTS[kind] === false);
18829
18867
  };
18830
18868
  var authorityEntries = () => {
18831
18869
  const seal = sealOf();
@@ -18883,6 +18921,13 @@ var raises = (kind, current, next) => {
18883
18921
  const rank = (value) => value === true ? 2 : value === "verified" ? 1 : 0;
18884
18922
  return rank(normalized(kind, next)) > rank(normalized(kind, current));
18885
18923
  };
18924
+ var SCOPE_FIELDS = new Set([
18925
+ "autonomy",
18926
+ "autoApprove",
18927
+ "defaultEndpoint",
18928
+ "verification",
18929
+ "youtrack"
18930
+ ]);
18886
18931
 
18887
18932
  // packages/workit-core/src/hooks/session-marker.ts
18888
18933
  import { createHash as createHash15 } from "node:crypto";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@workit-dev/pi",
3
- "version": "1.14.3",
3
+ "version": "2.0.0",
4
4
  "description": "Workit native extension for Pi — tools, method skills, and session continuity",
5
5
  "keywords": [
6
6
  "agentic-coding",