@agent-link/agent 0.1.293 → 0.1.295

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 (42) hide show
  1. package/dist/adoption-lock.d.ts +14 -0
  2. package/dist/adoption-lock.js +54 -0
  3. package/dist/adoption-lock.js.map +1 -0
  4. package/dist/adoption.d.ts +21 -0
  5. package/dist/adoption.js +303 -0
  6. package/dist/adoption.js.map +1 -0
  7. package/dist/bootstrap-delegator.d.ts +7 -0
  8. package/dist/bootstrap-delegator.js +36 -0
  9. package/dist/bootstrap-delegator.js.map +1 -0
  10. package/dist/cli.js +86 -3
  11. package/dist/cli.js.map +1 -1
  12. package/dist/config.d.ts +17 -2
  13. package/dist/config.js +25 -2
  14. package/dist/config.js.map +1 -1
  15. package/dist/index.js +16 -1
  16. package/dist/index.js.map +1 -1
  17. package/dist/launcher-manager.d.ts +9 -0
  18. package/dist/launcher-manager.js +84 -0
  19. package/dist/launcher-manager.js.map +1 -0
  20. package/dist/runtime-release.d.ts +41 -0
  21. package/dist/runtime-release.js +218 -0
  22. package/dist/runtime-release.js.map +1 -0
  23. package/dist/safe-tar.d.ts +11 -0
  24. package/dist/safe-tar.js +180 -0
  25. package/dist/safe-tar.js.map +1 -0
  26. package/dist/self-check.d.ts +14 -0
  27. package/dist/self-check.js +62 -0
  28. package/dist/self-check.js.map +1 -0
  29. package/dist/service.d.ts +11 -1
  30. package/dist/service.js +32 -4
  31. package/dist/service.js.map +1 -1
  32. package/dist/start-launch-spec.d.ts +4 -0
  33. package/dist/start-launch-spec.js +25 -0
  34. package/dist/start-launch-spec.js.map +1 -1
  35. package/dist/version-stager.d.ts +6 -0
  36. package/dist/version-stager.js +88 -0
  37. package/dist/version-stager.js.map +1 -0
  38. package/dist/version-store.d.ts +51 -0
  39. package/dist/version-store.js +277 -0
  40. package/dist/version-store.js.map +1 -0
  41. package/launcher/launcher.cjs +110 -0
  42. package/package.json +3 -2
@@ -0,0 +1,110 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ const fs = require('fs');
5
+ const os = require('os');
6
+ const path = require('path');
7
+ const { spawn } = require('child_process');
8
+
9
+ function fail(message) {
10
+ process.stderr.write(`[AgentLink Launcher] ${message}\n`);
11
+ process.exitCode = 1;
12
+ }
13
+
14
+ function isInside(root, candidate) {
15
+ const rel = path.relative(path.resolve(root), path.resolve(candidate));
16
+ return rel === '' || (!rel.startsWith('..') && !path.isAbsolute(rel));
17
+ }
18
+
19
+ function loadPointer(file, versionsRoot) {
20
+ const value = JSON.parse(fs.readFileSync(file, 'utf8'));
21
+ if (
22
+ !value
23
+ || value.schemaVersion !== 1
24
+ || typeof value.version !== 'string'
25
+ || typeof value.integrity !== 'string'
26
+ || typeof value.entry !== 'string'
27
+ ) {
28
+ throw new Error(`invalid pointer ${file}`);
29
+ }
30
+ const entry = path.resolve(value.entry);
31
+ const encoded = value.integrity.startsWith('sha512-')
32
+ ? value.integrity.slice('sha512-'.length)
33
+ : '';
34
+ const digest = Buffer.from(encoded, 'base64');
35
+ if (digest.length !== 64 || digest.toString('base64') !== encoded) {
36
+ throw new Error(`pointer integrity is invalid: ${file}`);
37
+ }
38
+ const expectedDirectory = path.join(
39
+ versionsRoot,
40
+ `${value.version}-${digest.toString('hex').slice(0, 16)}`,
41
+ );
42
+ if (!isInside(expectedDirectory, entry)) throw new Error(`pointer entry escapes its version directory: ${file}`);
43
+ const canonicalRoot = fs.realpathSync(versionsRoot);
44
+ const canonicalDirectory = fs.realpathSync(expectedDirectory);
45
+ const canonicalEntry = fs.realpathSync(entry);
46
+ if (
47
+ !isInside(canonicalRoot, canonicalDirectory)
48
+ || !isInside(canonicalDirectory, canonicalEntry)
49
+ || !fs.statSync(canonicalEntry).isFile()
50
+ ) {
51
+ throw new Error(`pointer entry is not a file: ${file}`);
52
+ }
53
+ const marker = JSON.parse(fs.readFileSync(path.join(canonicalDirectory, '.agentlink-version.json'), 'utf8'));
54
+ const markerEntry = path.resolve(canonicalDirectory, marker.entry || '');
55
+ if (
56
+ marker.schemaVersion !== 1
57
+ || marker.version !== value.version
58
+ || marker.integrity !== value.integrity
59
+ || markerEntry !== canonicalEntry
60
+ ) {
61
+ throw new Error(`version marker does not match pointer: ${file}`);
62
+ }
63
+ return { ...value, entry: canonicalEntry };
64
+ }
65
+
66
+ const agentHome = path.resolve(process.env.AGENTLINK_HOME || path.join(os.homedir(), '.agentlink'));
67
+ const versionsRoot = path.join(agentHome, 'versions');
68
+ let pointer;
69
+ try {
70
+ pointer = loadPointer(path.join(agentHome, 'current-version.json'), versionsRoot);
71
+ } catch (currentError) {
72
+ try {
73
+ pointer = loadPointer(path.join(agentHome, 'last-known-good.json'), versionsRoot);
74
+ process.stderr.write(`[AgentLink Launcher] Current selection invalid; using last-known-good: ${currentError.message}\n`);
75
+ } catch (lkgError) {
76
+ fail(`Cannot select an Agent version: ${currentError.message}; ${lkgError.message}`);
77
+ return;
78
+ }
79
+ }
80
+
81
+ const child = spawn(process.execPath, [pointer.entry, ...process.argv.slice(2)], {
82
+ stdio: 'inherit',
83
+ windowsHide: true,
84
+ env: {
85
+ ...process.env,
86
+ AGENTLINK_HOME: agentHome,
87
+ AGENTLINK_VERSION_STORE_ACTIVE: '1',
88
+ AGENTLINK_SELECTED_VERSION: pointer.version,
89
+ },
90
+ });
91
+
92
+ const signalHandlers = {};
93
+ for (const signal of ['SIGINT', 'SIGTERM']) {
94
+ signalHandlers[signal] = () => {
95
+ if (!child.killed) {
96
+ try { child.kill(signal); } catch { /* child already exited */ }
97
+ }
98
+ };
99
+ process.on(signal, signalHandlers[signal]);
100
+ }
101
+
102
+ child.on('error', error => fail(`Failed to launch selected Agent: ${error.message}`));
103
+ child.on('exit', (code, signal) => {
104
+ if (signal) {
105
+ process.removeListener(signal, signalHandlers[signal]);
106
+ process.kill(process.pid, signal);
107
+ return;
108
+ }
109
+ process.exitCode = code ?? 1;
110
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agent-link/agent",
3
- "version": "0.1.293",
3
+ "version": "0.1.295",
4
4
  "description": "AgentLink local agent CLI",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -24,7 +24,8 @@
24
24
  "main": "dist/index.js",
25
25
  "types": "dist/index.d.ts",
26
26
  "files": [
27
- "dist"
27
+ "dist",
28
+ "launcher"
28
29
  ],
29
30
  "bin": {
30
31
  "agentlink-client": "dist/cli.js"