@kairyou/agent-tools 0.9.0 → 0.10.1
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 +40 -110
- package/README.zh-CN.md +39 -100
- package/dist/usage/cli.mjs +5 -3
- package/dist/usage/codex-hook.mjs +18 -10
- package/dist/usage/core.mjs +224 -98
- package/docs/en/custom-gateway-routes.md +53 -0
- package/docs/en/repository-structure.md +20 -0
- package/docs/zh-CN/custom-gateway-routes.md +47 -0
- package/docs/zh-CN/repository-structure.md +20 -0
- package/integrations/usage/codex-hook.mjs +19 -10
- package/integrations/usage/core.mjs +60 -12
- package/integrations/usage/lib/cache.mjs +152 -70
- package/integrations/usage/lib/config.mjs +11 -10
- package/integrations/usage/lib/format.mjs +56 -4
- package/integrations/usage/lib/http.mjs +5 -2
- package/package.json +2 -1
- package/scripts/install.mjs +13 -4
- package/scripts/publish.mjs +6 -2
- package/scripts/release.mjs +8 -6
package/scripts/install.mjs
CHANGED
|
@@ -57,6 +57,15 @@ const INSTALL_ROOT =
|
|
|
57
57
|
process.env.AGENT_TOOLS_HOME || path.join(os.homedir(), ".agent-tools");
|
|
58
58
|
const META_KEY = "_agentTools";
|
|
59
59
|
const META_VERSION = 1;
|
|
60
|
+
// Stamped into install-state.json so a later install can tell which release
|
|
61
|
+
// wrote the current layout. Purely informational today.
|
|
62
|
+
const PACKAGE_VERSION = (() => {
|
|
63
|
+
try {
|
|
64
|
+
return JSON.parse(fs.readFileSync(path.join(REPO_ROOT, "package.json"), "utf8")).version || "";
|
|
65
|
+
} catch {
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
})();
|
|
60
69
|
// Everything copied into ~/.agent-tools is built output from dist/ (see
|
|
61
70
|
// scripts/build.mjs); integrations/ holds the sources.
|
|
62
71
|
const SOURCE = {
|
|
@@ -395,14 +404,13 @@ function removeFile(file, dryRun) {
|
|
|
395
404
|
console.log(` removed ${file}`);
|
|
396
405
|
}
|
|
397
406
|
|
|
398
|
-
function usageEntry() {
|
|
407
|
+
function usageEntry({ silent = false } = {}) {
|
|
399
408
|
return {
|
|
400
409
|
hooks: [
|
|
401
410
|
{
|
|
402
411
|
type: "command",
|
|
403
|
-
command: nodeCmd(RUNTIME.codexUsageHook)
|
|
412
|
+
command: `${nodeCmd(RUNTIME.codexUsageHook)}${silent ? " --silent" : ""}`,
|
|
404
413
|
timeout: 5,
|
|
405
|
-
statusMessage: "Refreshing API usage",
|
|
406
414
|
},
|
|
407
415
|
],
|
|
408
416
|
};
|
|
@@ -433,7 +441,7 @@ function applyProviderUsage(cfg, { remove }) {
|
|
|
433
441
|
}
|
|
434
442
|
cfg.hooks[event] = cfg.hooks[event] || [];
|
|
435
443
|
cfg.hooks[event] = cfg.hooks[event].filter((entry) => !isOurProviderUsageEntry(entry));
|
|
436
|
-
cfg.hooks[event].push(usageEntry());
|
|
444
|
+
cfg.hooks[event].push(usageEntry({ silent: event === "UserPromptSubmit" }));
|
|
437
445
|
}
|
|
438
446
|
if (Object.keys(cfg.hooks).length === 0) delete cfg.hooks;
|
|
439
447
|
}
|
|
@@ -631,6 +639,7 @@ function managedSkillStatus(dest, identity) {
|
|
|
631
639
|
|
|
632
640
|
function recordManagedSkill(dest, identity) {
|
|
633
641
|
const state = readInstallState();
|
|
642
|
+
state.packageVersion = PACKAGE_VERSION;
|
|
634
643
|
state.artifacts[skillManifestKey(dest)] = {
|
|
635
644
|
path: fwd(path.resolve(dest)),
|
|
636
645
|
...identity,
|
package/scripts/publish.mjs
CHANGED
|
@@ -41,8 +41,12 @@ if (typeof PACKAGE_NAME !== "string" || PACKAGE_NAME.trim() === "") {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
function runNpm(args, { capture = false, allowFailure = false } = {}) {
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
// npm run sets npm_execpath. When invoked directly (`node scripts/...`), find
|
|
45
|
+
// the bundled npm-cli.js next to node — spawning npm.cmd fails on Node 22+.
|
|
46
|
+
// Version-manager layouts may not have it there, so fall back to PATH.
|
|
47
|
+
const bundledNpm = path.join(path.dirname(process.execPath), "node_modules", "npm", "bin", "npm-cli.js");
|
|
48
|
+
const npmExecPath = process.env.npm_execpath || (fs.existsSync(bundledNpm) ? bundledNpm : undefined);
|
|
49
|
+
const command = npmExecPath ? process.execPath : "npm";
|
|
46
50
|
const commandArgs = npmExecPath ? [npmExecPath, ...args] : args;
|
|
47
51
|
const result = spawnSync(command, commandArgs, {
|
|
48
52
|
cwd: ROOT,
|
package/scripts/release.mjs
CHANGED
|
@@ -78,12 +78,14 @@ function run(command, args, { label, onFailure } = {}) {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
function runNpm(args) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
81
|
+
// npm run sets npm_execpath. When invoked directly (`node scripts/...`), find
|
|
82
|
+
// the bundled npm-cli.js next to node — spawning npm.cmd fails on Node 22+.
|
|
83
|
+
// Version-manager layouts may not have it there, so fall back to PATH.
|
|
84
|
+
const bundledNpm = path.join(path.dirname(process.execPath), "node_modules", "npm", "bin", "npm-cli.js");
|
|
85
|
+
const npmExecPath = process.env.npm_execpath || (fs.existsSync(bundledNpm) ? bundledNpm : undefined);
|
|
86
|
+
const command = npmExecPath ? process.execPath : "npm";
|
|
87
|
+
const commandArgs = npmExecPath ? [npmExecPath, ...args] : args;
|
|
88
|
+
run(command, commandArgs, { label: `npm ${args.join(" ")}` });
|
|
87
89
|
}
|
|
88
90
|
|
|
89
91
|
function printRecovery(commands) {
|