@1agents/acp-service 0.11.1 → 0.11.3

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.
@@ -14,11 +14,21 @@ import { defineTool } from '@deepseek-ai/dsh-tools';
14
14
  import { REVIEW_SUBMIT_PATH, ReviewHandBack, SUBMIT_DESCRIPTION, SUBMIT_TOOL, SUMMARY_DESCRIPTION } from './review.js';
15
15
  import { createTicketGateway, runTicketTool, ticketTools } from './ticket-tools.js';
16
16
  import { HANDOFF_PATH } from './handoff-spec.js';
17
+ import { syncGlobalAcpService } from './sync-global.js';
17
18
  import { handoffTools } from './handoff-tools.js';
18
19
  import { runHandoffTool } from './handoff-executor.js';
19
20
  import { TICKET_PATH } from './ticket-spec.js';
20
21
  export { name, inject } from '@1agents/acp-service';
21
22
  export async function apply(ctx, input = {}) {
23
+ // One plugin install updates the global acp-service CLI. A failure must not stop DSH.
24
+ try {
25
+ const synced = await syncGlobalAcpService();
26
+ if (synced.updated)
27
+ console.log(`acp-service global CLI updated ${synced.from ?? '(none)'} -> ${synced.version}`);
28
+ }
29
+ catch (error) {
30
+ console.warn(`acp-service global CLI was not updated: ${error instanceof Error ? error.message : String(error)}`);
31
+ }
22
32
  const homePath = ctx.get('dshHomePath');
23
33
  const home = homePath ? homePath() : process.env.DSH_HOME || join(homedir(), '.dsh');
24
34
  const service = resolveServiceOptions(input);
@@ -0,0 +1,19 @@
1
+ export interface SyncGlobalOptions {
2
+ packageDir?: string;
3
+ env?: NodeJS.ProcessEnv;
4
+ execFile?: (command: string, args: readonly string[], env: NodeJS.ProcessEnv) => Promise<{
5
+ stdout: string;
6
+ }>;
7
+ }
8
+ export interface SyncGlobalResult {
9
+ updated: boolean;
10
+ version: string;
11
+ from?: string;
12
+ reason?: string;
13
+ }
14
+ /** The installed @1agents/acp-service directory that contains this module. */
15
+ export declare function packageDirectory(moduleUrl?: string): string;
16
+ /** DSH profile installs only. A workspace checkout and the global install itself do not recurse. */
17
+ export declare function shouldSyncGlobal(packageDir: string, env?: NodeJS.ProcessEnv): boolean;
18
+ /** Install this exact package over the global CLI when its version differs. */
19
+ export declare function syncGlobalAcpService(options?: SyncGlobalOptions): Promise<SyncGlobalResult>;
@@ -0,0 +1,81 @@
1
+ /** Keep the global acp-service CLI on the same version as this DSH plugin install. */
2
+ import { execFile } from 'node:child_process';
3
+ import { existsSync, readFileSync } from 'node:fs';
4
+ import { dirname, join } from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+ import { promisify } from 'node:util';
7
+ const exec = promisify(execFile);
8
+ const PACKAGE = '@1agents/acp-service';
9
+ /** The installed @1agents/acp-service directory that contains this module. */
10
+ export function packageDirectory(moduleUrl = import.meta.url) {
11
+ let dir = dirname(fileURLToPath(moduleUrl));
12
+ for (let depth = 0; depth < 6; depth += 1) {
13
+ const manifestPath = join(dir, 'package.json');
14
+ if (existsSync(manifestPath)) {
15
+ try {
16
+ const manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
17
+ if (manifest.name === PACKAGE)
18
+ return dir;
19
+ }
20
+ catch { /* A broken manifest is not this package. */ }
21
+ }
22
+ const parent = dirname(dir);
23
+ if (parent === dir)
24
+ break;
25
+ dir = parent;
26
+ }
27
+ throw new Error(`${PACKAGE} package root was not found`);
28
+ }
29
+ function readVersion(directory) {
30
+ try {
31
+ const manifest = JSON.parse(readFileSync(join(directory, 'package.json'), 'utf8'));
32
+ if (manifest.name !== PACKAGE || typeof manifest.version !== 'string' || !manifest.version)
33
+ return undefined;
34
+ return manifest.version;
35
+ }
36
+ catch {
37
+ return undefined;
38
+ }
39
+ }
40
+ /** DSH profile installs only. A workspace checkout and the global install itself do not recurse. */
41
+ export function shouldSyncGlobal(packageDir, env = process.env) {
42
+ if (env.ACP_SERVICE_SKIP_GLOBAL_SYNC === '1' || env.ACP_SERVICE_SYNC_GLOBAL === '0')
43
+ return false;
44
+ if (env.ACP_SERVICE_SYNC_GLOBAL === '1')
45
+ return true;
46
+ return /[/\\]\.dsh[/\\]profiles[/\\]/.test(packageDir);
47
+ }
48
+ /** Install this exact package over the global CLI when its version differs. */
49
+ export async function syncGlobalAcpService(options = {}) {
50
+ const env = options.env ?? process.env;
51
+ const packageDir = options.packageDir ?? packageDirectory();
52
+ const version = readVersion(packageDir);
53
+ if (!version)
54
+ throw new Error(`${PACKAGE} version was not found`);
55
+ if (!shouldSyncGlobal(packageDir, env))
56
+ return { updated: false, version, reason: 'not-a-dsh-profile-install' };
57
+ const run = options.execFile ?? (async (command, args, commandEnv) => {
58
+ const result = await exec(command, args, { env: commandEnv, timeout: 120_000, maxBuffer: 1024 * 1024 });
59
+ return { stdout: result.stdout };
60
+ });
61
+ const root = (await run('npm', ['root', '-g'], env)).stdout.trim();
62
+ if (!root)
63
+ throw new Error('npm root -g returned an empty path');
64
+ const from = readVersion(join(root, PACKAGE));
65
+ if (from === version)
66
+ return { updated: false, version, from, reason: 'already-current' };
67
+ await run('npm', ['install', '-g', packageDir, '--no-fund', '--no-audit'], { ...env, ACP_SERVICE_SKIP_GLOBAL_SYNC: '1' });
68
+ return { updated: true, version, ...(from ? { from } : {}) };
69
+ }
70
+ const invokedDirectly = process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1];
71
+ if (invokedDirectly) {
72
+ syncGlobalAcpService().then(result => {
73
+ if (result.updated)
74
+ console.log(`acp-service global CLI updated ${result.from ?? '(none)'} -> ${result.version}`);
75
+ else
76
+ console.log(`acp-service global CLI unchanged (${result.reason ?? result.version})`);
77
+ }).catch(error => {
78
+ console.warn(`acp-service global CLI was not updated: ${error instanceof Error ? error.message : String(error)}`);
79
+ process.exitCode = 0;
80
+ });
81
+ }