agent-gear 2.5.0 → 2.6.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 (93) hide show
  1. package/AGENTS.md +48 -4
  2. package/dist/acp/__fixtures__/opencode-2.0.31-capabilities.json +25 -0
  3. package/dist/acp/bridge.d.ts +23 -1
  4. package/dist/acp/bridge.d.ts.map +1 -1
  5. package/dist/acp/bridge.js +152 -17
  6. package/dist/acp/bridge.js.map +1 -1
  7. package/dist/acp/bridge.test.js +366 -1
  8. package/dist/acp/bridge.test.js.map +1 -1
  9. package/dist/acp/capabilities.d.ts +81 -0
  10. package/dist/acp/capabilities.d.ts.map +1 -0
  11. package/dist/acp/capabilities.js +211 -0
  12. package/dist/acp/capabilities.js.map +1 -0
  13. package/dist/acp/capabilities.test.d.ts +2 -0
  14. package/dist/acp/capabilities.test.d.ts.map +1 -0
  15. package/dist/acp/capabilities.test.js +156 -0
  16. package/dist/acp/capabilities.test.js.map +1 -0
  17. package/dist/acp/elicitation.integration.test.d.ts +2 -0
  18. package/dist/acp/elicitation.integration.test.d.ts.map +1 -0
  19. package/dist/acp/elicitation.integration.test.js +98 -0
  20. package/dist/acp/elicitation.integration.test.js.map +1 -0
  21. package/dist/acp/prober.d.ts +4 -0
  22. package/dist/acp/prober.d.ts.map +1 -1
  23. package/dist/acp/prober.js +1 -0
  24. package/dist/acp/prober.js.map +1 -1
  25. package/dist/acp/spawner.d.ts.map +1 -1
  26. package/dist/acp/spawner.js +3 -0
  27. package/dist/acp/spawner.js.map +1 -1
  28. package/dist/acp/sync-bridge.d.ts.map +1 -1
  29. package/dist/acp/sync-bridge.js +5 -1
  30. package/dist/acp/sync-bridge.js.map +1 -1
  31. package/dist/cloud-host/supervisor.d.ts +13 -0
  32. package/dist/cloud-host/supervisor.d.ts.map +1 -1
  33. package/dist/cloud-host/supervisor.js +21 -0
  34. package/dist/cloud-host/supervisor.js.map +1 -1
  35. package/dist/cloud-host/supervisor.test.js +71 -0
  36. package/dist/cloud-host/supervisor.test.js.map +1 -1
  37. package/dist/github/credential-manager.d.ts +70 -0
  38. package/dist/github/credential-manager.d.ts.map +1 -0
  39. package/dist/github/credential-manager.js +205 -0
  40. package/dist/github/credential-manager.js.map +1 -0
  41. package/dist/github/credential-manager.test.d.ts +2 -0
  42. package/dist/github/credential-manager.test.d.ts.map +1 -0
  43. package/dist/github/credential-manager.test.js +215 -0
  44. package/dist/github/credential-manager.test.js.map +1 -0
  45. package/dist/github/gh-config.d.ts +17 -0
  46. package/dist/github/gh-config.d.ts.map +1 -0
  47. package/dist/github/gh-config.js +68 -0
  48. package/dist/github/gh-config.js.map +1 -0
  49. package/dist/github/gh-config.test.d.ts +2 -0
  50. package/dist/github/gh-config.test.d.ts.map +1 -0
  51. package/dist/github/gh-config.test.js +90 -0
  52. package/dist/github/gh-config.test.js.map +1 -0
  53. package/dist/socketio-client.d.ts +12 -0
  54. package/dist/socketio-client.d.ts.map +1 -1
  55. package/dist/socketio-client.github.test.d.ts +2 -0
  56. package/dist/socketio-client.github.test.d.ts.map +1 -0
  57. package/dist/socketio-client.github.test.js +66 -0
  58. package/dist/socketio-client.github.test.js.map +1 -0
  59. package/dist/socketio-client.js +115 -65
  60. package/dist/socketio-client.js.map +1 -1
  61. package/dist/socketio-client.test.js +251 -1
  62. package/dist/socketio-client.test.js.map +1 -1
  63. package/dist/workload-executor.d.ts +14 -1
  64. package/dist/workload-executor.d.ts.map +1 -1
  65. package/dist/workload-executor.js +33 -3
  66. package/dist/workload-executor.js.map +1 -1
  67. package/dist/workload-executor.test.js +106 -2
  68. package/dist/workload-executor.test.js.map +1 -1
  69. package/package.json +1 -1
  70. package/src/acp/__fixtures__/fake-elicitation-agent.mjs +113 -0
  71. package/src/acp/__fixtures__/opencode-2.0.31-capabilities.json +25 -0
  72. package/src/acp/bridge.test.ts +480 -1
  73. package/src/acp/bridge.ts +163 -18
  74. package/src/acp/capabilities.test.ts +200 -0
  75. package/src/acp/capabilities.ts +274 -0
  76. package/src/acp/elicitation.integration.test.ts +126 -0
  77. package/src/acp/prober.ts +4 -0
  78. package/src/acp/spawner.ts +3 -0
  79. package/src/acp/sync-bridge.ts +5 -1
  80. package/src/cloud-host/supervisor.test.ts +96 -1
  81. package/src/cloud-host/supervisor.ts +37 -0
  82. package/src/github/credential-manager.test.ts +268 -0
  83. package/src/github/credential-manager.ts +251 -0
  84. package/src/github/gh-config.test.ts +103 -0
  85. package/src/github/gh-config.ts +76 -0
  86. package/src/socketio-client.github.test.ts +76 -0
  87. package/src/socketio-client.test.ts +306 -1
  88. package/src/socketio-client.ts +113 -53
  89. package/src/workload-executor.test.ts +144 -2
  90. package/src/workload-executor.ts +48 -2
  91. package/tests/acp-sync-bridge.test.ts +5 -1
  92. package/tests/socketio-client.test.ts +2 -2
  93. package/vitest.config.ts +5 -1
@@ -1,5 +1,5 @@
1
- import { describe, it, expect, afterEach } from 'vitest';
2
- import { mkdtemp, mkdir, rm, access } from 'node:fs/promises';
1
+ import { describe, it, expect, afterEach, vi } from 'vitest';
2
+ import { mkdtemp, mkdir, rm, access, writeFile } from 'node:fs/promises';
3
3
  import { join } from 'node:path';
4
4
  import { setTimeout as delay } from 'node:timers/promises';
5
5
  import {
@@ -676,3 +676,145 @@ describe('WorkloadExecutor container env + secret redaction (T-AG13/T-AG14)', ()
676
676
  expect(redactSecrets('nothing to hide', secrets)).toBe('nothing to hide');
677
677
  });
678
678
  });
679
+
680
+ describe('WorkloadExecutor githubAuth prefetch (T-WE-G)', () => {
681
+ const dirs: string[] = [];
682
+
683
+ afterEach(async () => {
684
+ await Promise.all(dirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
685
+ });
686
+
687
+ async function tmp(): Promise<string> {
688
+ const dir = await makeTmpDir();
689
+ dirs.push(dir);
690
+ return dir;
691
+ }
692
+
693
+ it('T-WE-G1: githubAuth=true calls the hook once before the first script runs', async () => {
694
+ const executor = new WorkloadExecutor();
695
+ const dir = await tmp();
696
+ const marker = join(dir, 'hook.marker');
697
+ const { results, sink } = collect();
698
+ const calls: string[] = [];
699
+
700
+ const outcome = await executor.runBatch(
701
+ {
702
+ phase: 'init',
703
+ githubAuth: true,
704
+ items: [
705
+ { logId: 'g1', workloadName: 'One', script: `test -f "${marker}" && echo ready`, timeoutMs: 5000 },
706
+ { logId: 'g2', workloadName: 'Two', script: `test -f "${marker}" && echo ready`, timeoutMs: 5000 },
707
+ ],
708
+ },
709
+ sink,
710
+ {
711
+ beforeGithubAuth: async () => {
712
+ calls.push('hook');
713
+ await writeFile(marker, 'written');
714
+ },
715
+ },
716
+ );
717
+
718
+ expect(calls).toEqual(['hook']);
719
+ expect(outcome.failedCount).toBe(0);
720
+ expect(results.map((result) => result.status)).toEqual(['success', 'success']);
721
+ expect(results.map((result) => result.log.trim())).toEqual(['ready', 'ready']);
722
+ });
723
+
724
+ it('T-WE-G2: hook failure reports failed for every item and never spawns scripts', async () => {
725
+ const executor = new WorkloadExecutor();
726
+ const dir = await tmp();
727
+ const marker = join(dir, 'should-not-exist');
728
+ const { results, sink } = collect();
729
+
730
+ const outcome = await executor.runBatch(
731
+ {
732
+ phase: 'init',
733
+ githubAuth: true,
734
+ items: [
735
+ { logId: 'g1', workloadName: 'One', script: `touch "${marker}"`, timeoutMs: 5000 },
736
+ { logId: 'g2', workloadName: 'Two', script: `touch "${marker}"`, timeoutMs: 5000 },
737
+ ],
738
+ },
739
+ sink,
740
+ {
741
+ beforeGithubAuth: async () => {
742
+ throw new Error('未设置 Github 项目');
743
+ },
744
+ },
745
+ );
746
+
747
+ expect(outcome.failedCount).toBe(2);
748
+ expect(outcome.total).toBe(2);
749
+ expect(results.map((result) => result.status)).toEqual(['failed', 'failed']);
750
+ expect(results.map((result) => result.log)).toEqual([
751
+ 'Github 凭据申请失败:未设置 Github 项目',
752
+ 'Github 凭据申请失败:未设置 Github 项目',
753
+ ]);
754
+ expect(await fileExists(marker)).toBe(false);
755
+ });
756
+
757
+ it('T-WE-G3: no githubAuth field keeps legacy behavior and never calls the hook', async () => {
758
+ const executor = new WorkloadExecutor();
759
+ const { results, sink } = collect();
760
+ const hook = vi.fn(async () => {});
761
+
762
+ const outcome = await executor.runBatch(
763
+ {
764
+ phase: 'init',
765
+ items: [{ logId: 'legacy', workloadName: 'Legacy', script: 'echo legacy', timeoutMs: 5000 }],
766
+ },
767
+ sink,
768
+ { beforeGithubAuth: hook },
769
+ );
770
+
771
+ expect(hook).not.toHaveBeenCalled();
772
+ expect(outcome.failedCount).toBe(0);
773
+ expect(results.map((result) => result.status)).toEqual(['success']);
774
+ expect(results[0].log.trim()).toBe('legacy');
775
+ });
776
+
777
+ it('T-WE-G4: githubAuth=false is accepted and behaves like the legacy payload', async () => {
778
+ const executor = new WorkloadExecutor();
779
+ const { results, sink } = collect();
780
+ const hook = vi.fn(async () => {});
781
+
782
+ const outcome = await executor.runBatch(
783
+ {
784
+ phase: 'post',
785
+ githubAuth: false,
786
+ items: [{ logId: 'off', workloadName: 'Off', script: 'echo off', timeoutMs: 5000 }],
787
+ },
788
+ sink,
789
+ { beforeGithubAuth: hook },
790
+ );
791
+
792
+ expect(hook).not.toHaveBeenCalled();
793
+ expect(outcome.failedCount).toBe(0);
794
+ expect(results[0].status).toBe('success');
795
+ });
796
+
797
+ it('T-WE-G2b: redacts secrets from the hook failure reason', async () => {
798
+ const executor = new WorkloadExecutor();
799
+ const { results, sink } = collect();
800
+ const secret = 'zag_k_1_super_secret';
801
+
802
+ await executor.runBatch(
803
+ {
804
+ phase: 'init',
805
+ githubAuth: true,
806
+ env: { ZAG_HOST_KEY: secret },
807
+ items: [{ logId: 'redact', workloadName: 'Redact', script: 'echo nope', timeoutMs: 5000 }],
808
+ },
809
+ sink,
810
+ {
811
+ beforeGithubAuth: async () => {
812
+ throw new Error(`hook failed with ${secret}`);
813
+ },
814
+ },
815
+ );
816
+
817
+ expect(results[0].log).toContain(REDACTED);
818
+ expect(results[0].log).not.toContain(secret);
819
+ });
820
+ });
@@ -44,6 +44,20 @@ export interface WorkloadRunPayload {
44
44
  * 对批次内所有 item 生效;`item.params` 派生的 `WORKLOAD_PARAM_*` 同名时优先。
45
45
  */
46
46
  env?: Record<string, string>;
47
+ /**
48
+ * `true` 时必须在执行本批第一条脚本前完成 gh 凭据申请与写入(由 `beforeGithubAuth` 承担);
49
+ * 缺省/false 行为与旧版完全一致。
50
+ */
51
+ githubAuth?: boolean;
52
+ }
53
+
54
+ /** `runBatch` 的可选行为注入(默认空实现,保证旧调用方零变化)。 */
55
+ export interface WorkloadRunOptions {
56
+ /**
57
+ * `payload.githubAuth === true` 时、执行首条脚本前调用一次。
58
+ * 抛错时本批所有 item 直接回报 `failed`,且不启动任何脚本。
59
+ */
60
+ beforeGithubAuth?: (payload: WorkloadRunPayload) => Promise<void>;
47
61
  }
48
62
 
49
63
  /** 需要在日志/错误/脚本输出中脱敏的环境变量名(契约 §2.9「云电脑初始化 env」)。 */
@@ -273,12 +287,16 @@ export class WorkloadExecutor {
273
287
  /**
274
288
  * 执行一个批次。若已有批次在跑,先终止其进程组并停止推进,再执行新批次。
275
289
  */
276
- runBatch(payload: WorkloadRunPayload, onResult: WorkloadResultSink): Promise<WorkloadBatchOutcome> {
290
+ runBatch(
291
+ payload: WorkloadRunPayload,
292
+ onResult: WorkloadResultSink,
293
+ options: WorkloadRunOptions = {},
294
+ ): Promise<WorkloadBatchOutcome> {
277
295
  this.interruptActive();
278
296
 
279
297
  const run: ActiveRun = { cancelled: false, child: null };
280
298
  this.active = run;
281
- const promise = this.executeBatch(payload, onResult, run).finally(() => {
299
+ const promise = this.executeBatch(payload, onResult, run, options).finally(() => {
282
300
  // 仅当自己仍是当前批次时才清空(被打断时 active 已指向新批次)
283
301
  if (this.active === run) {
284
302
  this.active = null;
@@ -293,6 +311,7 @@ export class WorkloadExecutor {
293
311
  payload: WorkloadRunPayload,
294
312
  onResult: WorkloadResultSink,
295
313
  run: ActiveRun,
314
+ options: WorkloadRunOptions = {},
296
315
  ): Promise<WorkloadBatchOutcome> {
297
316
  const items = Array.isArray(payload?.items) ? payload.items : [];
298
317
  const total = items.length;
@@ -310,6 +329,33 @@ export class WorkloadExecutor {
310
329
  const containerEnv = normalizeContainerEnv(payload.env);
311
330
  const secrets = collectSecretValues(process.env, containerEnv);
312
331
 
332
+ // Github 凭据预取:仅在显式 `githubAuth === true` 时触发,失败则整批逐条 failed、不启动脚本。
333
+ // 缺省/false 时不调用 hook,行为与旧版完全一致。
334
+ if (payload.githubAuth === true && options.beforeGithubAuth) {
335
+ try {
336
+ await options.beforeGithubAuth(payload);
337
+ } catch (error) {
338
+ if (run.cancelled) return outcome();
339
+ const reason = error instanceof Error ? error.message : String(error);
340
+ const message = redactSecrets(`Github 凭据申请失败:${reason}`, secrets);
341
+ const now = nowIso();
342
+ for (const item of items) {
343
+ if (run.cancelled) return outcome();
344
+ failedCount += 1;
345
+ this.report(onResult, {
346
+ logId: item.logId,
347
+ status: 'failed',
348
+ exitCode: null,
349
+ log: message,
350
+ startedAt: now,
351
+ finishedAt: nowIso(),
352
+ });
353
+ }
354
+ return outcome();
355
+ }
356
+ if (run.cancelled) return outcome();
357
+ }
358
+
313
359
  for (const item of items) {
314
360
  if (run.cancelled) return outcome();
315
361
 
@@ -65,7 +65,11 @@ describe('AcpSyncBridge', () => {
65
65
  expect(mockSpawner.start).toHaveBeenCalledOnce();
66
66
  expect(mc().initialize).toHaveBeenCalledWith({
67
67
  protocolVersion: 1,
68
- clientCapabilities: {},
68
+ // 显式值断言(非 CLIENT_CAPABILITIES 自引用)
69
+ clientCapabilities: {
70
+ session: { configOptions: { boolean: {} } },
71
+ elicitation: { form: {}, url: {} },
72
+ },
69
73
  clientInfo: { name: 'agent-gear', version: '1.0.0' },
70
74
  });
71
75
  });
@@ -229,7 +229,7 @@ describe('SocketIO Client', () => {
229
229
  expect(mockSocket.emit).toHaveBeenCalledWith('register', {
230
230
  key: 'zag_k_1_abc123',
231
231
  hostname: 'my-machine',
232
- version: '2.5.0',
232
+ version: '2.6.0',
233
233
  resumeToken: undefined,
234
234
  homeDir: '/home/user',
235
235
  platform: 'linux',
@@ -247,7 +247,7 @@ describe('SocketIO Client', () => {
247
247
  expect(mockSocket.emit).toHaveBeenCalledWith('register', {
248
248
  key: 'zag_k_1_abc123',
249
249
  hostname: 'test-machine',
250
- version: '2.5.0',
250
+ version: '2.6.0',
251
251
  resumeToken: undefined,
252
252
  homeDir: '/home/user',
253
253
  platform: 'linux',
package/vitest.config.ts CHANGED
@@ -1,9 +1,13 @@
1
- import { defineConfig } from 'vitest/config';
1
+ import { configDefaults, defineConfig } from 'vitest/config';
2
2
 
3
3
  export default defineConfig({
4
4
  test: {
5
5
  globals: true,
6
6
  environment: 'node',
7
+ // tsconfig 会把 src/**/*.test.ts 一并编译进 dist;在 vitest 默认排除项之外
8
+ // 追加 **/dist/**,避免构建后重复执行编译副本(且 sidecar fixture 如 .mjs
9
+ // 不会被 tsc 复制而必然失败)。不得用自定义数组覆盖默认值(会丢 .git 等默认排除)。
10
+ exclude: [...configDefaults.exclude, '**/dist/**'],
7
11
  coverage: {
8
12
  provider: 'v8',
9
13
  reporter: ['text', 'text-summary'],