@sjawhar/claude-envoy 4.17.0 → 4.17.2

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.
@@ -2,5 +2,5 @@
2
2
  "name": "claude-envoy",
3
3
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
4
4
  "mcpServers": "./.mcp.json",
5
- "version": "4.17.0"
5
+ "version": "4.17.2"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-envoy",
3
- "version": "4.17.0",
3
+ "version": "4.17.2",
4
4
  "description": "Put Envoy events into the Claude Code session's own conversation and expose Envoy MCP tools.",
5
5
  "mcpServers": {}
6
6
  }
@@ -27028,14 +27028,15 @@ function tokenUrl(audience, env) {
27028
27028
  function serverNamed(env) {
27029
27029
  return (env[METADATA_HOST_VAR] ?? "").trim() === "" ? `at ${DEFAULT_METADATA_HOST}` : `${METADATA_HOST_VAR} names`;
27030
27030
  }
27031
- function get(url, signal) {
27031
+ function get(url, signal, lookup) {
27032
27032
  const { promise, resolve, reject } = Promise.withResolvers();
27033
27033
  const call = request(url, {
27034
27034
  agent,
27035
27035
  method: "GET",
27036
27036
  headers: { "Metadata-Flavor": "Google" },
27037
27037
  timeout: TIMEOUT_MS,
27038
- ...signal === undefined ? {} : { signal }
27038
+ ...signal === undefined ? {} : { signal },
27039
+ ...lookup === undefined ? {} : { lookup }
27039
27040
  }, (answer) => {
27040
27041
  const chunks = [];
27041
27042
  let read = 0;
@@ -27052,14 +27053,14 @@ function get(url, signal) {
27052
27053
  call.end();
27053
27054
  return promise;
27054
27055
  }
27055
- function metadataIdentity(audience, env = process.env) {
27056
+ function metadataIdentity(audience, env = process.env, options = {}) {
27056
27057
  return {
27057
27058
  async read(signal) {
27058
27059
  const url = tokenUrl(audience, env);
27059
27060
  const named = `the metadata server ${serverNamed(env)}`;
27060
27061
  let answer;
27061
27062
  try {
27062
- answer = await get(url, signal);
27063
+ answer = await get(url, signal, options.lookup);
27063
27064
  } catch (error) {
27064
27065
  throw new Error(`${named} could not be reached: ${errorClass(error)}`);
27065
27066
  }
@@ -28859,12 +28860,13 @@ function poolIdentity(options) {
28859
28860
  const mintEndpoint = `${iamCredentials}/v1/projects/-/serviceAccounts/${account}:generateIdToken`;
28860
28861
  const securityTokenServiceShown = urlForText(securityTokenService, STS_SETTING);
28861
28862
  const mintEndpointShown = requestForText(iamCredentials, mintEndpoint, IAM_SETTING);
28863
+ const send = options.fetch ?? fetch;
28862
28864
  const call = async (endpoint, bearer, body, member, signal) => {
28863
28865
  const signals = [AbortSignal.timeout(POOL_TIMEOUT_MS), signal].filter((one) => one !== undefined);
28864
28866
  let answer;
28865
28867
  let text;
28866
28868
  try {
28867
- answer = await fetch(endpoint, {
28869
+ answer = await send(endpoint, {
28868
28870
  method: "POST",
28869
28871
  headers: {
28870
28872
  "Content-Type": "application/json",
package/dist/dispatch.js CHANGED
@@ -28279,14 +28279,15 @@ function tokenUrl(audience, env) {
28279
28279
  function serverNamed(env) {
28280
28280
  return (env[METADATA_HOST_VAR] ?? "").trim() === "" ? `at ${DEFAULT_METADATA_HOST}` : `${METADATA_HOST_VAR} names`;
28281
28281
  }
28282
- function get(url, signal) {
28282
+ function get(url, signal, lookup) {
28283
28283
  const { promise, resolve, reject } = Promise.withResolvers();
28284
28284
  const call = request(url, {
28285
28285
  agent,
28286
28286
  method: "GET",
28287
28287
  headers: { "Metadata-Flavor": "Google" },
28288
28288
  timeout: TIMEOUT_MS,
28289
- ...signal === undefined ? {} : { signal }
28289
+ ...signal === undefined ? {} : { signal },
28290
+ ...lookup === undefined ? {} : { lookup }
28290
28291
  }, (answer) => {
28291
28292
  const chunks = [];
28292
28293
  let read = 0;
@@ -28303,14 +28304,14 @@ function get(url, signal) {
28303
28304
  call.end();
28304
28305
  return promise;
28305
28306
  }
28306
- function metadataIdentity(audience, env = process.env) {
28307
+ function metadataIdentity(audience, env = process.env, options = {}) {
28307
28308
  return {
28308
28309
  async read(signal) {
28309
28310
  const url = tokenUrl(audience, env);
28310
28311
  const named = `the metadata server ${serverNamed(env)}`;
28311
28312
  let answer;
28312
28313
  try {
28313
- answer = await get(url, signal);
28314
+ answer = await get(url, signal, options.lookup);
28314
28315
  } catch (error) {
28315
28316
  throw new Error(`${named} could not be reached: ${errorClass(error)}`);
28316
28317
  }
@@ -30110,12 +30111,13 @@ function poolIdentity(options) {
30110
30111
  const mintEndpoint = `${iamCredentials}/v1/projects/-/serviceAccounts/${account}:generateIdToken`;
30111
30112
  const securityTokenServiceShown = urlForText(securityTokenService, STS_SETTING);
30112
30113
  const mintEndpointShown = requestForText(iamCredentials, mintEndpoint, IAM_SETTING);
30114
+ const send = options.fetch ?? fetch;
30113
30115
  const call = async (endpoint, bearer, body, member, signal) => {
30114
30116
  const signals = [AbortSignal.timeout(POOL_TIMEOUT_MS), signal].filter((one) => one !== undefined);
30115
30117
  let answer;
30116
30118
  let text;
30117
30119
  try {
30118
- answer = await fetch(endpoint, {
30120
+ answer = await send(endpoint, {
30119
30121
  method: "POST",
30120
30122
  headers: {
30121
30123
  "Content-Type": "application/json",
@@ -40533,14 +40533,15 @@ function tokenUrl(audience, env) {
40533
40533
  function serverNamed(env) {
40534
40534
  return (env[METADATA_HOST_VAR] ?? "").trim() === "" ? `at ${DEFAULT_METADATA_HOST}` : `${METADATA_HOST_VAR} names`;
40535
40535
  }
40536
- function get(url, signal) {
40536
+ function get(url, signal, lookup) {
40537
40537
  const { promise, resolve, reject } = Promise.withResolvers();
40538
40538
  const call = request(url, {
40539
40539
  agent,
40540
40540
  method: "GET",
40541
40541
  headers: { "Metadata-Flavor": "Google" },
40542
40542
  timeout: TIMEOUT_MS,
40543
- ...signal === undefined ? {} : { signal }
40543
+ ...signal === undefined ? {} : { signal },
40544
+ ...lookup === undefined ? {} : { lookup }
40544
40545
  }, (answer) => {
40545
40546
  const chunks = [];
40546
40547
  let read = 0;
@@ -40557,14 +40558,14 @@ function get(url, signal) {
40557
40558
  call.end();
40558
40559
  return promise;
40559
40560
  }
40560
- function metadataIdentity(audience, env = process.env) {
40561
+ function metadataIdentity(audience, env = process.env, options = {}) {
40561
40562
  return {
40562
40563
  async read(signal) {
40563
40564
  const url = tokenUrl(audience, env);
40564
40565
  const named = `the metadata server ${serverNamed(env)}`;
40565
40566
  let answer;
40566
40567
  try {
40567
- answer = await get(url, signal);
40568
+ answer = await get(url, signal, options.lookup);
40568
40569
  } catch (error) {
40569
40570
  throw new Error(`${named} could not be reached: ${errorClass(error)}`);
40570
40571
  }
@@ -42747,12 +42748,13 @@ function poolIdentity(options) {
42747
42748
  const mintEndpoint = `${iamCredentials}/v1/projects/-/serviceAccounts/${account}:generateIdToken`;
42748
42749
  const securityTokenServiceShown = urlForText(securityTokenService, STS_SETTING);
42749
42750
  const mintEndpointShown = requestForText(iamCredentials, mintEndpoint, IAM_SETTING);
42751
+ const send = options.fetch ?? fetch;
42750
42752
  const call = async (endpoint, bearer, body, member, signal) => {
42751
42753
  const signals = [AbortSignal.timeout(POOL_TIMEOUT_MS), signal].filter((one) => one !== undefined);
42752
42754
  let answer;
42753
42755
  let text;
42754
42756
  try {
42755
- answer = await fetch(endpoint, {
42757
+ answer = await send(endpoint, {
42756
42758
  method: "POST",
42757
42759
  headers: {
42758
42760
  "Content-Type": "application/json",
@@ -57834,7 +57836,7 @@ var import_nats5 = __toESM(require_mod4(), 1);
57834
57836
 
57835
57837
  // package.json
57836
57838
  var name2 = "@sjawhar/claude-envoy";
57837
- var version2 = "4.17.0";
57839
+ var version2 = "4.17.2";
57838
57840
  var legion = {
57839
57841
  daemonApiVersion: 199
57840
57842
  };
@@ -61498,7 +61500,7 @@ var PHASE_OP_SENTENCES = {
61498
61500
  };
61499
61501
  var STALE_ENTRY_INSTRUCTION = "End this turn without completing. The task of the entry the phase is on is owed to this claim, and the daemon sends it by itself. " + "That task is work of its own: do what it asks at the head it names and complete it with a handoff of its own, never this completion's " + "record, commit or verdict";
61500
61502
  function legionToolDescription(host) {
61501
- return "Perform the workflow operation the Legion daemon assigned this role. The daemon advances phases; this tool cannot spawn workers. " + (host.before ?? "") + "handoff_complete (phase workers alone: the daemon refuses an architect's completion, with ACCEPTANCE_IS_SIGN_OFF where nothing else refuses it first, since an architect accepts with sign_off; " + "the daemon accepts a completion only from the role working the issue's current phase, " + "or a role's first completion of the phase it left, which it records and which moves nothing, " + "and the checking role's report on a look of its closed issue's production check) reports this phase complete: `summary` (two sentences for the " + "architect), `verdict` pass|fail from the tester alone on a phase completion (the daemon refuses a verdict from " + "any other role there) and pass|pending|fail on a production check report (pending: production does not carry the merge " + "yet, or carries it with a requirement only the deploy can show still unobserved and a look still to follow). " + "A planning, implementing, testing or reviewing phase ends with a handoff record on the " + "Dispatch issue: write it with `dispatch handoff-write --issue <issue> --phase <plan|implement|test|review> --body-file <file>` before " + "calling. This call reads from Dispatch the newest record of the phase your role works or, once the issue has moved on, of the phase it left, " + "and reports it with `commit`, the head that record's body names " + "(`head`, the 40-character lower-case commit the work it reports was done against); in implementing, the implementer's must be the commit its " + "workspace stands on, `@-`, pushed to `legion/<issue>@origin`, so push the branch first; retro, the merger's completion and a phase you left with no record, or with an implement record naming no head, report the commit the workspace stands on. It " + "refuses, posting nothing, a phase you work with no record, a Dispatch that does not answer, and, in implementing, an implement record naming no head, an " + "implementer's `@-` not yet on `legion/<issue>@origin`, or an implement record whose head is not that pushed `@-`, each naming the remedy. A production check report " + "(the task whose first line is `Production check of <KEY>`, handed once the merge closed the issue to the role the check records) needs no " + "handoff and no commit: it carries its verdict and summary alone. A pending report also names `wake_at`, an RFC 3339 time: when you want the " + "next look. A pass, a fail, and a pending on the check's last look end the check, so none of them carries `wake_at` " + "(CHECK_WAKE_UNEXPECTED), and a pending on any other look is refused without one (CHECK_WAKE_REQUIRED). A report on an issue whose check is " + "closed or never opened is refused (CHECK_NOT_OPEN), and so is one from a role the check does not record (CHECK_ROLE_MISMATCH). " + `The completion that ends the retro carries \`plan_rating\` (${LEGION_PLAN_RATING_LEAST} to ${LEGION_PLAN_RATING_MOST}) and \`plan_reason\`, as ` + "skill://legion-retro says, and the daemon refuses a completion that breaks that skill's rating rule " + "(PLAN_RATING_REQUIRED, PLAN_RATING_UNEXPECTED or PLAN_RATING_INPUT). " + "The daemon refuses " + "HANDOFF_SESSION_MISMATCH (another session wrote the record), HANDOFF_NOT_NEW (the record is the one you named for your previous phase: " + "write this phase's handoff), " + "HANDOFF_STALE_ENTRY (this completion is of a phase entry behind the one your role's phases row names, because the phase was entered " + `again while your turn ran, and nothing was recorded. ${STALE_ENTRY_INSTRUCTION}), the implementer's completion of implementing with no open ` + "pull request on `legion/<issue>` and none recorded " + "merged (HANDOFF_NO_PULL_REQUEST: open it; one naming a closed pull request is the architect's to decide); a refused completion changed " + "nothing, so fix what it names and complete again. " + "ready_for_update answers the daemon's update message on this issue's pod: `round` is the round id that message names, and the " + "daemon takes your answer for that round alone. Push every commit you want kept to the issue branch " + "first. Then let each subagent and each background job that you started finish, or stop it. Commit and push what it made " + "before you answer. The daemon replaces the pod and its disk when the round ends. The round ends at the moment the message " + "names. It can end earlier, once every role has answered, no role is in a turn and each role's last report names no running " + "subagent or background job. No answer delays that moment, and the end of a turn is no answer. If a subagent or a background " + "job finishes after you answer, commit and push what it made. Then call ready_for_update again with the same round. " + "The call ends no phase. The daemon holds your next task until your process comes back on the new pod, in this same session. " + (host.after ?? "") + `What a later phase needs goes in your handoff; a question for another live role goes to its role topic with ${host.envoyPublish}.`;
61503
+ return "Perform the workflow operation the Legion daemon assigned this role. The daemon advances phases; this tool cannot spawn workers. " + (host.before ?? "") + "handoff_complete (phase workers alone: the daemon refuses an architect's completion, with ACCEPTANCE_IS_SIGN_OFF where nothing else refuses it first, since an architect accepts with sign_off; " + "the daemon accepts a completion only from the role working the issue's current phase, " + "or a role's first completion of the phase it left, which it records and which moves nothing, " + "and the checking role's report on a look of its closed issue's production check) reports this phase complete: `summary` (two sentences for the " + "architect), `verdict` pass|fail from the tester alone on a phase completion (the daemon refuses a verdict from " + "any other role there) and pass|pending|fail on a production check report (pending: production does not carry the merge " + "yet, or carries it with a requirement only the deploy can show still unobserved and a look still to follow; on the check's last look, only for an issue with no such requirement). " + "A planning, implementing, testing or reviewing phase ends with a handoff record on the " + "Dispatch issue: write it with `dispatch handoff-write --issue <issue> --phase <plan|implement|test|review> --body-file <file>` before " + "calling. This call reads from Dispatch the newest record of the phase your role works or, once the issue has moved on, of the phase it left, " + "and reports it with `commit`, the head that record's body names " + "(`head`, the 40-character lower-case commit the work it reports was done against); in implementing, the implementer's must be the commit its " + "workspace stands on, `@-`, pushed to `legion/<issue>@origin`, so push the branch first; retro, the merger's completion and a phase you left with no record, or with an implement record naming no head, report the commit the workspace stands on. It " + "refuses, posting nothing, a phase you work with no record, a Dispatch that does not answer, and, in implementing, an implement record naming no head, an " + "implementer's `@-` not yet on `legion/<issue>@origin`, or an implement record whose head is not that pushed `@-`, each naming the remedy. A production check report " + "(the task whose first line is `Production check of <KEY>`, handed once the merge closed the issue to the role the check records) needs no " + "handoff and no commit: it carries its verdict and summary alone. A pending report also names `wake_at`, an RFC 3339 time: when you want the " + "next look. A pass, a fail, and a pending on the check's last look end the check, so none of them carries `wake_at` " + "(CHECK_WAKE_UNEXPECTED), and a pending on any other look is refused without one (CHECK_WAKE_REQUIRED). A report on an issue whose check is " + "closed or never opened is refused (CHECK_NOT_OPEN), and so is one from a role the check does not record (CHECK_ROLE_MISMATCH). " + `The completion that ends the retro carries \`plan_rating\` (${LEGION_PLAN_RATING_LEAST} to ${LEGION_PLAN_RATING_MOST}) and \`plan_reason\`, as ` + "skill://legion-retro says, and the daemon refuses a completion that breaks that skill's rating rule " + "(PLAN_RATING_REQUIRED, PLAN_RATING_UNEXPECTED or PLAN_RATING_INPUT). " + "The daemon refuses " + "HANDOFF_SESSION_MISMATCH (another session wrote the record), HANDOFF_NOT_NEW (the record is the one you named for your previous phase: " + "write this phase's handoff), " + "HANDOFF_STALE_ENTRY (this completion is of a phase entry behind the one your role's phases row names, because the phase was entered " + `again while your turn ran, and nothing was recorded. ${STALE_ENTRY_INSTRUCTION}), the implementer's completion of implementing with no open ` + "pull request on `legion/<issue>` and none recorded " + "merged (HANDOFF_NO_PULL_REQUEST: open it; one naming a closed pull request is the architect's to decide); a refused completion changed " + "nothing, so fix what it names and complete again. " + "ready_for_update answers the daemon's update message on this issue's pod: `round` is the round id that message names, and the " + "daemon takes your answer for that round alone. Push every commit you want kept to the issue branch " + "first. Then let each subagent and each background job that you started finish, or stop it. Commit and push what it made " + "before you answer. The daemon replaces the pod and its disk when the round ends. The round ends at the moment the message " + "names. It can end earlier, once every role has answered, no role is in a turn and each role's last report names no running " + "subagent or background job. No answer delays that moment, and the end of a turn is no answer. If a subagent or a background " + "job finishes after you answer, commit and push what it made. Then call ready_for_update again with the same round. " + "The call ends no phase. The daemon holds your next task until your process comes back on the new pod, in this same session. " + (host.after ?? "") + `What a later phase needs goes in your handoff; a question for another live role goes to its role topic with ${host.envoyPublish}.`;
61502
61504
  }
61503
61505
  function pluginBuildOf(manifest) {
61504
61506
  return {
@@ -27054,14 +27054,15 @@ function tokenUrl(audience, env) {
27054
27054
  function serverNamed(env) {
27055
27055
  return (env[METADATA_HOST_VAR] ?? "").trim() === "" ? `at ${DEFAULT_METADATA_HOST}` : `${METADATA_HOST_VAR} names`;
27056
27056
  }
27057
- function get(url, signal) {
27057
+ function get(url, signal, lookup) {
27058
27058
  const { promise, resolve, reject } = Promise.withResolvers();
27059
27059
  const call = request(url, {
27060
27060
  agent,
27061
27061
  method: "GET",
27062
27062
  headers: { "Metadata-Flavor": "Google" },
27063
27063
  timeout: TIMEOUT_MS,
27064
- ...signal === undefined ? {} : { signal }
27064
+ ...signal === undefined ? {} : { signal },
27065
+ ...lookup === undefined ? {} : { lookup }
27065
27066
  }, (answer) => {
27066
27067
  const chunks = [];
27067
27068
  let read = 0;
@@ -27078,14 +27079,14 @@ function get(url, signal) {
27078
27079
  call.end();
27079
27080
  return promise;
27080
27081
  }
27081
- function metadataIdentity(audience, env = process.env) {
27082
+ function metadataIdentity(audience, env = process.env, options = {}) {
27082
27083
  return {
27083
27084
  async read(signal) {
27084
27085
  const url = tokenUrl(audience, env);
27085
27086
  const named = `the metadata server ${serverNamed(env)}`;
27086
27087
  let answer;
27087
27088
  try {
27088
- answer = await get(url, signal);
27089
+ answer = await get(url, signal, options.lookup);
27089
27090
  } catch (error) {
27090
27091
  throw new Error(`${named} could not be reached: ${errorClass(error)}`);
27091
27092
  }
@@ -28885,12 +28886,13 @@ function poolIdentity(options) {
28885
28886
  const mintEndpoint = `${iamCredentials}/v1/projects/-/serviceAccounts/${account}:generateIdToken`;
28886
28887
  const securityTokenServiceShown = urlForText(securityTokenService, STS_SETTING);
28887
28888
  const mintEndpointShown = requestForText(iamCredentials, mintEndpoint, IAM_SETTING);
28889
+ const send = options.fetch ?? fetch;
28888
28890
  const call = async (endpoint, bearer, body, member, signal) => {
28889
28891
  const signals = [AbortSignal.timeout(POOL_TIMEOUT_MS), signal].filter((one) => one !== undefined);
28890
28892
  let answer;
28891
28893
  let text;
28892
28894
  try {
28893
- answer = await fetch(endpoint, {
28895
+ answer = await send(endpoint, {
28894
28896
  method: "POST",
28895
28897
  headers: {
28896
28898
  "Content-Type": "application/json",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sjawhar/claude-envoy",
3
- "version": "4.17.0",
3
+ "version": "4.17.2",
4
4
  "license": "Apache-2.0",
5
5
  "description": "Claude Code plugin for Legion's Envoy bus",
6
6
  "type": "module",
package/scripts/build.ts CHANGED
@@ -19,7 +19,7 @@
19
19
  // buildBundles and buildLegionPlugin report reading; a file this script reads by path or
20
20
  // imports from outside the listed packages (.bun-version, scripts/third-party-notices.ts, the
21
21
  // scripts it runs) is listed by hand.
22
- import { cp, mkdir, readdir, readFile, realpath, writeFile } from "node:fs/promises"
22
+ import { chmod, cp, lstat, mkdir, readdir, readFile, realpath, writeFile } from "node:fs/promises"
23
23
  import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path"
24
24
  import { thirdPartyNotices } from "../../../scripts/third-party-notices"
25
25
  import { PHASE_HOOK_TOOL_NAME } from "../src/legion-phase-hook"
@@ -489,6 +489,21 @@ export async function buildCodexPlugin(out: string, dist?: string): Promise<void
489
489
  }
490
490
  if (dist === undefined) await buildBundles(join(out, "dist"))
491
491
  else await cp(dist, join(out, "dist"), { recursive: true })
492
+ // The pack keeps each file's mode as the disk has it, and the copies and writes above take the
493
+ // source's mode and the builder's umask: a build under umask 0002, which a systemd user unit
494
+ // runs with, ships group-writable files. Every entry of `out` is shipped, so each loses group and
495
+ // other write; every user keeps read, and search on each directory and execute on each file the
496
+ // owner can run. The published modes are then the same whoever builds.
497
+ for (const path of [
498
+ out,
499
+ ...(await readdir(out, { recursive: true })).map((entry) => join(out, entry)),
500
+ ]) {
501
+ const entry = await lstat(path)
502
+ if (entry.isSymbolicLink()) continue
503
+ const mode = entry.mode & 0o7777
504
+ const runnable = entry.isDirectory() || (mode & 0o100) !== 0
505
+ await chmod(path, (mode & ~0o022) | 0o444 | (runnable ? 0o111 : 0))
506
+ }
492
507
  }
493
508
 
494
509
  const USAGE =
@@ -17,7 +17,9 @@
17
17
  # rather than deleting them, and the list of skills is read off the links rather than written out
18
18
  # a second time here.
19
19
  #
20
- # Where no postpack runs — bun runs none when a pack fails — `--restore` puts the links back.
20
+ # Where no postpack runs — bun runs none when a pack fails — `--restore` puts the links back. The
21
+ # prepack's last step takes group and other write from every shipped path, so the published modes
22
+ # do not depend on the packer's umask.
21
23
  #
22
24
  # npm and bun both run these with the package root as the working directory, as that script's
23
25
  # header says, so the package is $PWD and the repository $PWD/../..:
@@ -131,11 +133,39 @@ if [ ${#staged[@]} -gt 0 ]; then
131
133
  refuse "bash scripts/pack-skills.sh --restore puts those links back"
132
134
  fi
133
135
 
134
- # The swap, under a trap that puts back every link it has replaced. What is left to fail here is
135
- # the filesystem rather than an entry, and a failure between the first swap and the last would
136
- # leave tracked links as copied directories. The trap is disarmed the moment the loop finishes,
137
- # and nowhere earlier: the pack this prepack runs for needs the real directories, and the
138
- # postpack puts the links back after it.
136
+ # The paths the pack ships, read here, before the swap, so that every refusal comes before a link is
137
+ # touched. The tarball keeps each shipped file's mode as it is on disk, and that mode is the
138
+ # packer's umask's: a checkout and a pack under umask 0002, which a systemd user unit runs with,
139
+ # give 0664 and 0775 where umask 022 gives 0644 and 0755, and the copies the swap makes take the
140
+ # packer's umask too. So every path the pack ships loses group and other write after the swap: each
141
+ # `files` entry that exists (a `<dir>/**` entry is its directory), and what `bun pm pack` ships
142
+ # whatever `files` says (bun 1.4.4: the manifest and the root's README*, LICENSE* and LICENCE*
143
+ # files). Every user keeps read, search on each directory and execute on each file already
144
+ # executable (chmod's X).
145
+ command -v jq > /dev/null 2>&1 || refuse "jq is required to set the shipped files' modes"
146
+ files_list=$(jq -r '.files | if type == "array" then .[] else empty end' package.json) ||
147
+ refuse "package.json could not be read for its files list"
148
+ [ -n "$files_list" ] || refuse "package.json has no files list, or an empty one, to set the shipped files' modes from"
149
+ shopt -s nullglob nocaseglob
150
+ shipped=(package.json README* LICENSE* LICENCE*)
151
+ shopt -u nocaseglob
152
+ while IFS= read -r entry; do
153
+ case $entry in
154
+ */\*\*) root=${entry%/\*\*} ;;
155
+ *[*?[]*) refuse "files entry \"$entry\" is a pattern whose paths this prepack cannot set the modes of; list a path, or a directory as <dir>/**" ;;
156
+ *) root=$entry ;;
157
+ esac
158
+ if [ -e "$root" ]; then
159
+ shipped+=("$root")
160
+ fi
161
+ done <<< "$files_list"
162
+
163
+ # The swap and the modes, under a trap that puts back every link it has replaced. What is left to
164
+ # fail here is the filesystem rather than an entry, and a failure between the first swap and the
165
+ # chmod would leave tracked links as copied directories. The trap is disarmed the moment the chmod
166
+ # has passed, and nowhere earlier: the pack this prepack runs for needs the real directories, and
167
+ # the postpack puts the links back after it. `shipped` names skills/ itself, so the chmod reaches
168
+ # the copies the swap made.
139
169
  swapped=()
140
170
  trap '[ ${#swapped[@]} -eq 0 ] || link_back "${swapped[@]}"' EXIT
141
171
  for name in "${names[@]}"; do
@@ -143,4 +173,5 @@ for name in "${names[@]}"; do
143
173
  swapped+=("$name")
144
174
  cp -R "$repo_skills/$name" "skills/$name"
145
175
  done
176
+ chmod -R go-w,a+rX -- "${shipped[@]}"
146
177
  trap - EXIT