@h-rig/standard-plugin 0.0.6-alpha.81 → 0.0.6-alpha.83

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.
@@ -11,9 +11,9 @@ function createEnvGitHubCredentialProvider() {
11
11
  return {
12
12
  async resolveGitHubToken(input) {
13
13
  if (input.purpose === "selected-repo") {
14
- return { token: cleanToken(process.env.RIG_GITHUB_SELECTED_TOKEN ?? null) ?? "", source: "signed-in-user" };
14
+ return { token: cleanToken(process.env.RIG_GITHUB_SELECTED_TOKEN ?? process.env.RIG_GITHUB_TOKEN ?? null) ?? "", source: "signed-in-user" };
15
15
  }
16
- const token = cleanToken(process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN ?? null);
16
+ const token = cleanToken(process.env.RIG_GITHUB_TOKEN ?? process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN ?? null);
17
17
  if (!token) {
18
18
  throw new Error("No host GitHub token is configured for admin fallback.");
19
19
  }
@@ -44,12 +44,12 @@ function createStateGitHubCredentialProvider(options = {}) {
44
44
  async resolveGitHubToken(input) {
45
45
  const token = readToken();
46
46
  if (input.purpose === "selected-repo") {
47
- return { token: token ?? "", source: "signed-in-user" };
47
+ return { token: token ?? cleanToken(process.env.RIG_GITHUB_SELECTED_TOKEN ?? process.env.RIG_GITHUB_TOKEN ?? null) ?? "", source: "signed-in-user" };
48
48
  }
49
49
  if (token) {
50
50
  return { token, source: "signed-in-user" };
51
51
  }
52
- const fallback = cleanToken(process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN ?? null);
52
+ const fallback = cleanToken(process.env.RIG_GITHUB_TOKEN ?? process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN ?? null);
53
53
  if (!fallback) {
54
54
  throw new Error("No signed-in GitHub token is stored for Rig and no host admin fallback token is configured.");
55
55
  }
@@ -183,13 +183,21 @@ function isRigStickyStatusComment(body) {
183
183
  return body.includes(RIG_STATUS_COMMENT_MARKER);
184
184
  }
185
185
  function ghSpawnOptions(extraEnv, timeoutMs) {
186
- if (!extraEnv)
187
- return { encoding: "utf-8", timeout: timeoutMs };
188
- return { encoding: "utf-8", timeout: timeoutMs, env: { ...process.env, ...extraEnv } };
186
+ return {
187
+ encoding: "utf-8",
188
+ timeout: timeoutMs,
189
+ env: {
190
+ ...process.env,
191
+ ...process.env.GH_TOKEN !== undefined ? { GH_TOKEN: process.env.GH_TOKEN } : {},
192
+ ...process.env.GITHUB_TOKEN !== undefined ? { GITHUB_TOKEN: process.env.GITHUB_TOKEN } : {},
193
+ ...process.env.RIG_GITHUB_TOKEN !== undefined ? { RIG_GITHUB_TOKEN: process.env.RIG_GITHUB_TOKEN } : {},
194
+ ...extraEnv ?? {}
195
+ }
196
+ };
189
197
  }
190
198
  function credentialEnv(token) {
191
199
  const clean = token?.trim() ?? "";
192
- return { GH_TOKEN: clean, GITHUB_TOKEN: clean };
200
+ return { GH_TOKEN: clean, GITHUB_TOKEN: clean, RIG_GITHUB_TOKEN: clean };
193
201
  }
194
202
  async function resolveCredentialEnv(opts, purpose) {
195
203
  if (!opts.credentialProvider)
@@ -204,24 +212,31 @@ async function resolveCredentialEnv(opts, purpose) {
204
212
  const resolved = await opts.credentialProvider.resolveGitHubToken(input);
205
213
  return credentialEnv(resolved.token);
206
214
  }
215
+ function tokenDiagnostic(value) {
216
+ const clean = value?.trim() ?? "";
217
+ return clean ? `present(len=${clean.length})` : "missing";
218
+ }
207
219
  function runGh(bin, args, spawn, extraEnv, timeoutMs) {
208
- const res = spawn(bin, [...args], ghSpawnOptions(extraEnv, timeoutMs));
209
- assertGhSuccess(args, res);
220
+ const options = ghSpawnOptions(extraEnv, timeoutMs);
221
+ const res = spawn(bin, [...args], options);
222
+ assertGhSuccess(args, res, options.env);
210
223
  if (!res.stdout || res.stdout.trim() === "")
211
224
  return [];
212
225
  return JSON.parse(res.stdout);
213
226
  }
214
227
  function runGhVoid(bin, args, spawn, extraEnv, timeoutMs) {
215
- const res = spawn(bin, [...args], ghSpawnOptions(extraEnv, timeoutMs));
216
- assertGhSuccess(args, res);
228
+ const options = ghSpawnOptions(extraEnv, timeoutMs);
229
+ const res = spawn(bin, [...args], options);
230
+ assertGhSuccess(args, res, options.env);
217
231
  }
218
- function assertGhSuccess(args, res) {
232
+ function assertGhSuccess(args, res, env) {
219
233
  if (res.error) {
220
234
  const msg = res.error.message ?? String(res.error);
221
235
  throw new Error(`gh CLI not available \u2014 install gh (brew install gh / apt install gh): ${msg}`);
222
236
  }
223
237
  if (res.status !== 0) {
224
- throw new Error(`gh ${args.join(" ")} failed (exit ${res.status}): ${res.stderr}`);
238
+ throw new Error(`gh ${args.join(" ")} failed (exit ${res.status}): ${res.stderr}
239
+ [rig gh env:standard-plugin] GH_TOKEN=${tokenDiagnostic(env.GH_TOKEN)} GITHUB_TOKEN=${tokenDiagnostic(env.GITHUB_TOKEN)} RIG_GITHUB_TOKEN=${tokenDiagnostic(env.RIG_GITHUB_TOKEN)}`);
225
240
  }
226
241
  }
227
242
  function statusLabelFor(status) {
package/dist/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // @bun
2
2
  // packages/standard-plugin/src/index.ts
3
+ import { resolve as resolve3 } from "path";
3
4
  import { definePlugin } from "@rig/core";
4
5
 
5
6
  // packages/standard-plugin/src/github-issues-source.ts
@@ -14,9 +15,9 @@ function createEnvGitHubCredentialProvider() {
14
15
  return {
15
16
  async resolveGitHubToken(input) {
16
17
  if (input.purpose === "selected-repo") {
17
- return { token: cleanToken(process.env.RIG_GITHUB_SELECTED_TOKEN ?? null) ?? "", source: "signed-in-user" };
18
+ return { token: cleanToken(process.env.RIG_GITHUB_SELECTED_TOKEN ?? process.env.RIG_GITHUB_TOKEN ?? null) ?? "", source: "signed-in-user" };
18
19
  }
19
- const token = cleanToken(process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN ?? null);
20
+ const token = cleanToken(process.env.RIG_GITHUB_TOKEN ?? process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN ?? null);
20
21
  if (!token) {
21
22
  throw new Error("No host GitHub token is configured for admin fallback.");
22
23
  }
@@ -47,12 +48,12 @@ function createStateGitHubCredentialProvider(options = {}) {
47
48
  async resolveGitHubToken(input) {
48
49
  const token = readToken();
49
50
  if (input.purpose === "selected-repo") {
50
- return { token: token ?? "", source: "signed-in-user" };
51
+ return { token: token ?? cleanToken(process.env.RIG_GITHUB_SELECTED_TOKEN ?? process.env.RIG_GITHUB_TOKEN ?? null) ?? "", source: "signed-in-user" };
51
52
  }
52
53
  if (token) {
53
54
  return { token, source: "signed-in-user" };
54
55
  }
55
- const fallback = cleanToken(process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN ?? null);
56
+ const fallback = cleanToken(process.env.RIG_GITHUB_TOKEN ?? process.env.GH_TOKEN ?? process.env.GITHUB_TOKEN ?? null);
56
57
  if (!fallback) {
57
58
  throw new Error("No signed-in GitHub token is stored for Rig and no host admin fallback token is configured.");
58
59
  }
@@ -170,13 +171,21 @@ function isRigStickyStatusComment(body) {
170
171
  return body.includes(RIG_STATUS_COMMENT_MARKER);
171
172
  }
172
173
  function ghSpawnOptions(extraEnv, timeoutMs) {
173
- if (!extraEnv)
174
- return { encoding: "utf-8", timeout: timeoutMs };
175
- return { encoding: "utf-8", timeout: timeoutMs, env: { ...process.env, ...extraEnv } };
174
+ return {
175
+ encoding: "utf-8",
176
+ timeout: timeoutMs,
177
+ env: {
178
+ ...process.env,
179
+ ...process.env.GH_TOKEN !== undefined ? { GH_TOKEN: process.env.GH_TOKEN } : {},
180
+ ...process.env.GITHUB_TOKEN !== undefined ? { GITHUB_TOKEN: process.env.GITHUB_TOKEN } : {},
181
+ ...process.env.RIG_GITHUB_TOKEN !== undefined ? { RIG_GITHUB_TOKEN: process.env.RIG_GITHUB_TOKEN } : {},
182
+ ...extraEnv ?? {}
183
+ }
184
+ };
176
185
  }
177
186
  function credentialEnv(token) {
178
187
  const clean = token?.trim() ?? "";
179
- return { GH_TOKEN: clean, GITHUB_TOKEN: clean };
188
+ return { GH_TOKEN: clean, GITHUB_TOKEN: clean, RIG_GITHUB_TOKEN: clean };
180
189
  }
181
190
  async function resolveCredentialEnv(opts, purpose) {
182
191
  if (!opts.credentialProvider)
@@ -191,24 +200,31 @@ async function resolveCredentialEnv(opts, purpose) {
191
200
  const resolved = await opts.credentialProvider.resolveGitHubToken(input);
192
201
  return credentialEnv(resolved.token);
193
202
  }
203
+ function tokenDiagnostic(value) {
204
+ const clean = value?.trim() ?? "";
205
+ return clean ? `present(len=${clean.length})` : "missing";
206
+ }
194
207
  function runGh(bin, args, spawn, extraEnv, timeoutMs) {
195
- const res = spawn(bin, [...args], ghSpawnOptions(extraEnv, timeoutMs));
196
- assertGhSuccess(args, res);
208
+ const options = ghSpawnOptions(extraEnv, timeoutMs);
209
+ const res = spawn(bin, [...args], options);
210
+ assertGhSuccess(args, res, options.env);
197
211
  if (!res.stdout || res.stdout.trim() === "")
198
212
  return [];
199
213
  return JSON.parse(res.stdout);
200
214
  }
201
215
  function runGhVoid(bin, args, spawn, extraEnv, timeoutMs) {
202
- const res = spawn(bin, [...args], ghSpawnOptions(extraEnv, timeoutMs));
203
- assertGhSuccess(args, res);
216
+ const options = ghSpawnOptions(extraEnv, timeoutMs);
217
+ const res = spawn(bin, [...args], options);
218
+ assertGhSuccess(args, res, options.env);
204
219
  }
205
- function assertGhSuccess(args, res) {
220
+ function assertGhSuccess(args, res, env) {
206
221
  if (res.error) {
207
222
  const msg = res.error.message ?? String(res.error);
208
223
  throw new Error(`gh CLI not available \u2014 install gh (brew install gh / apt install gh): ${msg}`);
209
224
  }
210
225
  if (res.status !== 0) {
211
- throw new Error(`gh ${args.join(" ")} failed (exit ${res.status}): ${res.stderr}`);
226
+ throw new Error(`gh ${args.join(" ")} failed (exit ${res.status}): ${res.stderr}
227
+ [rig gh env:standard-plugin] GH_TOKEN=${tokenDiagnostic(env.GH_TOKEN)} GITHUB_TOKEN=${tokenDiagnostic(env.GITHUB_TOKEN)} RIG_GITHUB_TOKEN=${tokenDiagnostic(env.RIG_GITHUB_TOKEN)}`);
212
228
  }
213
229
  }
214
230
  function statusLabelFor(status) {
@@ -610,13 +626,13 @@ function standardPlugin(opts = {}) {
610
626
  id: "std:github-issues",
611
627
  kind: "github-issues",
612
628
  description: "GitHub Issues via gh CLI",
613
- factory(config) {
629
+ factory(config, context) {
614
630
  const options = {
615
631
  owner: requireStringField(config, "owner", "github-issues"),
616
632
  repo: requireStringField(config, "repo", "github-issues")
617
633
  };
618
- if (opts.githubCredentialProvider)
619
- options.credentialProvider = opts.githubCredentialProvider;
634
+ const credentialProviderOptions = context?.projectRoot ? { stateDir: resolve3(context.projectRoot, ".rig", "state") } : {};
635
+ options.credentialProvider = opts.githubCredentialProvider ?? createStateGitHubCredentialProvider(credentialProviderOptions);
620
636
  if (opts.githubWorkspaceId)
621
637
  options.workspaceId = opts.githubWorkspaceId;
622
638
  if (opts.githubUserId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@h-rig/standard-plugin",
3
- "version": "0.0.6-alpha.81",
3
+ "version": "0.0.6-alpha.83",
4
4
  "type": "module",
5
5
  "description": "Rig package",
6
6
  "license": "UNLICENSED",
@@ -21,8 +21,8 @@
21
21
  "module": "./dist/src/index.js",
22
22
  "types": "./dist/src/index.d.ts",
23
23
  "dependencies": {
24
- "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.81",
25
- "@rig/core": "npm:@h-rig/core@0.0.6-alpha.81",
24
+ "@rig/contracts": "npm:@h-rig/contracts@0.0.6-alpha.83",
25
+ "@rig/core": "npm:@h-rig/core@0.0.6-alpha.83",
26
26
  "effect": "4.0.0-beta.78"
27
27
  }
28
28
  }