@0xmaxma/claude-gateway 2.1.10 → 2.1.12
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/config.template.json +4 -0
- package/dist/agent/runner.d.ts +68 -2
- package/dist/agent/runner.d.ts.map +1 -1
- package/dist/agent/runner.js +338 -108
- package/dist/agent/runner.js.map +1 -1
- package/dist/api/async-guard.d.ts +13 -0
- package/dist/api/async-guard.d.ts.map +1 -0
- package/dist/api/async-guard.js +38 -0
- package/dist/api/async-guard.js.map +1 -0
- package/dist/api/auth.d.ts +5 -0
- package/dist/api/auth.d.ts.map +1 -1
- package/dist/api/auth.js +3 -0
- package/dist/api/auth.js.map +1 -1
- package/dist/api/browser-bindings-router.d.ts.map +1 -1
- package/dist/api/browser-bindings-router.js +2 -0
- package/dist/api/browser-bindings-router.js.map +1 -1
- package/dist/api/capabilities.d.ts +47 -2
- package/dist/api/capabilities.d.ts.map +1 -1
- package/dist/api/capabilities.js +51 -8
- package/dist/api/capabilities.js.map +1 -1
- package/dist/api/files-router.d.ts +23 -0
- package/dist/api/files-router.d.ts.map +1 -0
- package/dist/api/files-router.js +102 -0
- package/dist/api/files-router.js.map +1 -0
- package/dist/api/gateway-router.d.ts +4 -2
- package/dist/api/gateway-router.d.ts.map +1 -1
- package/dist/api/gateway-router.js +20 -2
- package/dist/api/gateway-router.js.map +1 -1
- package/dist/api/git-router.d.ts +4 -0
- package/dist/api/git-router.d.ts.map +1 -0
- package/dist/api/git-router.js +51 -0
- package/dist/api/git-router.js.map +1 -0
- package/dist/api/manifest-sources.d.ts.map +1 -1
- package/dist/api/manifest-sources.js +6 -0
- package/dist/api/manifest-sources.js.map +1 -1
- package/dist/api/processes-router.d.ts +28 -0
- package/dist/api/processes-router.d.ts.map +1 -0
- package/dist/api/processes-router.js +179 -0
- package/dist/api/processes-router.js.map +1 -0
- package/dist/api/router.d.ts +41 -1
- package/dist/api/router.d.ts.map +1 -1
- package/dist/api/router.js +98 -25
- package/dist/api/router.js.map +1 -1
- package/dist/api/voice-router.d.ts.map +1 -1
- package/dist/api/voice-router.js +2 -0
- package/dist/api/voice-router.js.map +1 -1
- package/dist/build-provenance.json +4 -4
- package/dist/cli/redact.d.ts +1 -0
- package/dist/cli/redact.d.ts.map +1 -1
- package/dist/cli/redact.js +12 -0
- package/dist/cli/redact.js.map +1 -1
- package/dist/config/loader.d.ts +5 -0
- package/dist/config/loader.d.ts.map +1 -1
- package/dist/config/loader.js +121 -0
- package/dist/config/loader.js.map +1 -1
- package/dist/config/reload-policy.d.ts.map +1 -1
- package/dist/config/reload-policy.js +1 -0
- package/dist/config/reload-policy.js.map +1 -1
- package/dist/config/watcher.d.ts.map +1 -1
- package/dist/config/watcher.js +1 -0
- package/dist/config/watcher.js.map +1 -1
- package/dist/files/config.d.ts +6 -0
- package/dist/files/config.d.ts.map +1 -0
- package/dist/files/config.js +15 -0
- package/dist/files/config.js.map +1 -0
- package/dist/files/delete.d.ts +27 -0
- package/dist/files/delete.d.ts.map +1 -0
- package/dist/files/delete.js +143 -0
- package/dist/files/delete.js.map +1 -0
- package/dist/files/fs.d.ts +70 -0
- package/dist/files/fs.d.ts.map +1 -0
- package/dist/files/fs.js +319 -0
- package/dist/files/fs.js.map +1 -0
- package/dist/files/holds.d.ts +11 -0
- package/dist/files/holds.d.ts.map +1 -0
- package/dist/files/holds.js +20 -0
- package/dist/files/holds.js.map +1 -0
- package/dist/files/paths.d.ts +26 -0
- package/dist/files/paths.d.ts.map +1 -0
- package/dist/files/paths.js +112 -0
- package/dist/files/paths.js.map +1 -0
- package/dist/files/session-cwd.d.ts +8 -0
- package/dist/files/session-cwd.d.ts.map +1 -0
- package/dist/files/session-cwd.js +139 -0
- package/dist/files/session-cwd.js.map +1 -0
- package/dist/git/read.d.ts +25 -0
- package/dist/git/read.d.ts.map +1 -0
- package/dist/git/read.js +166 -0
- package/dist/git/read.js.map +1 -0
- package/dist/git/runner.d.ts +46 -0
- package/dist/git/runner.d.ts.map +1 -0
- package/dist/git/runner.js +176 -0
- package/dist/git/runner.js.map +1 -0
- package/dist/git/status.d.ts +119 -0
- package/dist/git/status.d.ts.map +1 -0
- package/dist/git/status.js +273 -0
- package/dist/git/status.js.map +1 -0
- package/dist/index.js +7 -2
- package/dist/index.js.map +1 -1
- package/dist/orchestration/agent-tool-schemas.js +1 -1
- package/dist/orchestration/agent-tool-schemas.js.map +1 -1
- package/dist/orchestration/bridge.d.ts.map +1 -1
- package/dist/orchestration/bridge.js +2 -1
- package/dist/orchestration/bridge.js.map +1 -1
- package/dist/orchestration/response-errors.d.ts.map +1 -1
- package/dist/orchestration/response-errors.js +2 -0
- package/dist/orchestration/response-errors.js.map +1 -1
- package/dist/orchestration/runtime.d.ts +10 -1
- package/dist/orchestration/runtime.d.ts.map +1 -1
- package/dist/orchestration/runtime.js +23 -3
- package/dist/orchestration/runtime.js.map +1 -1
- package/dist/orchestration/tasks/driver.d.ts.map +1 -1
- package/dist/orchestration/tasks/driver.js +19 -1
- package/dist/orchestration/tasks/driver.js.map +1 -1
- package/dist/orchestration/tasks/service.d.ts +25 -2
- package/dist/orchestration/tasks/service.d.ts.map +1 -1
- package/dist/orchestration/tasks/service.js +45 -4
- package/dist/orchestration/tasks/service.js.map +1 -1
- package/dist/orchestration/types.d.ts +2 -0
- package/dist/orchestration/types.d.ts.map +1 -1
- package/dist/orchestration/types.js.map +1 -1
- package/dist/processes/listeners.d.ts +41 -0
- package/dist/processes/listeners.d.ts.map +1 -0
- package/dist/processes/listeners.js +140 -0
- package/dist/processes/listeners.js.map +1 -0
- package/dist/processes/start.d.ts +39 -0
- package/dist/processes/start.d.ts.map +1 -0
- package/dist/processes/start.js +208 -0
- package/dist/processes/start.js.map +1 -0
- package/dist/processes/stop.d.ts +37 -0
- package/dist/processes/stop.d.ts.map +1 -0
- package/dist/processes/stop.js +94 -0
- package/dist/processes/stop.js.map +1 -0
- package/dist/session/cwd.d.ts +65 -0
- package/dist/session/cwd.d.ts.map +1 -0
- package/dist/session/cwd.js +24 -0
- package/dist/session/cwd.js.map +1 -0
- package/dist/session/process.d.ts +17 -0
- package/dist/session/process.d.ts.map +1 -1
- package/dist/session/process.js +58 -3
- package/dist/session/process.js.map +1 -1
- package/dist/session/runtime-profile.d.ts +2 -0
- package/dist/session/runtime-profile.d.ts.map +1 -1
- package/dist/session/runtime-profile.js +1 -0
- package/dist/session/runtime-profile.js.map +1 -1
- package/dist/session/store.d.ts +13 -1
- package/dist/session/store.d.ts.map +1 -1
- package/dist/session/store.js +50 -4
- package/dist/session/store.js.map +1 -1
- package/dist/types.d.ts +19 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/paths.d.ts +5 -0
- package/dist/utils/paths.d.ts.map +1 -1
- package/dist/utils/paths.js +15 -0
- package/dist/utils/paths.js.map +1 -1
- package/dist/utils/result.d.ts +16 -0
- package/dist/utils/result.d.ts.map +1 -0
- package/dist/utils/result.js +8 -0
- package/dist/utils/result.js.map +1 -0
- package/mcp/tools/telegram/model-menu-request.ts +48 -0
- package/mcp/tools/telegram/receiver-server.ts +31 -28
- package/package.json +1 -1
|
@@ -0,0 +1,176 @@
|
|
|
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.MAX_FILTER_KEY = exports.MAX_BLANKED_FILTER_KEYS = exports.GIT_READ_TIMEOUT_MS = void 0;
|
|
37
|
+
exports.gitEnv = gitEnv;
|
|
38
|
+
exports.hardenedGit = hardenedGit;
|
|
39
|
+
exports.runGit = runGit;
|
|
40
|
+
const child_process_1 = require("child_process");
|
|
41
|
+
const fs_1 = require("fs");
|
|
42
|
+
const path = __importStar(require("path"));
|
|
43
|
+
const result_1 = require("../utils/result");
|
|
44
|
+
const status_1 = require("./status");
|
|
45
|
+
exports.GIT_READ_TIMEOUT_MS = 3000;
|
|
46
|
+
const MAX_OUTPUT = 32 * 1024 * 1024;
|
|
47
|
+
let warnedGitMissing = false;
|
|
48
|
+
/**
|
|
49
|
+
* What git and the operator's filters may inherit. Anything not named here is dropped, so the gateway's own API keys
|
|
50
|
+
* and bot tokens never reach a filter program. No network call is made, so no proxy, credential or ssh variables pass.
|
|
51
|
+
* `HOME`, `XDG_CONFIG_HOME` and the three `GIT_CONFIG_*` selectors decide which operator config files git reads
|
|
52
|
+
* (filters such as `git lfs install`, `safe.directory`).
|
|
53
|
+
*/
|
|
54
|
+
const PASSTHROUGH_ENV = new Set(['PATH', 'HOME', 'TMPDIR', 'XDG_CONFIG_HOME', 'GIT_CONFIG_GLOBAL', 'GIT_CONFIG_SYSTEM', 'GIT_CONFIG_NOSYSTEM']);
|
|
55
|
+
/**
|
|
56
|
+
* The environment git runs with: an allowlist of process.env, and no GIT_DIR/GIT_WORK_TREE that would aim git at
|
|
57
|
+
* another repository. Built from process.env explicitly: jest gives tests a copy that child_process ignores.
|
|
58
|
+
*
|
|
59
|
+
* `GIT_ALLOW_PROTOCOL` set empty allows no transport at all, and unlike `protocol.<name>.allow` in the repository's
|
|
60
|
+
* config it cannot be overridden by the repository. Git can start a fetch on its own during a read, to fetch a missing
|
|
61
|
+
* object of a partial clone, so this is what keeps a repository's `core.sshCommand`, `uploadpack`, `ext::` URL or
|
|
62
|
+
* credential helper from ever running. `GIT_NO_LAZY_FETCH` (git 2.44 and later) stops that fetch from being tried.
|
|
63
|
+
*/
|
|
64
|
+
function gitEnv() {
|
|
65
|
+
const env = Object.fromEntries(Object.entries(process.env).filter(([k]) => PASSTHROUGH_ENV.has(k)));
|
|
66
|
+
return { ...env, GIT_TERMINAL_PROMPT: '0', LC_ALL: 'C', GIT_ALLOW_PROTOCOL: '', GIT_NO_LAZY_FETCH: '1' };
|
|
67
|
+
}
|
|
68
|
+
/** `filter.*` keys a status read may blank; more than this, or a longer key, and the repository is refused. */
|
|
69
|
+
exports.MAX_BLANKED_FILTER_KEYS = 64;
|
|
70
|
+
exports.MAX_FILTER_KEY = 1024;
|
|
71
|
+
/**
|
|
72
|
+
* `GIT_CONFIG_COUNT/KEY_n/VALUE_n` entries that empty each named `filter.*` key. Every key is taken whole as git
|
|
73
|
+
* printed it, never split into driver name and variable, so no name (empty, dotted, holding `=`) can slip past a
|
|
74
|
+
* parser. Unlike `-c name=value` they take the key whole, and they rank as command-line config, above every file.
|
|
75
|
+
* An empty clean, smudge or process command runs nothing, and an empty `required` is false.
|
|
76
|
+
*/
|
|
77
|
+
function blankFilterEnv(keys) {
|
|
78
|
+
const env = { GIT_CONFIG_COUNT: String(keys.length) };
|
|
79
|
+
keys.forEach((key, i) => {
|
|
80
|
+
env[`GIT_CONFIG_KEY_${i}`] = key;
|
|
81
|
+
env[`GIT_CONFIG_VALUE_${i}`] = '';
|
|
82
|
+
});
|
|
83
|
+
return env;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The command line and environment every git call of the gateway uses, reads and `git init` alike. `core.fsmonitor`
|
|
87
|
+
* is a command from the repository's config, so it is turned off for every call. A call that can run a clean filter
|
|
88
|
+
* (status) names the repository's `filter.*` keys in `blankFilterKeys` so no driver runs.
|
|
89
|
+
*/
|
|
90
|
+
function hardenedGit(cwd, args, blankFilterKeys = []) {
|
|
91
|
+
return {
|
|
92
|
+
argv: ['--no-optional-locks', '-c', 'core.fsmonitor=false', ...args],
|
|
93
|
+
env: { ...gitEnv(), GIT_CEILING_DIRECTORIES: path.dirname(cwd), ...blankFilterEnv(blankFilterKeys) },
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** How long a timed-out git gets to clean up its lock files after SIGTERM before the group is killed. */
|
|
97
|
+
/** After git exits, how long its pipes get to deliver the rest of the output. */
|
|
98
|
+
const EXIT_DRAIN_MS = 200;
|
|
99
|
+
const KILL_GRACE_MS = 1000;
|
|
100
|
+
/**
|
|
101
|
+
* Runs git in the folder `cwd`. Discovery stops at `cwd`, so a folder inside some
|
|
102
|
+
* other repository never reads as a repo itself.
|
|
103
|
+
*/
|
|
104
|
+
async function runGit(cwd, args, opts) {
|
|
105
|
+
const { argv, env } = hardenedGit(cwd, args, opts.blankFilterKeys);
|
|
106
|
+
return new Promise((resolve) => {
|
|
107
|
+
// Its own process group, so a timeout also reaches the hooks, filters and ssh that git started.
|
|
108
|
+
const child = (0, child_process_1.spawn)('git', argv, { cwd, env, detached: true, stdio: ['ignore', 'pipe', 'pipe'] });
|
|
109
|
+
const signalGroup = (signal) => {
|
|
110
|
+
try {
|
|
111
|
+
if (child.pid)
|
|
112
|
+
process.kill(-child.pid, signal);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
// The group has already exited.
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
let settled = false;
|
|
119
|
+
const settle = (r) => {
|
|
120
|
+
if (settled)
|
|
121
|
+
return;
|
|
122
|
+
settled = true;
|
|
123
|
+
clearTimeout(timer);
|
|
124
|
+
resolve(r);
|
|
125
|
+
};
|
|
126
|
+
const stdout = [];
|
|
127
|
+
const stderr = [];
|
|
128
|
+
let size = 0;
|
|
129
|
+
const collect = (into) => (chunk) => {
|
|
130
|
+
size += chunk.length;
|
|
131
|
+
if (size > MAX_OUTPUT) {
|
|
132
|
+
signalGroup('SIGKILL');
|
|
133
|
+
return settle((0, result_1.err)('git_failed'));
|
|
134
|
+
}
|
|
135
|
+
into.push(chunk);
|
|
136
|
+
};
|
|
137
|
+
child.stdout.on('data', collect(stdout));
|
|
138
|
+
child.stderr.on('data', collect(stderr));
|
|
139
|
+
child.on('error', (e) => {
|
|
140
|
+
// ENOENT is also what a missing cwd gives, and the folder going away mid-read is not a missing git.
|
|
141
|
+
if (e.code === 'ENOENT' && (0, fs_1.existsSync)(cwd)) {
|
|
142
|
+
if (!warnedGitMissing) {
|
|
143
|
+
warnedGitMissing = true;
|
|
144
|
+
opts.logger.warn('git: git is not installed or not on PATH, so git status is unavailable');
|
|
145
|
+
}
|
|
146
|
+
return settle((0, result_1.err)('git_unavailable'));
|
|
147
|
+
}
|
|
148
|
+
opts.logger.warn(`git: git ${args[0]} in ${cwd} failed: ${(0, status_1.redactCredentials)(e.message)}`);
|
|
149
|
+
settle((0, result_1.err)('git_failed'));
|
|
150
|
+
});
|
|
151
|
+
const finish = (code) => {
|
|
152
|
+
if (code === null)
|
|
153
|
+
return settle((0, result_1.err)('git_failed'));
|
|
154
|
+
settle((0, result_1.ok)({ code, stdout: Buffer.concat(stdout).toString('utf8'), stdoutBytes: Buffer.concat(stdout), stderr: Buffer.concat(stderr).toString('utf8') }));
|
|
155
|
+
};
|
|
156
|
+
child.on('close', finish);
|
|
157
|
+
// A hook's backgrounded child keeps the pipes open long after git is done; take what arrived and let go.
|
|
158
|
+
child.on('exit', (code) => {
|
|
159
|
+
setTimeout(() => {
|
|
160
|
+
child.stdout.destroy();
|
|
161
|
+
child.stderr.destroy();
|
|
162
|
+
finish(code);
|
|
163
|
+
}, EXIT_DRAIN_MS).unref();
|
|
164
|
+
});
|
|
165
|
+
const timer = setTimeout(() => {
|
|
166
|
+
// TERM first: git removes its index.lock on TERM but leaves it behind on KILL.
|
|
167
|
+
signalGroup('SIGTERM');
|
|
168
|
+
setTimeout(() => signalGroup('SIGKILL'), KILL_GRACE_MS).unref();
|
|
169
|
+
// An orphan that escaped the group can still hold the pipes open; let go of them now.
|
|
170
|
+
child.stdout.destroy();
|
|
171
|
+
child.stderr.destroy();
|
|
172
|
+
settle((0, result_1.err)('timeout'));
|
|
173
|
+
}, opts.timeoutMs);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/git/runner.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,wBAGC;AA0BD,kCAKC;AAmBD,wBAsEC;AApKD,iDAAsC;AACtC,2BAAgC;AAChC,2CAA6B;AAC7B,4CAAkD;AAClD,qCAA6C;AAGhC,QAAA,mBAAmB,GAAG,IAAK,CAAC;AAEzC,MAAM,UAAU,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAapC,IAAI,gBAAgB,GAAG,KAAK,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EA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ACL,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export type GitHost = 'github' | 'gitlab' | 'bitbucket' | 'other';
|
|
2
|
+
export type GitSync = 'in_sync' | 'ahead' | 'behind' | 'diverged' | 'no_upstream' | 'upstream_gone' | 'upstream_mismatch' | 'no_remote' | 'detached';
|
|
3
|
+
export type GitChangeKind = 'added' | 'modified' | 'deleted' | 'renamed' | 'copied' | 'type_changed' | 'untracked' | 'conflicted';
|
|
4
|
+
export interface GitFileChange {
|
|
5
|
+
path: string;
|
|
6
|
+
orig_path?: string;
|
|
7
|
+
staged: GitChangeKind | null;
|
|
8
|
+
unstaged: GitChangeKind | null;
|
|
9
|
+
}
|
|
10
|
+
export interface GitRemote {
|
|
11
|
+
name: string;
|
|
12
|
+
url: string;
|
|
13
|
+
host: GitHost;
|
|
14
|
+
web_url: string | null;
|
|
15
|
+
}
|
|
16
|
+
export type GitOperation = 'none' | 'merge' | 'rebase' | 'cherry_pick' | 'revert' | 'bisect';
|
|
17
|
+
export interface GitCommitInfo {
|
|
18
|
+
sha: string;
|
|
19
|
+
subject: string;
|
|
20
|
+
author: string;
|
|
21
|
+
committed_at: string;
|
|
22
|
+
}
|
|
23
|
+
export interface GitStatus {
|
|
24
|
+
branch: string | null;
|
|
25
|
+
detached: boolean;
|
|
26
|
+
has_commits: boolean;
|
|
27
|
+
upstream: string | null;
|
|
28
|
+
ahead: number;
|
|
29
|
+
behind: number;
|
|
30
|
+
sync: GitSync;
|
|
31
|
+
remote: GitRemote | null;
|
|
32
|
+
changes: GitFileChange[];
|
|
33
|
+
change_count: number;
|
|
34
|
+
conflicted_count: number;
|
|
35
|
+
truncated: boolean;
|
|
36
|
+
last_commit: GitCommitInfo | null;
|
|
37
|
+
operation: GitOperation;
|
|
38
|
+
}
|
|
39
|
+
export interface GitSummary {
|
|
40
|
+
branch: string | null;
|
|
41
|
+
detached: boolean;
|
|
42
|
+
sync: GitSync;
|
|
43
|
+
ahead: number;
|
|
44
|
+
behind: number;
|
|
45
|
+
change_count: number;
|
|
46
|
+
conflicted_count: number;
|
|
47
|
+
remote_host: GitHost | null;
|
|
48
|
+
}
|
|
49
|
+
/** What `git status --porcelain=v2 --branch -z` says, before anything else is joined in. */
|
|
50
|
+
export interface ParsedStatus {
|
|
51
|
+
/** null for an unborn branch (`branch.oid (initial)`). */
|
|
52
|
+
oid: string | null;
|
|
53
|
+
/** null when detached. */
|
|
54
|
+
head: string | null;
|
|
55
|
+
upstream: string | null;
|
|
56
|
+
/**
|
|
57
|
+
* The branch has commits and an upstream setting, but no remote-tracking branch: deleted and pruned, or never
|
|
58
|
+
* fetched, which porcelain cannot tell apart. Never set on an unborn branch, where git prints no `branch.ab` either way.
|
|
59
|
+
*/
|
|
60
|
+
upstreamGone: boolean;
|
|
61
|
+
ahead: number;
|
|
62
|
+
behind: number;
|
|
63
|
+
changes: GitFileChange[];
|
|
64
|
+
}
|
|
65
|
+
/** The repo config status needs: remotes and branch tracking. */
|
|
66
|
+
export interface RepoConfig {
|
|
67
|
+
remotes: Array<{
|
|
68
|
+
name: string;
|
|
69
|
+
url: string;
|
|
70
|
+
}>;
|
|
71
|
+
/** `branch.<name>.remote` and `branch.<name>.merge`, keyed by branch name. */
|
|
72
|
+
branches: Record<string, {
|
|
73
|
+
remote?: string;
|
|
74
|
+
merge?: string;
|
|
75
|
+
}>;
|
|
76
|
+
}
|
|
77
|
+
export declare const CHANGES_LIMIT = 200;
|
|
78
|
+
export declare function parseStatusV2(raw: string): ParsedStatus;
|
|
79
|
+
export interface ConfigList {
|
|
80
|
+
config: RepoConfig;
|
|
81
|
+
/** Every `filter.*` key the repository's own config defines, directly or through an include, as git printed it. */
|
|
82
|
+
filterKeys: string[];
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* True when a repository-scope `filter.*` key in the raw `git config -z` output is not valid UTF-8. Environment values
|
|
86
|
+
* are UTF-8 strings, so such a key cannot be passed back byte for byte, and a lossy copy would blank a different
|
|
87
|
+
* driver. The caller refuses the repository instead.
|
|
88
|
+
*/
|
|
89
|
+
export declare function hasUndecodableFilterKey(raw: Buffer): boolean;
|
|
90
|
+
/** What `git config --list -z --show-scope` prints: `scope NUL key NL value NUL` per entry, a valueless key without the NL. */
|
|
91
|
+
export declare function parseConfigList(raw: string): ConfigList;
|
|
92
|
+
export declare function deriveSync(s: {
|
|
93
|
+
detached: boolean;
|
|
94
|
+
hasCommits: boolean;
|
|
95
|
+
upstream: string | null;
|
|
96
|
+
upstreamGone: boolean;
|
|
97
|
+
upstreamMismatch: boolean;
|
|
98
|
+
ahead: number;
|
|
99
|
+
behind: number;
|
|
100
|
+
hasRemote: boolean;
|
|
101
|
+
}): GitSync;
|
|
102
|
+
/** `https://user:token@host/x?token=s` becomes `https://host/x?token=[redacted]`, anywhere in `text`. */
|
|
103
|
+
export declare function redactCredentials(text: string): string;
|
|
104
|
+
/** The remote's hostname alone, or null when it is not a plain DNS name. */
|
|
105
|
+
export declare function remoteHostname(url: string): string | null;
|
|
106
|
+
export declare function describeRemote(name: string, rawUrl: string): GitRemote;
|
|
107
|
+
/** The upstream's remote, else "origin", else the only remote. */
|
|
108
|
+
export declare function pickRemote(cfg: RepoConfig, branch: string | null): {
|
|
109
|
+
name: string;
|
|
110
|
+
url: string;
|
|
111
|
+
} | null;
|
|
112
|
+
export declare function buildStatus(input: {
|
|
113
|
+
parsed: ParsedStatus;
|
|
114
|
+
config: RepoConfig;
|
|
115
|
+
lastCommit: GitCommitInfo | null;
|
|
116
|
+
operation: GitOperation;
|
|
117
|
+
}): GitStatus;
|
|
118
|
+
export declare function toSummary(s: GitStatus): GitSummary;
|
|
119
|
+
//# sourceMappingURL=status.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/git/status.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,OAAO,CAAC;AAElE,MAAM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,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CHANGES_LIMIT = void 0;
|
|
4
|
+
exports.parseStatusV2 = parseStatusV2;
|
|
5
|
+
exports.hasUndecodableFilterKey = hasUndecodableFilterKey;
|
|
6
|
+
exports.parseConfigList = parseConfigList;
|
|
7
|
+
exports.deriveSync = deriveSync;
|
|
8
|
+
exports.redactCredentials = redactCredentials;
|
|
9
|
+
exports.remoteHostname = remoteHostname;
|
|
10
|
+
exports.describeRemote = describeRemote;
|
|
11
|
+
exports.pickRemote = pickRemote;
|
|
12
|
+
exports.buildStatus = buildStatus;
|
|
13
|
+
exports.toSummary = toSummary;
|
|
14
|
+
exports.CHANGES_LIMIT = 200;
|
|
15
|
+
const KIND_BY_CODE = {
|
|
16
|
+
'.': null,
|
|
17
|
+
M: 'modified',
|
|
18
|
+
T: 'type_changed',
|
|
19
|
+
A: 'added',
|
|
20
|
+
D: 'deleted',
|
|
21
|
+
R: 'renamed',
|
|
22
|
+
C: 'copied',
|
|
23
|
+
U: 'conflicted',
|
|
24
|
+
};
|
|
25
|
+
function kindOf(code) {
|
|
26
|
+
return code in KIND_BY_CODE ? KIND_BY_CODE[code] : 'modified';
|
|
27
|
+
}
|
|
28
|
+
/** Splits off the first `n` space-separated fields; the remainder is the path, which may contain spaces. */
|
|
29
|
+
function fields(record, n) {
|
|
30
|
+
const parts = [];
|
|
31
|
+
let at = 0;
|
|
32
|
+
for (let i = 0; i < n; i++) {
|
|
33
|
+
const sp = record.indexOf(' ', at);
|
|
34
|
+
parts.push(record.slice(at, sp));
|
|
35
|
+
at = sp + 1;
|
|
36
|
+
}
|
|
37
|
+
return { parts, rest: record.slice(at) };
|
|
38
|
+
}
|
|
39
|
+
function parseStatusV2(raw) {
|
|
40
|
+
const out = { oid: null, head: null, upstream: null, upstreamGone: false, ahead: 0, behind: 0, changes: [] };
|
|
41
|
+
let sawAheadBehind = false;
|
|
42
|
+
const records = raw.split('\0');
|
|
43
|
+
for (let i = 0; i < records.length; i++) {
|
|
44
|
+
const rec = records[i];
|
|
45
|
+
if (rec === '')
|
|
46
|
+
continue;
|
|
47
|
+
switch (rec[0]) {
|
|
48
|
+
case '#': {
|
|
49
|
+
const { parts, rest } = fields(rec, 2);
|
|
50
|
+
const key = parts[1];
|
|
51
|
+
if (key === 'branch.oid')
|
|
52
|
+
out.oid = rest === '(initial)' ? null : rest;
|
|
53
|
+
else if (key === 'branch.head')
|
|
54
|
+
out.head = rest === '(detached)' ? null : rest;
|
|
55
|
+
else if (key === 'branch.upstream')
|
|
56
|
+
out.upstream = rest;
|
|
57
|
+
else if (key === 'branch.ab') {
|
|
58
|
+
const m = /^\+(\d+) -(\d+)$/.exec(rest);
|
|
59
|
+
sawAheadBehind = true;
|
|
60
|
+
if (m)
|
|
61
|
+
[out.ahead, out.behind] = [Number(m[1]), Number(m[2])];
|
|
62
|
+
}
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case '1': {
|
|
66
|
+
const { parts, rest } = fields(rec, 8);
|
|
67
|
+
out.changes.push({ path: rest, staged: kindOf(parts[1][0]), unstaged: kindOf(parts[1][1]) });
|
|
68
|
+
break;
|
|
69
|
+
}
|
|
70
|
+
case '2': {
|
|
71
|
+
const { parts, rest } = fields(rec, 9);
|
|
72
|
+
// The original path is the next NUL-separated record.
|
|
73
|
+
out.changes.push({ path: rest, orig_path: records[++i], staged: kindOf(parts[1][0]), unstaged: kindOf(parts[1][1]) });
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
76
|
+
case 'u': {
|
|
77
|
+
const { rest } = fields(rec, 10);
|
|
78
|
+
out.changes.push({ path: rest, staged: 'conflicted', unstaged: 'conflicted' });
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case '?':
|
|
82
|
+
out.changes.push({ path: rec.slice(2), staged: null, unstaged: 'untracked' });
|
|
83
|
+
break;
|
|
84
|
+
// '!' (ignored) is never requested.
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
out.upstreamGone = out.oid !== null && out.upstream !== null && !sawAheadBehind;
|
|
88
|
+
return out;
|
|
89
|
+
}
|
|
90
|
+
/** Config scopes whose files the repository controls. Git reports an included file under the scope of the file that includes it. */
|
|
91
|
+
const REPO_SCOPES = new Set(['local', 'worktree']);
|
|
92
|
+
/**
|
|
93
|
+
* True when a repository-scope `filter.*` key in the raw `git config -z` output is not valid UTF-8. Environment values
|
|
94
|
+
* are UTF-8 strings, so such a key cannot be passed back byte for byte, and a lossy copy would blank a different
|
|
95
|
+
* driver. The caller refuses the repository instead.
|
|
96
|
+
*/
|
|
97
|
+
function hasUndecodableFilterKey(raw) {
|
|
98
|
+
const strict = new TextDecoder('utf-8', { fatal: true });
|
|
99
|
+
const fields = [];
|
|
100
|
+
for (let start = 0; start <= raw.length;) {
|
|
101
|
+
const end = raw.indexOf(0, start);
|
|
102
|
+
fields.push(raw.subarray(start, end < 0 ? raw.length : end));
|
|
103
|
+
if (end < 0)
|
|
104
|
+
break;
|
|
105
|
+
start = end + 1;
|
|
106
|
+
}
|
|
107
|
+
for (let i = 0; i + 1 < fields.length; i += 2) {
|
|
108
|
+
if (!REPO_SCOPES.has(fields[i].toString('latin1')))
|
|
109
|
+
continue;
|
|
110
|
+
const entry = fields[i + 1];
|
|
111
|
+
const nl = entry.indexOf(10);
|
|
112
|
+
const key = nl < 0 ? entry : entry.subarray(0, nl);
|
|
113
|
+
if (!key.subarray(0, 7).equals(Buffer.from('filter.')))
|
|
114
|
+
continue;
|
|
115
|
+
try {
|
|
116
|
+
strict.decode(key);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
/** What `git config --list -z --show-scope` prints: `scope NUL key NL value NUL` per entry, a valueless key without the NL. */
|
|
125
|
+
function parseConfigList(raw) {
|
|
126
|
+
var _a, _b;
|
|
127
|
+
const cfg = { remotes: [], branches: {} };
|
|
128
|
+
const filters = new Set();
|
|
129
|
+
const fields = raw.split('\0');
|
|
130
|
+
for (let i = 0; i + 1 < fields.length; i += 2) {
|
|
131
|
+
const scope = fields[i];
|
|
132
|
+
const entry = fields[i + 1];
|
|
133
|
+
const nl = entry.indexOf('\n');
|
|
134
|
+
const key = nl < 0 ? entry : entry.slice(0, nl);
|
|
135
|
+
const value = nl < 0 ? '' : entry.slice(nl + 1);
|
|
136
|
+
let m;
|
|
137
|
+
if ((m = /^remote\.(.+)\.url$/.exec(key))) {
|
|
138
|
+
if (!cfg.remotes.some((r) => r.name === m[1]))
|
|
139
|
+
cfg.remotes.push({ name: m[1], url: value });
|
|
140
|
+
}
|
|
141
|
+
else if ((m = /^branch\.(.+)\.(remote|merge)$/.exec(key))) {
|
|
142
|
+
((_a = cfg.branches)[_b = m[1]] ?? (_a[_b] = {}))[m[2]] = value;
|
|
143
|
+
}
|
|
144
|
+
else if (REPO_SCOPES.has(scope) && key.startsWith('filter.')) {
|
|
145
|
+
filters.add(key);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return { config: cfg, filterKeys: [...filters] };
|
|
149
|
+
}
|
|
150
|
+
function deriveSync(s) {
|
|
151
|
+
if (s.detached)
|
|
152
|
+
return 'detached';
|
|
153
|
+
if (s.upstream === null)
|
|
154
|
+
return s.hasRemote ? 'no_upstream' : 'no_remote';
|
|
155
|
+
if (s.upstreamMismatch)
|
|
156
|
+
return 'upstream_mismatch';
|
|
157
|
+
if (s.upstreamGone)
|
|
158
|
+
return 'upstream_gone';
|
|
159
|
+
// Unborn and nothing online to pull: in sync would claim it is published.
|
|
160
|
+
if (!s.hasCommits && s.behind === 0)
|
|
161
|
+
return 'no_upstream';
|
|
162
|
+
if (s.ahead > 0 && s.behind > 0)
|
|
163
|
+
return 'diverged';
|
|
164
|
+
if (s.ahead > 0)
|
|
165
|
+
return 'ahead';
|
|
166
|
+
if (s.behind > 0)
|
|
167
|
+
return 'behind';
|
|
168
|
+
return 'in_sync';
|
|
169
|
+
}
|
|
170
|
+
const SECRET_PARAM = /([?&#;](?:[\w.-]*(?:token|password|passwd|secret|sig|signature|auth|credential)|api[_-]?key|key)=)[^&#\s'"]+/gi;
|
|
171
|
+
/** `https://user:token@host/x?token=s` becomes `https://host/x?token=[redacted]`, anywhere in `text`. */
|
|
172
|
+
function redactCredentials(text) {
|
|
173
|
+
return text.replace(/:\/\/[^\s/]*@/g, '://').replace(SECRET_PARAM, '$1[redacted]');
|
|
174
|
+
}
|
|
175
|
+
const KNOWN_HOSTS = {
|
|
176
|
+
'github.com': 'github',
|
|
177
|
+
'gitlab.com': 'gitlab',
|
|
178
|
+
'bitbucket.org': 'bitbucket',
|
|
179
|
+
};
|
|
180
|
+
/** Host and `owner/repo` path from an https, ssh:// or scp-style (`git@host:owner/repo`) URL. */
|
|
181
|
+
function hostAndPath(url) {
|
|
182
|
+
const scheme = /^[a-z][a-z0-9+.-]*:\/\/(?:[^/@]*@)?([^/:]+)(?::\d+)?\/(.*)$/i.exec(url);
|
|
183
|
+
if (scheme)
|
|
184
|
+
return { host: scheme[1].toLowerCase(), repoPath: scheme[2] };
|
|
185
|
+
const scp = /^(?:[^@/]+@)?([^/:]+):(?!\/)(.*)$/.exec(url);
|
|
186
|
+
if (scp)
|
|
187
|
+
return { host: scp[1].toLowerCase(), repoPath: scp[2] };
|
|
188
|
+
return null;
|
|
189
|
+
}
|
|
190
|
+
/** The remote's hostname alone, or null when it is not a plain DNS name. */
|
|
191
|
+
function remoteHostname(url) {
|
|
192
|
+
const host = hostAndPath(redactCredentials(url))?.host;
|
|
193
|
+
return host && /^[a-z0-9.-]+$/.test(host) ? host : null;
|
|
194
|
+
}
|
|
195
|
+
function describeRemote(name, rawUrl) {
|
|
196
|
+
const url = redactCredentials(rawUrl);
|
|
197
|
+
const parsed = hostAndPath(url);
|
|
198
|
+
const host = (parsed && KNOWN_HOSTS[parsed.host]) ?? 'other';
|
|
199
|
+
const repoPath = parsed?.repoPath.replace(/[?#].*$/, '').replace(/\.git$/, '').replace(/\/+$/, '');
|
|
200
|
+
const web_url = host !== 'other' && repoPath ? `https://${parsed.host}/${repoPath}` : null;
|
|
201
|
+
return { name, url, host, web_url };
|
|
202
|
+
}
|
|
203
|
+
/** The upstream's remote, else "origin", else the only remote. */
|
|
204
|
+
function pickRemote(cfg, branch) {
|
|
205
|
+
const upstreamRemote = branch ? cfg.branches[branch]?.remote : undefined;
|
|
206
|
+
return (cfg.remotes.find((r) => r.name === upstreamRemote) ??
|
|
207
|
+
cfg.remotes.find((r) => r.name === 'origin') ??
|
|
208
|
+
(cfg.remotes.length === 1 ? cfg.remotes[0] : null));
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* The upstream is not a same-named branch on a configured remote: `checkout -b feature origin/main`, or a branch
|
|
212
|
+
* tracking a local one (remote "."). Publishing there would move someone else's branch.
|
|
213
|
+
*/
|
|
214
|
+
function tracksAnotherBranch(config, head, upstream) {
|
|
215
|
+
if (head === null || upstream === null)
|
|
216
|
+
return false;
|
|
217
|
+
const tracking = config.branches[head];
|
|
218
|
+
return tracking?.merge !== `refs/heads/${head}` || !config.remotes.some((r) => r.name === tracking.remote);
|
|
219
|
+
}
|
|
220
|
+
/** Sort rank: conflicted, staged, unstaged, untracked. */
|
|
221
|
+
function rank(c) {
|
|
222
|
+
if (c.staged === 'conflicted')
|
|
223
|
+
return 0;
|
|
224
|
+
if (c.staged !== null)
|
|
225
|
+
return 1;
|
|
226
|
+
if (c.unstaged !== 'untracked')
|
|
227
|
+
return 2;
|
|
228
|
+
return 3;
|
|
229
|
+
}
|
|
230
|
+
function buildStatus(input) {
|
|
231
|
+
const { parsed, config } = input;
|
|
232
|
+
const detached = parsed.head === null;
|
|
233
|
+
const picked = pickRemote(config, parsed.head);
|
|
234
|
+
const sorted = [...parsed.changes].sort((a, b) => rank(a) - rank(b) || (a.path < b.path ? -1 : a.path > b.path ? 1 : 0));
|
|
235
|
+
return {
|
|
236
|
+
branch: parsed.head,
|
|
237
|
+
detached,
|
|
238
|
+
has_commits: parsed.oid !== null,
|
|
239
|
+
upstream: parsed.upstream,
|
|
240
|
+
ahead: parsed.ahead,
|
|
241
|
+
behind: parsed.behind,
|
|
242
|
+
sync: deriveSync({
|
|
243
|
+
detached,
|
|
244
|
+
hasCommits: parsed.oid !== null,
|
|
245
|
+
upstream: parsed.upstream,
|
|
246
|
+
upstreamGone: parsed.upstreamGone,
|
|
247
|
+
upstreamMismatch: tracksAnotherBranch(config, parsed.head, parsed.upstream),
|
|
248
|
+
ahead: parsed.ahead,
|
|
249
|
+
behind: parsed.behind,
|
|
250
|
+
hasRemote: config.remotes.length > 0,
|
|
251
|
+
}),
|
|
252
|
+
remote: picked ? describeRemote(picked.name, picked.url) : null,
|
|
253
|
+
changes: sorted.slice(0, exports.CHANGES_LIMIT),
|
|
254
|
+
change_count: sorted.length,
|
|
255
|
+
conflicted_count: sorted.filter((c) => c.staged === 'conflicted').length,
|
|
256
|
+
truncated: sorted.length > exports.CHANGES_LIMIT,
|
|
257
|
+
last_commit: input.lastCommit,
|
|
258
|
+
operation: input.operation,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function toSummary(s) {
|
|
262
|
+
return {
|
|
263
|
+
branch: s.branch,
|
|
264
|
+
detached: s.detached,
|
|
265
|
+
sync: s.sync,
|
|
266
|
+
ahead: s.ahead,
|
|
267
|
+
behind: s.behind,
|
|
268
|
+
change_count: s.change_count,
|
|
269
|
+
conflicted_count: s.conflicted_count,
|
|
270
|
+
remote_host: s.remote?.host ?? null,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
//# sourceMappingURL=status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"status.js","sourceRoot":"","sources":["../../src/git/status.ts"],"names":[],"mappings":";;;AA+HA,sCA6CC;AAgBD,0DAkBC;AAGD,0CAoBC;AAED,gCAoBC;AAKD,8CAEC;AAkBD,wCA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C,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI;QAC/D,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAa,CAAC;QACvC,YAAY,EAAE,MAAM,CAAC,MAAM;QAC3B,gBAAgB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,YAAY,CAAC,CAAC,MAAM;QACxE,SAAS,EAAE,MAAM,CAAC,MAAM,GAAG,qBAAa;QACxC,WAAW,EAAE,KAAK,CAAC,UAAU;QAC7B,SAAS,EAAE,KAAK,CAAC,SAAS;KAC3B,CAAC;AACJ,CAAC;AAED,SAAgB,SAAS,CAAC,CAAY;IACpC,OAAO;QACL,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,KAAK,EAAE,CAAC,CAAC,KAAK;QACd,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,YAAY,EAAE,CAAC,CAAC,YAAY;QAC5B,gBAAgB,EAAE,CAAC,CAAC,gBAAgB;QACpC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,IAAI,IAAI;KACpC,CAAC;AACJ,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -58,6 +58,7 @@ const skills_1 = require("./skills");
|
|
|
58
58
|
const sync_1 = require("./skills/sync");
|
|
59
59
|
const factory_1 = require("./watch/factory");
|
|
60
60
|
const runner_1 = require("./agent/runner");
|
|
61
|
+
const session_cwd_1 = require("./files/session-cwd");
|
|
61
62
|
const skill_learning_1 = require("./agent/skill-learning");
|
|
62
63
|
const config_1 = require("./agent/skill-learning/config");
|
|
63
64
|
const db_1 = require("./history/db");
|
|
@@ -263,7 +264,7 @@ async function startAgent(agentConfig, gatewayConfig, ctx) {
|
|
|
263
264
|
// Create runner
|
|
264
265
|
let runner;
|
|
265
266
|
try {
|
|
266
|
-
runner = new runner_1.AgentRunner(agentConfig, gatewayConfig, logger);
|
|
267
|
+
runner = new runner_1.AgentRunner(agentConfig, gatewayConfig, logger, (0, session_cwd_1.createCwdResolver)(gatewayConfig, logger));
|
|
267
268
|
if (workspace.skillRegistry) {
|
|
268
269
|
runner.setSkillRegistry(workspace.skillRegistry);
|
|
269
270
|
}
|
|
@@ -626,8 +627,10 @@ async function main() {
|
|
|
626
627
|
// logs/gateway.log at startup too, not only on reload (#427).
|
|
627
628
|
const startupSkips = [];
|
|
628
629
|
let publicUrlUnsetAtStartup = false;
|
|
630
|
+
const startupWarnings = [];
|
|
629
631
|
const config = (0, loader_1.loadConfig)(CONFIG_PATH, {
|
|
630
632
|
onSkippedAgent: (s) => startupSkips.push(s),
|
|
633
|
+
onWarning: (m) => startupWarnings.push(m),
|
|
631
634
|
onPublicUrlUnset: () => { publicUrlUnsetAtStartup = true; },
|
|
632
635
|
});
|
|
633
636
|
config.gateway.logDir = (0, paths_1.expandHome)(config.gateway.logDir);
|
|
@@ -649,6 +652,8 @@ async function main() {
|
|
|
649
652
|
// went missing.
|
|
650
653
|
const globalLogger = (0, logger_1.createLogger)('gateway', (0, paths_1.expandHome)(config.gateway.logDir));
|
|
651
654
|
(0, loader_1.logSkippedAgents)(globalLogger, startupSkips, 'Agent skipped at startup');
|
|
655
|
+
for (const message of startupWarnings)
|
|
656
|
+
globalLogger.warn(message);
|
|
652
657
|
// Same #427 rationale as skipped agents: the console.warn already happened
|
|
653
658
|
// inside loadConfig (before logDir/globalLogger could exist), replay it here
|
|
654
659
|
// so it also reaches logs/gateway.log under structured/JSON logging (#472).
|
|
@@ -848,7 +853,7 @@ async function main() {
|
|
|
848
853
|
// stays in the background below; only this cheap registry read is awaited.
|
|
849
854
|
const restorePending = await appInstaller.markRestorePending();
|
|
850
855
|
// Start gateway router
|
|
851
|
-
const router = new gateway_router_1.GatewayRouter(agentRunners, agentConfigs, undefined, config, cronManager, CONFIG_PATH, appsRegistry, appInstaller, registryClient);
|
|
856
|
+
const router = new gateway_router_1.GatewayRouter(agentRunners, agentConfigs, undefined, config, cronManager, CONFIG_PATH, appsRegistry, appInstaller, registryClient, globalLogger);
|
|
852
857
|
await router.start(PORT);
|
|
853
858
|
console.log(`[gateway] Listening on port ${PORT}`);
|
|
854
859
|
// Write the pidfile so the CLI can detect a foreground gateway (and SIGTERM it
|