@agentfare/setup 0.1.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.
- package/README.md +24 -0
- package/dist/detector.d.ts +11 -0
- package/dist/detector.d.ts.map +1 -0
- package/dist/detector.js +89 -0
- package/dist/detector.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/reporter.d.ts +3 -0
- package/dist/reporter.d.ts.map +1 -0
- package/dist/reporter.js +16 -0
- package/dist/reporter.js.map +1 -0
- package/dist/shell-writer.d.ts +5 -0
- package/dist/shell-writer.d.ts.map +1 -0
- package/dist/shell-writer.js +92 -0
- package/dist/shell-writer.js.map +1 -0
- package/dist/validator.d.ts +6 -0
- package/dist/validator.d.ts.map +1 -0
- package/dist/validator.js +35 -0
- package/dist/validator.js.map +1 -0
- package/package.json +18 -0
package/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# @agentfare/setup
|
|
2
|
+
|
|
3
|
+
环境检测和 Shell 配置工具。
|
|
4
|
+
|
|
5
|
+
## 功能
|
|
6
|
+
|
|
7
|
+
- 检测平台(macOS / Linux / WSL / Windows)
|
|
8
|
+
- 检测已安装的 CLI 工具
|
|
9
|
+
- 生成并写入 Shell 函数到 `.zshrc` / `.bashrc`
|
|
10
|
+
- 验证 hook 注入状态
|
|
11
|
+
|
|
12
|
+
## 使用
|
|
13
|
+
|
|
14
|
+
```typescript
|
|
15
|
+
import { detectTools, detectPlatform, runSetup } from "@agentfare/setup";
|
|
16
|
+
|
|
17
|
+
const tools = detectTools();
|
|
18
|
+
const platform = detectPlatform();
|
|
19
|
+
await runSetup();
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## License
|
|
23
|
+
|
|
24
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type Platform = "macos" | "linux" | "wsl" | "windows-native";
|
|
2
|
+
export interface DetectedTool {
|
|
3
|
+
name: "codex" | "claude";
|
|
4
|
+
path: string;
|
|
5
|
+
provider: string;
|
|
6
|
+
envKey: string;
|
|
7
|
+
envKeyPresent: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare function detectTools(): DetectedTool[];
|
|
10
|
+
export declare function detectPlatform(): Platform;
|
|
11
|
+
//# sourceMappingURL=detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,KAAK,GAAG,gBAAgB,CAAC;AAEpE,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,OAAO,CAAC;CACxB;AAED,wBAAgB,WAAW,IAAI,YAAY,EAAE,CAgC5C;AAED,wBAAgB,cAAc,IAAI,QAAQ,CAczC"}
|
package/dist/detector.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.detectTools = detectTools;
|
|
37
|
+
exports.detectPlatform = detectPlatform;
|
|
38
|
+
const node_child_process_1 = require("node:child_process");
|
|
39
|
+
const os = __importStar(require("node:os"));
|
|
40
|
+
const fs = __importStar(require("node:fs"));
|
|
41
|
+
function detectTools() {
|
|
42
|
+
const tools = [];
|
|
43
|
+
const checks = [
|
|
44
|
+
{ name: "codex", provider: "openai", envKey: "OPENAI_API_KEY" },
|
|
45
|
+
{ name: "claude", provider: "anthropic", envKey: "ANTHROPIC_API_KEY" },
|
|
46
|
+
];
|
|
47
|
+
for (const check of checks) {
|
|
48
|
+
try {
|
|
49
|
+
const isWindows = os.platform() === "win32";
|
|
50
|
+
const cmd = isWindows
|
|
51
|
+
? `where ${check.name} 2>nul`
|
|
52
|
+
: `which ${check.name} 2>/dev/null`;
|
|
53
|
+
const execResult = (0, node_child_process_1.execSync)(cmd, { encoding: "utf-8" }).trim();
|
|
54
|
+
if (execResult) {
|
|
55
|
+
tools.push({
|
|
56
|
+
name: check.name,
|
|
57
|
+
path: execResult.split("\n")[0].trim(),
|
|
58
|
+
provider: check.provider,
|
|
59
|
+
envKey: check.envKey,
|
|
60
|
+
envKeyPresent: !!process.env[check.envKey],
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Tool not found on PATH — skip
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return tools;
|
|
69
|
+
}
|
|
70
|
+
function detectPlatform() {
|
|
71
|
+
const platform = os.platform();
|
|
72
|
+
if (platform === "darwin")
|
|
73
|
+
return "macos";
|
|
74
|
+
if (platform === "linux") {
|
|
75
|
+
try {
|
|
76
|
+
const release = fs.readFileSync("/proc/version", "utf-8");
|
|
77
|
+
if (release.toLowerCase().includes("microsoft"))
|
|
78
|
+
return "wsl";
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// Not WSL
|
|
82
|
+
}
|
|
83
|
+
return "linux";
|
|
84
|
+
}
|
|
85
|
+
if (platform === "win32")
|
|
86
|
+
return "windows-native";
|
|
87
|
+
return "linux";
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"detector.js","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,kCAgCC;AAED,wCAcC;AA9DD,2DAA8C;AAC9C,4CAA8B;AAC9B,4CAA8B;AAY9B,SAAgB,WAAW;IACzB,MAAM,KAAK,GAAmB,EAAE,CAAC;IACjC,MAAM,MAAM,GAIP;QACH,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE;QAC/D,EAAE,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,mBAAmB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,OAAO,KAAK,CAAC;QAChE,CAAC;QAAC,MAAM,CAAC;YACP,UAAU;QACZ,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,QAAQ,KAAK,OAAO;QAAE,OAAO,gBAAgB,CAAC;IAClD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { detectTools, detectPlatform } from "./detector.js";
|
|
2
|
+
export { generateShellFunctions, writeShellConfig } from "./shell-writer.js";
|
|
3
|
+
export { validateHookInjection } from "./validator.js";
|
|
4
|
+
export { reportStatus } from "./reporter.js";
|
|
5
|
+
/**
|
|
6
|
+
* Run the full setup flow. ISSUE-030: exported instead of auto-executed on import.
|
|
7
|
+
*/
|
|
8
|
+
export declare function runSetup(): Promise<void>;
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE7C;;GAEG;AACH,wBAAsB,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAyB9C"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reportStatus = exports.validateHookInjection = exports.writeShellConfig = exports.generateShellFunctions = exports.detectPlatform = exports.detectTools = void 0;
|
|
4
|
+
exports.runSetup = runSetup;
|
|
5
|
+
const detector_js_1 = require("./detector.js");
|
|
6
|
+
const shell_writer_js_1 = require("./shell-writer.js");
|
|
7
|
+
const validator_js_1 = require("./validator.js");
|
|
8
|
+
const reporter_js_1 = require("./reporter.js");
|
|
9
|
+
var detector_js_2 = require("./detector.js");
|
|
10
|
+
Object.defineProperty(exports, "detectTools", { enumerable: true, get: function () { return detector_js_2.detectTools; } });
|
|
11
|
+
Object.defineProperty(exports, "detectPlatform", { enumerable: true, get: function () { return detector_js_2.detectPlatform; } });
|
|
12
|
+
var shell_writer_js_2 = require("./shell-writer.js");
|
|
13
|
+
Object.defineProperty(exports, "generateShellFunctions", { enumerable: true, get: function () { return shell_writer_js_2.generateShellFunctions; } });
|
|
14
|
+
Object.defineProperty(exports, "writeShellConfig", { enumerable: true, get: function () { return shell_writer_js_2.writeShellConfig; } });
|
|
15
|
+
var validator_js_2 = require("./validator.js");
|
|
16
|
+
Object.defineProperty(exports, "validateHookInjection", { enumerable: true, get: function () { return validator_js_2.validateHookInjection; } });
|
|
17
|
+
var reporter_js_2 = require("./reporter.js");
|
|
18
|
+
Object.defineProperty(exports, "reportStatus", { enumerable: true, get: function () { return reporter_js_2.reportStatus; } });
|
|
19
|
+
/**
|
|
20
|
+
* Run the full setup flow. ISSUE-030: exported instead of auto-executed on import.
|
|
21
|
+
*/
|
|
22
|
+
async function runSetup() {
|
|
23
|
+
const platform = (0, detector_js_1.detectPlatform)();
|
|
24
|
+
if (platform === "windows-native") {
|
|
25
|
+
console.warn("[AgentFare] Windows 原生平台支持为实验性功能,部分功能可能受限");
|
|
26
|
+
}
|
|
27
|
+
console.log(`detected platform: ${platform}`);
|
|
28
|
+
const tools = (0, detector_js_1.detectTools)();
|
|
29
|
+
if (tools.length === 0) {
|
|
30
|
+
console.error("No codex or claude CLI tools detected.");
|
|
31
|
+
process.exit(1);
|
|
32
|
+
}
|
|
33
|
+
const shellContent = (0, shell_writer_js_1.generateShellFunctions)(tools);
|
|
34
|
+
const rcPath = (0, shell_writer_js_1.writeShellConfig)(shellContent);
|
|
35
|
+
console.log(`shell functions written to ${rcPath}`);
|
|
36
|
+
const hookResult = (0, validator_js_1.validateHookInjection)();
|
|
37
|
+
if (hookResult.available) {
|
|
38
|
+
console.log("hook injection available (monkey-patch mode)");
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
console.warn(`warning: ${hookResult.reason}`);
|
|
42
|
+
}
|
|
43
|
+
(0, reporter_js_1.reportStatus)(tools);
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAaA,4BAyBC;AAtCD,+CAA4D;AAC5D,uDAA6E;AAC7E,iDAAuD;AACvD,+CAA6C;AAE7C,6CAA4D;AAAnD,0GAAA,WAAW,OAAA;AAAE,6GAAA,cAAc,OAAA;AACpC,qDAA6E;AAApE,yHAAA,sBAAsB,OAAA;AAAE,mHAAA,gBAAgB,OAAA;AACjD,+CAAuD;AAA9C,qHAAA,qBAAqB,OAAA;AAC9B,6CAA6C;AAApC,2GAAA,YAAY,OAAA;AAErB;;GAEG;AACI,KAAK,UAAU,QAAQ;IAC5B,MAAM,QAAQ,GAAG,IAAA,4BAAc,GAAE,CAAC;IAClC,IAAI,QAAQ,KAAK,gBAAgB,EAAE,CAAC;QAClC,OAAO,CAAC,IAAI,CAAC,2CAA2C,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,sBAAsB,QAAQ,EAAE,CAAC,CAAC;IAE9C,MAAM,KAAK,GAAG,IAAA,yBAAW,GAAE,CAAC;IAC5B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,CAAC,KAAK,CAAC,wCAAwC,CAAC,CAAC;QACxD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,YAAY,GAAG,IAAA,wCAAsB,EAAC,KAAK,CAAC,CAAC;IACnD,MAAM,MAAM,GAAG,IAAA,kCAAgB,EAAC,YAAY,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,8BAA8B,MAAM,EAAE,CAAC,CAAC;IAEpD,MAAM,UAAU,GAAG,IAAA,oCAAqB,GAAE,CAAC;IAC3C,IAAI,UAAU,CAAC,SAAS,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;IAC9D,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,IAAI,CAAC,YAAY,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;IAChD,CAAC;IAED,IAAA,0BAAY,EAAC,KAAK,CAAC,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporter.d.ts","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI,CAcxD"}
|
package/dist/reporter.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.reportStatus = reportStatus;
|
|
4
|
+
function reportStatus(tools) {
|
|
5
|
+
console.log("\n检测环境...");
|
|
6
|
+
for (const tool of tools) {
|
|
7
|
+
console.log(` found ${tool.name === "codex" ? "Codex" : "Claude Code"} (${tool.provider})`);
|
|
8
|
+
if (tool.envKeyPresent)
|
|
9
|
+
console.log(` found ${tool.envKey}`);
|
|
10
|
+
}
|
|
11
|
+
console.log(`\nsame-provider routing: ready`);
|
|
12
|
+
console.log(`\ncross-provider routing:`);
|
|
13
|
+
console.log(` mode: off (same-provider only)`);
|
|
14
|
+
console.log(` enable with: agentfare config set routing.crossProvider opt-in\n`);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=reporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporter.js","sourceRoot":"","sources":["../src/reporter.ts"],"names":[],"mappings":";;AAEA,oCAcC;AAdD,SAAgB,YAAY,CAAC,KAAqB;IAChD,OAAO,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACzB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,GAAG,CACT,WAAW,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,aAAa,KAAK,IAAI,CAAC,QAAQ,GAAG,CAChF,CAAC;QACF,IAAI,IAAI,CAAC,aAAa;YAAE,OAAO,CAAC,GAAG,CAAC,WAAW,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAChE,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAC9C,OAAO,CAAC,GAAG,CAAC,2BAA2B,CAAC,CAAC;IACzC,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;IAChD,OAAO,CAAC,GAAG,CACT,oEAAoE,CACrE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-writer.d.ts","sourceRoot":"","sources":["../src/shell-writer.ts"],"names":[],"mappings":"AAOA,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,KAAK,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAC7B,MAAM,CASR;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CA0BxD"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.generateShellFunctions = generateShellFunctions;
|
|
37
|
+
exports.writeShellConfig = writeShellConfig;
|
|
38
|
+
const fs = __importStar(require("node:fs"));
|
|
39
|
+
const path = __importStar(require("node:path"));
|
|
40
|
+
const os = __importStar(require("node:os"));
|
|
41
|
+
const MARKER_START = "# >>> agentfare >>>";
|
|
42
|
+
const MARKER_END = "# <<< agentfare <<<";
|
|
43
|
+
function generateShellFunctions(tools) {
|
|
44
|
+
const functions = tools
|
|
45
|
+
.map((tool) =>
|
|
46
|
+
// ISSUE-031: use $HOME instead of ~ for reliable shell expansion
|
|
47
|
+
`${tool.name}() {\n NODE_OPTIONS="--require \"$HOME/.agentfare/loader.js\"" command ${tool.name} "$@"\n}`)
|
|
48
|
+
.join("\n");
|
|
49
|
+
return `${MARKER_START}\n${functions}\n${MARKER_END}`;
|
|
50
|
+
}
|
|
51
|
+
function writeShellConfig(content) {
|
|
52
|
+
const homeDir = os.homedir();
|
|
53
|
+
const shellRcPaths = [
|
|
54
|
+
path.join(homeDir, ".zshrc"),
|
|
55
|
+
path.join(homeDir, ".bashrc"),
|
|
56
|
+
];
|
|
57
|
+
for (const rcPath of shellRcPaths) {
|
|
58
|
+
if (fs.existsSync(rcPath)) {
|
|
59
|
+
const existing = fs.readFileSync(rcPath, "utf-8");
|
|
60
|
+
const cleaned = existing
|
|
61
|
+
.replace(new RegExp(`${escapeRegex(MARKER_START)}[\\s\\S]*?${escapeRegex(MARKER_END)}`, "g"), "")
|
|
62
|
+
.trim();
|
|
63
|
+
const updated = `${cleaned}\n\n${content}\n`;
|
|
64
|
+
atomicWriteFileSync(rcPath, updated);
|
|
65
|
+
return rcPath;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
const bashrc = path.join(homeDir, ".bashrc");
|
|
69
|
+
atomicWriteFileSync(bashrc, content);
|
|
70
|
+
return bashrc;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* ISSUE-063: Atomic file write to prevent corruption on crash.
|
|
74
|
+
* Writes to a temp file first, then renames (POSIX atomic).
|
|
75
|
+
* On Windows where cross-drive rename may fail, falls back to copy+unlink.
|
|
76
|
+
*/
|
|
77
|
+
function atomicWriteFileSync(targetPath, data) {
|
|
78
|
+
const tmpPath = path.join(os.tmpdir(), `.agentfare-rc-${Date.now()}.tmp`);
|
|
79
|
+
fs.writeFileSync(tmpPath, data, "utf-8");
|
|
80
|
+
try {
|
|
81
|
+
fs.renameSync(tmpPath, targetPath);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
// Cross-device rename (Windows): fall back to copy + unlink
|
|
85
|
+
fs.copyFileSync(tmpPath, targetPath);
|
|
86
|
+
fs.unlinkSync(tmpPath);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
function escapeRegex(str) {
|
|
90
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=shell-writer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shell-writer.js","sourceRoot":"","sources":["../src/shell-writer.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,wDAWC;AAED,4CA0BC;AA9CD,4CAA8B;AAC9B,gDAAkC;AAClC,4CAA8B;AAE9B,MAAM,YAAY,GAAG,qBAAqB,CAAC;AAC3C,MAAM,UAAU,GAAG,qBAAqB,CAAC;AAEzC,SAAgB,sBAAsB,CACpC,KAA8B;IAE9B,MAAM,SAAS,GAAG,KAAK;SACpB,GAAG,CACF,CAAC,IAAI,EAAE,EAAE;IACP,iEAAiE;IACjE,GAAG,IAAI,CAAC,IAAI,2EAA2E,IAAI,CAAC,IAAI,UAAU,CAC7G;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;IACd,OAAO,GAAG,YAAY,KAAK,SAAS,KAAK,UAAU,EAAE,CAAC;AACxD,CAAC;AAED,SAAgB,gBAAgB,CAAC,OAAe;IAC9C,MAAM,OAAO,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;IAC7B,MAAM,YAAY,GAAG;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,QAAQ,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,SAAS,CAAC;KAC9B,CAAC;IACF,KAAK,MAAM,MAAM,IAAI,YAAY,EAAE,CAAC;QAClC,IAAI,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1B,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@@
|
|
|
1
|
+
{"version":3,"file":"validator.d.ts","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":"AAAA,wBAAgB,qBAAqB,IAAI;IACvC,SAAS,EAAE,OAAO,CAAC;IACnB,IAAI,EAAE,cAAc,GAAG,gBAAgB,CAAC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CA8BA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateHookInjection = validateHookInjection;
|
|
4
|
+
function validateHookInjection() {
|
|
5
|
+
try {
|
|
6
|
+
const original = globalThis.fetch;
|
|
7
|
+
let patched = false;
|
|
8
|
+
globalThis.fetch = () => {
|
|
9
|
+
patched = true;
|
|
10
|
+
return Promise.resolve(new Response(null, { status: 200 }));
|
|
11
|
+
};
|
|
12
|
+
try {
|
|
13
|
+
globalThis.fetch("https://test.agentfare.local/ping");
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
// Expected — we're not actually making a real request
|
|
17
|
+
}
|
|
18
|
+
globalThis.fetch = original;
|
|
19
|
+
if (patched)
|
|
20
|
+
return { available: true, mode: "monkey-patch" };
|
|
21
|
+
return {
|
|
22
|
+
available: false,
|
|
23
|
+
mode: "proxy-required",
|
|
24
|
+
reason: "fetch 拦截不可用,请使用 Proxy 模式:agentfare init --mode proxy",
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
return {
|
|
29
|
+
available: false,
|
|
30
|
+
mode: "proxy-required",
|
|
31
|
+
reason: `Hook 验证异常: ${err}`,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../src/validator.ts"],"names":[],"mappings":";;AAAA,sDAkCC;AAlCD,SAAgB,qBAAqB;IAKnC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC;QAClC,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,UAAU,CAAC,KAAK,GAAG,GAAG,EAAE;YACtB,OAAO,GAAG,IAAI,CAAC;YACf,OAAO,OAAO,CAAC,OAAO,CACpB,IAAI,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CACpC,CAAC;QACJ,CAAC,CAAC;QACF,IAAI,CAAC;YACH,UAAU,CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACxD,CAAC;QAAC,MAAM,CAAC;YACP,sDAAsD;QACxD,CAAC;QACD,UAAU,CAAC,KAAK,GAAG,QAAQ,CAAC;QAC5B,IAAI,OAAO;YAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;QAC9D,OAAO;YACL,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,gBAAgB;YACtB,MAAM,EACJ,sDAAsD;SACzD,CAAC;IACJ,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO;YACL,SAAS,EAAE,KAAK;YAChB,IAAI,EAAE,gBAAgB;YACtB,MAAM,EAAE,cAAc,GAAG,EAAE;SAC5B,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentfare/setup",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": ["dist"],
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc",
|
|
10
|
+
"test": "vitest run",
|
|
11
|
+
"test:watch": "vitest"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"@types/node": "^22.0.0",
|
|
15
|
+
"typescript": "^5.8",
|
|
16
|
+
"vitest": "^3.2"
|
|
17
|
+
}
|
|
18
|
+
}
|