@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,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findHold = findHold;
|
|
4
|
+
exports.addHold = addHold;
|
|
5
|
+
exports.releaseHold = releaseHold;
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
const paths_1 = require("./paths");
|
|
8
|
+
const holds = new Map();
|
|
9
|
+
/** The hold on this folder, one inside it, or one containing it. */
|
|
10
|
+
function findHold(dir) {
|
|
11
|
+
return [...holds.values()].find((hold) => (0, paths_1.overlaps)(hold.dir, dir));
|
|
12
|
+
}
|
|
13
|
+
/** Called after checking for overlap in the same synchronous step. */
|
|
14
|
+
function addHold(dir) {
|
|
15
|
+
const hold = { id: (0, crypto_1.randomUUID)(), dir };
|
|
16
|
+
holds.set(hold.id, hold);
|
|
17
|
+
return hold;
|
|
18
|
+
}
|
|
19
|
+
function releaseHold(id) { holds.delete(id); }
|
|
20
|
+
//# sourceMappingURL=holds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"holds.js","sourceRoot":"","sources":["../../src/files/holds.ts"],"names":[],"mappings":";;AAQA,4BAEC;AAGD,0BAIC;AAED,kCAAmE;AAnBnE,mCAAoC;AACpC,mCAAmC;AAInC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAgB,CAAC;AAEtC,oEAAoE;AACpE,SAAgB,QAAQ,CAAC,GAAW;IAClC,OAAO,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAA,gBAAQ,EAAC,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC,CAAC;AACrE,CAAC;AAED,sEAAsE;AACtE,SAAgB,OAAO,CAAC,GAAW;IACjC,MAAM,IAAI,GAAG,EAAE,EAAE,EAAE,IAAA,mBAAU,GAAE,EAAE,GAAG,EAAE,CAAC;IACvC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACzB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAgB,WAAW,CAAC,EAAU,IAAU,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Result } from '../utils/result';
|
|
2
|
+
/** The files root when gateway.files.root is not set. */
|
|
3
|
+
export declare const DEFAULT_FILES_ROOT = "~/projects";
|
|
4
|
+
/** One path segment that passed {@link ENTRY_NAME_RE}. */
|
|
5
|
+
export type EntryName = string & {
|
|
6
|
+
readonly __brand: 'EntryName';
|
|
7
|
+
};
|
|
8
|
+
/** A path under the files root: `''` for the root itself, else entry names joined by `/`. */
|
|
9
|
+
export type RelPath = string & {
|
|
10
|
+
readonly __brand: 'RelPath';
|
|
11
|
+
};
|
|
12
|
+
export type FilesErrorCode = 'invalid_path' | 'invalid_name' | 'not_a_directory' | 'path_escape' | 'symlink_in_path' | 'cross_device' | 'permission_denied' | 'forbidden_key' | 'not_found' | 'already_exists' | 'internal';
|
|
13
|
+
export declare function parseEntryName(raw: unknown, allowHidden?: boolean): Result<EntryName, 'invalid_name'>;
|
|
14
|
+
/** `invalid_path` for a non-string, an absolute path, an empty segment or too many segments; `invalid_name` for a segment the name rule refuses. */
|
|
15
|
+
export declare function parseRelPath(raw: unknown, allowHidden?: boolean): Result<RelPath, 'invalid_path' | 'invalid_name'>;
|
|
16
|
+
export declare function pathSegments(rel: RelPath): EntryName[];
|
|
17
|
+
export declare function joinRel(rel: RelPath, name: EntryName): RelPath;
|
|
18
|
+
export declare function errnoToCode(e: unknown): FilesErrorCode;
|
|
19
|
+
/** `a` and `b` are the same folder, or one holds the other. Both must be real paths. */
|
|
20
|
+
export declare function overlaps(a: string, b: string): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Resolve `rel` under `realRoot` (which must already be a realpath) following
|
|
23
|
+
* every symlink, and refuse anything whose real location is outside the root.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveInside(realRoot: string, rel: string): Promise<Result<string, FilesErrorCode>>;
|
|
26
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/files/paths.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAElD,yDAAyD;AACzD,eAAO,MAAM,kBAAkB,eAAe,CAAC;AAE/C,0DAA0D;AAC1D,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAA;CAAE,CAAC;AAEnE,6FAA6F;AAC7F,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,SAAS,CAAA;CAAE,CAAC;AAE/D,MAAM,MAAM,cAAc,GACtB,cAAc,GACd,cAAc,GACd,iBAAiB,GACjB,aAAa,GACb,iBAAiB,GACjB,cAAc,GACd,mBAAmB,GACnB,eAAe,GACf,WAAW,GACX,gBAAgB,GAChB,UAAU,CAAC;AASf,wBAAgB,cAAc,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW,UAAQ,GAAG,MAAM,CAAC,SAAS,EAAE,cAAc,CAAC,CAOnG;AAED,oJAAoJ;AACpJ,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,EAAE,WAAW,UAAQ,GAAG,MAAM,CAAC,OAAO,EAAE,cAAc,GAAG,cAAc,CAAC,CAMhH;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,EAAE,CAEtD;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,GAAG,OAAO,CAE9D;AAaD,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,GAAG,cAAc,CAGtD;AAED,wFAAwF;AACxF,wBAAgB,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED;;;GAGG;AACH,wBAAsB,aAAa,CACjC,QAAQ,EAAE,MAAM,EAChB,GAAG,EAAE,MAAM,GACV,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAQzC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
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.DEFAULT_FILES_ROOT = void 0;
|
|
37
|
+
exports.parseEntryName = parseEntryName;
|
|
38
|
+
exports.parseRelPath = parseRelPath;
|
|
39
|
+
exports.pathSegments = pathSegments;
|
|
40
|
+
exports.joinRel = joinRel;
|
|
41
|
+
exports.errnoToCode = errnoToCode;
|
|
42
|
+
exports.overlaps = overlaps;
|
|
43
|
+
exports.resolveInside = resolveInside;
|
|
44
|
+
const fs_1 = require("fs");
|
|
45
|
+
const path = __importStar(require("path"));
|
|
46
|
+
const paths_1 = require("../utils/paths");
|
|
47
|
+
const result_1 = require("../utils/result");
|
|
48
|
+
/** The files root when gateway.files.root is not set. */
|
|
49
|
+
exports.DEFAULT_FILES_ROOT = '~/projects';
|
|
50
|
+
/**
|
|
51
|
+
* Ordinary routes use entry names without a dot prefix. Delete may opt into hidden names but still refuses trash.
|
|
52
|
+
*/
|
|
53
|
+
const ENTRY_NAME_RE = /^[A-Za-z0-9][A-Za-z0-9._-]{0,63}$/;
|
|
54
|
+
const MAX_PATH_DEPTH = 32;
|
|
55
|
+
function parseEntryName(raw, allowHidden = false) {
|
|
56
|
+
const visible = typeof raw === 'string' && ENTRY_NAME_RE.test(raw);
|
|
57
|
+
const hidden = allowHidden && typeof raw === 'string' && /^\.[A-Za-z0-9][A-Za-z0-9._-]{0,62}$/.test(raw) && !raw.startsWith('.deleting-');
|
|
58
|
+
if (!visible && !hidden) {
|
|
59
|
+
return (0, result_1.err)('invalid_name');
|
|
60
|
+
}
|
|
61
|
+
return (0, result_1.ok)(raw);
|
|
62
|
+
}
|
|
63
|
+
/** `invalid_path` for a non-string, an absolute path, an empty segment or too many segments; `invalid_name` for a segment the name rule refuses. */
|
|
64
|
+
function parseRelPath(raw, allowHidden = false) {
|
|
65
|
+
if (typeof raw !== 'string')
|
|
66
|
+
return (0, result_1.err)('invalid_path');
|
|
67
|
+
if (raw === '')
|
|
68
|
+
return (0, result_1.ok)(raw);
|
|
69
|
+
const segments = raw.split('/');
|
|
70
|
+
if (segments.length > MAX_PATH_DEPTH || segments.some((s) => s === ''))
|
|
71
|
+
return (0, result_1.err)('invalid_path');
|
|
72
|
+
return segments.every((s) => parseEntryName(s, allowHidden).ok) ? (0, result_1.ok)(raw) : (0, result_1.err)('invalid_name');
|
|
73
|
+
}
|
|
74
|
+
function pathSegments(rel) {
|
|
75
|
+
return rel === '' ? [] : rel.split('/');
|
|
76
|
+
}
|
|
77
|
+
function joinRel(rel, name) {
|
|
78
|
+
return (rel === '' ? name : `${rel}/${name}`);
|
|
79
|
+
}
|
|
80
|
+
const ERRNO_CODES = {
|
|
81
|
+
ENOENT: 'not_found',
|
|
82
|
+
ENOTDIR: 'not_a_directory',
|
|
83
|
+
EACCES: 'permission_denied',
|
|
84
|
+
EPERM: 'permission_denied',
|
|
85
|
+
EEXIST: 'already_exists',
|
|
86
|
+
EXDEV: 'cross_device',
|
|
87
|
+
// Only reachable through a symlink loop, which never resolves inside the root.
|
|
88
|
+
ELOOP: 'path_escape',
|
|
89
|
+
};
|
|
90
|
+
function errnoToCode(e) {
|
|
91
|
+
const code = e?.code;
|
|
92
|
+
return (code && ERRNO_CODES[code]) || 'internal';
|
|
93
|
+
}
|
|
94
|
+
/** `a` and `b` are the same folder, or one holds the other. Both must be real paths. */
|
|
95
|
+
function overlaps(a, b) {
|
|
96
|
+
return (0, paths_1.pathWithin)(a, b) || (0, paths_1.pathWithin)(b, a);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Resolve `rel` under `realRoot` (which must already be a realpath) following
|
|
100
|
+
* every symlink, and refuse anything whose real location is outside the root.
|
|
101
|
+
*/
|
|
102
|
+
async function resolveInside(realRoot, rel) {
|
|
103
|
+
let real;
|
|
104
|
+
try {
|
|
105
|
+
real = await fs_1.promises.realpath(path.join(realRoot, rel));
|
|
106
|
+
}
|
|
107
|
+
catch (e) {
|
|
108
|
+
return (0, result_1.err)(errnoToCode(e));
|
|
109
|
+
}
|
|
110
|
+
return (0, paths_1.pathWithin)(realRoot, real) ? (0, result_1.ok)(real) : (0, result_1.err)('path_escape');
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=paths.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.js","sourceRoot":"","sources":["../../src/files/paths.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,wCAOC;AAGD,oCAMC;AAED,oCAEC;AAED,0BAEC;AAaD,kCAGC;AAGD,4BAEC;AAMD,sCAWC;AAhGD,2BAAqC;AACrC,2CAA6B;AAC7B,0CAA4C;AAC5C,4CAAkD;AAElD,yDAAyD;AAC5C,Q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AC;IACtD,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,OAAO,IAAA,YAAG,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC7B,CAAC;IACD,OAAO,IAAA,kBAAU,EAAC,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,WAAE,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAA,YAAG,EAAC,aAAa,CAAC,CAAC;AACpE,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CwdResolver } from '../session/cwd';
|
|
2
|
+
import type { GatewayConfig, Logger } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Session working folders under `gateway.files.root`. A cwd is any folder under the root except the root itself, named
|
|
5
|
+
* by a path the files API accepts. It is stored as an absolute path and resolved again at every spawn and turn.
|
|
6
|
+
*/
|
|
7
|
+
export declare function createCwdResolver(config: GatewayConfig, logger: Logger): CwdResolver;
|
|
8
|
+
//# sourceMappingURL=session-cwd.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-cwd.d.ts","sourceRoot":"","sources":["../../src/files/session-cwd.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,WAAW,EAAoC,MAAM,gBAAgB,CAAC;AACnG,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAoBtD;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,CAuEpF"}
|
|
@@ -0,0 +1,139 @@
|
|
|
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.createCwdResolver = createCwdResolver;
|
|
37
|
+
const fs_1 = require("fs");
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
const paths_1 = require("../utils/paths");
|
|
40
|
+
const result_1 = require("../utils/result");
|
|
41
|
+
const read_1 = require("../git/read");
|
|
42
|
+
const status_1 = require("../git/status");
|
|
43
|
+
const config_1 = require("./config");
|
|
44
|
+
const fs_2 = require("./fs");
|
|
45
|
+
const holds_1 = require("./holds");
|
|
46
|
+
const paths_2 = require("./paths");
|
|
47
|
+
/** A branch name the note may carry verbatim. Git allows far more, and the note is a prompt. */
|
|
48
|
+
const PLAIN_BRANCH_RE = /^[\w./-]{1,100}$/;
|
|
49
|
+
const UNAVAILABLE = {
|
|
50
|
+
not_found: 'not_found',
|
|
51
|
+
path_escape: 'outside_root',
|
|
52
|
+
not_a_directory: 'not_a_directory',
|
|
53
|
+
permission_denied: 'permission_denied',
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Session working folders under `gateway.files.root`. A cwd is any folder under the root except the root itself, named
|
|
57
|
+
* by a path the files API accepts. It is stored as an absolute path and resolved again at every spawn and turn.
|
|
58
|
+
*/
|
|
59
|
+
function createCwdResolver(config, logger) {
|
|
60
|
+
const root = () => (0, config_1.resolveFilesRoot)(config);
|
|
61
|
+
/** The root-relative path of `abs`, under the real root or the configured spelling of it. */
|
|
62
|
+
async function relUnderRoot(abs) {
|
|
63
|
+
const realRoot = await fs_1.promises.realpath(root()).catch(() => null);
|
|
64
|
+
if (!realRoot)
|
|
65
|
+
return (0, result_1.err)('not_found');
|
|
66
|
+
const base = [realRoot, root()].find((r) => (0, paths_1.pathWithin)(r, abs));
|
|
67
|
+
if (base === undefined)
|
|
68
|
+
return (0, result_1.err)('outside_root');
|
|
69
|
+
const rel = (0, paths_2.parseRelPath)(path.relative(base, abs).split(path.sep).join('/'));
|
|
70
|
+
return rel.ok ? (0, result_1.ok)({ realRoot, rel: rel.value }) : (0, result_1.err)('invalid');
|
|
71
|
+
}
|
|
72
|
+
/** Exact match on the real folder, no inheritance into subfolders, and never through a symlink alias. */
|
|
73
|
+
function trusted(realRoot, rel, dir) {
|
|
74
|
+
if (dir !== path.join(realRoot, rel))
|
|
75
|
+
return false;
|
|
76
|
+
return (config.gateway.files?.trusted ?? []).some((entry) => path.join(realRoot, entry) === dir);
|
|
77
|
+
}
|
|
78
|
+
async function resolveAt(abs) {
|
|
79
|
+
if (!(0, config_1.filesEnabled)(config))
|
|
80
|
+
return (0, result_1.err)('disabled');
|
|
81
|
+
const where = await relUnderRoot(abs);
|
|
82
|
+
if (!where.ok)
|
|
83
|
+
return where;
|
|
84
|
+
const { realRoot, rel } = where.value;
|
|
85
|
+
const dir = await (0, fs_2.resolveDir)(root(), rel);
|
|
86
|
+
if (!dir.ok)
|
|
87
|
+
return (0, result_1.err)(UNAVAILABLE[dir.error] ?? 'internal');
|
|
88
|
+
const hold = (0, holds_1.findHold)(dir.value);
|
|
89
|
+
if (hold)
|
|
90
|
+
return (0, result_1.err)('deleting');
|
|
91
|
+
const st = await fs_1.promises.stat(dir.value).catch(() => null);
|
|
92
|
+
if (!st)
|
|
93
|
+
return (0, result_1.err)('not_found');
|
|
94
|
+
const stored = path.join(realRoot, rel);
|
|
95
|
+
return (0, result_1.ok)({
|
|
96
|
+
path: stored,
|
|
97
|
+
dir: dir.value,
|
|
98
|
+
trusted: trusted(realRoot, rel, dir.value),
|
|
99
|
+
identity: `${st.dev}:${st.ino}`,
|
|
100
|
+
location: `You are working in the folder ${rel} at ${dir.value}.`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return {
|
|
104
|
+
async parse(raw) {
|
|
105
|
+
// A trailing slash is refused in both forms, as the files API refuses it, so one folder has one spelling.
|
|
106
|
+
if (typeof raw !== 'string' || raw === '' || raw.includes('\0') || (raw.length > 1 && raw.endsWith('/')))
|
|
107
|
+
return (0, result_1.err)('invalid');
|
|
108
|
+
if (!(0, config_1.filesEnabled)(config))
|
|
109
|
+
return (0, result_1.err)('disabled');
|
|
110
|
+
if (path.isAbsolute(raw))
|
|
111
|
+
return path.normalize(raw) === raw ? resolveAt(raw) : (0, result_1.err)('invalid');
|
|
112
|
+
const rel = (0, paths_2.parseRelPath)(raw);
|
|
113
|
+
if (!rel.ok)
|
|
114
|
+
return (0, result_1.err)('invalid');
|
|
115
|
+
const realRoot = await fs_1.promises.realpath(root()).catch(() => null);
|
|
116
|
+
return resolveAt(path.join(realRoot ?? root(), rel.value));
|
|
117
|
+
},
|
|
118
|
+
async resolve(abs) {
|
|
119
|
+
if (!path.isAbsolute(abs))
|
|
120
|
+
return (0, result_1.err)('outside_root');
|
|
121
|
+
const resolved = await resolveAt(path.normalize(abs));
|
|
122
|
+
return resolved.ok || resolved.error !== 'invalid' ? resolved : (0, result_1.err)('outside_root');
|
|
123
|
+
},
|
|
124
|
+
async note(cwd) {
|
|
125
|
+
const status = await (0, read_1.readStatusSummary)(cwd.dir, logger).catch(() => null);
|
|
126
|
+
if (!status?.ok)
|
|
127
|
+
return cwd.location;
|
|
128
|
+
const s = status.value;
|
|
129
|
+
const host = s.remote ? (0, status_1.remoteHostname)(s.remote.url) : null;
|
|
130
|
+
const git = [
|
|
131
|
+
...(s.branch === null ? ['detached HEAD'] : PLAIN_BRANCH_RE.test(s.branch) ? [`branch ${s.branch}`] : []),
|
|
132
|
+
`${s.change_count} ${s.change_count === 1 ? 'change' : 'changes'}`,
|
|
133
|
+
...(host ? [`remote ${host}`] : []),
|
|
134
|
+
];
|
|
135
|
+
return `${cwd.location} Git: ${git.join(', ')}.`;
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
//# sourceMappingURL=session-cwd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-cwd.js","sourceRoot":"","sources":["../../src/files/session-cwd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,8CAuEC;AAlGD,2BAAqC;AACrC,2CAA6B;AAG7B,0CAA4C;AAC5C,4CAAkD;AAClD,sCAAgD;AAChD,0CAA+C;AAC/C,qCAA0D;AAC1D,6BAAkC;AAClC,mCAAmC;AACnC,mCAAgE;AAEhE,gGAAgG;AAChG,MAAM,eAAe,GAAG,kBAAkB,CAAC;AAE3C,MAAM,WAAW,GAA0D;IACzE,SAAS,EAAE,WAAW;IACtB,WAAW,EAAE,cAAc;IAC3B,eAAe,EAAE,iBAAiB;IAClC,iBAAiB,EAAE,mBAAmB;CACvC,CA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,EAAE;gBAClE,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;aACpC,CAAC;YACF,OAAO,GAAG,GAAG,CAAC,QAAQ,SAAS,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;QACnD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { GitCommitInfo, GitStatus, GitSummary } from './status';
|
|
2
|
+
import { FilesErrorCode, RelPath } from '../files/paths';
|
|
3
|
+
import type { Logger } from '../types';
|
|
4
|
+
import { Result } from '../utils/result';
|
|
5
|
+
export type GitErrorCode = 'not_a_git_repo'
|
|
6
|
+
/** git refuses a repository that another user owns (`safe.directory`). */
|
|
7
|
+
| 'git_unsafe_owner'
|
|
8
|
+
/** There is a `.git` that git cannot read: permissions, damage, a bad config, or a filter setup the gateway cannot make safe. */
|
|
9
|
+
| 'git_unreadable' | 'timeout'
|
|
10
|
+
/** git is not installed or not on the gateway's PATH. */
|
|
11
|
+
| 'git_unavailable' | 'git_failed';
|
|
12
|
+
export type GitError = {
|
|
13
|
+
code: GitErrorCode | FilesErrorCode;
|
|
14
|
+
};
|
|
15
|
+
export type GitResult<T> = Result<T, GitError>;
|
|
16
|
+
export declare function parseCommitInfo(stdout: string): GitCommitInfo | null;
|
|
17
|
+
/** The cheaper read for a summary or a chat's context note: an untracked folder counts once, and no last commit or operation. */
|
|
18
|
+
export declare function readStatusSummary(dir: string, logger: Logger): Promise<GitResult<GitStatus>>;
|
|
19
|
+
/** Git status of the folder `rel` names under `root`. The root itself is refused. */
|
|
20
|
+
export declare function getStatus(root: string, rel: RelPath, logger: Logger): Promise<GitResult<GitStatus>>;
|
|
21
|
+
/** Every folder directly under `rel` with a `.git`, keyed by name; null when its status timed out or failed. Others are left out. */
|
|
22
|
+
export declare function getSummaries(root: string, rel: RelPath, logger: Logger): Promise<GitResult<{
|
|
23
|
+
summaries: Record<string, GitSummary | null>;
|
|
24
|
+
}>>;
|
|
25
|
+
//# sourceMappingURL=read.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../../src/git/read.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,aAAa,EAEb,SAAS,EACT,UAAU,EAKX,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,cAAc,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAW,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,YAAY,GACpB,gBAAgB;AAClB,0EAA0E;GACxE,kBAAkB;AACpB,iIAAiI;GAC/H,gBAAgB,GAChB,SAAS;AACX,yDAAyD;GACvD,iBAAiB,GACjB,YAAY,CAAC;AAEjB,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,YAAY,GAAG,cAAc,CAAA;CAAE,CAAC;AAE/D,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;AAwB/C,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,GAAG,IAAI,CAGpE;AA8ED,iIAAiI;AACjI,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAE5F;AAED,qFAAqF;AACrF,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAGzG;AAED,qIAAqI;AACrI,wBAAsB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAAE,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC,CAAA;CAAE,CAAC,CAAC,CAYnJ"}
|
package/dist/git/read.js
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
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.parseCommitInfo = parseCommitInfo;
|
|
37
|
+
exports.readStatusSummary = readStatusSummary;
|
|
38
|
+
exports.getStatus = getStatus;
|
|
39
|
+
exports.getSummaries = getSummaries;
|
|
40
|
+
const fs_1 = require("fs");
|
|
41
|
+
const path = __importStar(require("path"));
|
|
42
|
+
const fs_2 = require("../files/fs");
|
|
43
|
+
const runner_1 = require("./runner");
|
|
44
|
+
const status_1 = require("./status");
|
|
45
|
+
const result_1 = require("../utils/result");
|
|
46
|
+
const fail = (code) => (0, result_1.err)({ code });
|
|
47
|
+
const SUMMARY_CONCURRENCY = 4;
|
|
48
|
+
const COMMIT_FORMAT = '%H%x00%s%x00%an%x00%cI';
|
|
49
|
+
/** First match wins: a rebase also leaves files a merge would. */
|
|
50
|
+
const OPERATION_MARKERS = [
|
|
51
|
+
['rebase-merge', 'rebase'],
|
|
52
|
+
['rebase-apply', 'rebase'],
|
|
53
|
+
['MERGE_HEAD', 'merge'],
|
|
54
|
+
['CHERRY_PICK_HEAD', 'cherry_pick'],
|
|
55
|
+
['REVERT_HEAD', 'revert'],
|
|
56
|
+
['BISECT_LOG', 'bisect'],
|
|
57
|
+
];
|
|
58
|
+
async function operationIn(gitDir) {
|
|
59
|
+
for (const [marker, op] of OPERATION_MARKERS) {
|
|
60
|
+
if (await fs_1.promises.lstat(path.join(gitDir, marker)).then(() => true, () => false))
|
|
61
|
+
return op;
|
|
62
|
+
}
|
|
63
|
+
return 'none';
|
|
64
|
+
}
|
|
65
|
+
function parseCommitInfo(stdout) {
|
|
66
|
+
const [sha, subject, author, committed_at] = stdout.replace(/\n$/, '').split('\0');
|
|
67
|
+
return sha && committed_at ? { sha, subject, author, committed_at } : null;
|
|
68
|
+
}
|
|
69
|
+
const DETAIL_READ = { timeoutMs: runner_1.GIT_READ_TIMEOUT_MS, untracked: 'all', commitAndOperation: true };
|
|
70
|
+
const SUMMARY_READ = { timeoutMs: runner_1.GIT_READ_TIMEOUT_MS, untracked: 'normal', commitAndOperation: false };
|
|
71
|
+
/** What git said when it could not read the repository, in words the client can act on. LC_ALL=C keeps these messages stable. */
|
|
72
|
+
async function readFailure(dir, out) {
|
|
73
|
+
if (/detected dubious ownership/.test(out.stderr))
|
|
74
|
+
return { code: 'git_unsafe_owner' };
|
|
75
|
+
if (/not a git repository/i.test(out.stderr)) {
|
|
76
|
+
// A `.git` entry git cannot open reads as "not a repository": say it is there but unreadable.
|
|
77
|
+
return { code: (await fs_1.promises.lstat(path.join(dir, '.git')).then(() => true, () => false)) ? 'git_unreadable' : 'not_a_git_repo' };
|
|
78
|
+
}
|
|
79
|
+
if (/permission denied|cannot (open|read|access)|unable to (open|read|access)|operation not permitted|bad config|invalid gitfile/i.test(out.stderr))
|
|
80
|
+
return { code: 'git_unreadable' };
|
|
81
|
+
// Git versions differ in the message for a broken gitfile. A present .git entry means the repository itself failed to open.
|
|
82
|
+
if (await fs_1.promises.lstat(path.join(dir, '.git')).then(() => true, () => false))
|
|
83
|
+
return { code: 'git_unreadable' };
|
|
84
|
+
return { code: 'git_failed' };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* The config is listed first, by git itself, so the includes, the worktree config and the scopes are git's reading and
|
|
88
|
+
* not ours. Every filter driver the repository's own config defines is then blanked for the status call, which would
|
|
89
|
+
* otherwise run a driver's clean command on any file whose stat changed. A driver that cannot be blanked safely makes
|
|
90
|
+
* the repository unreadable rather than risking the run.
|
|
91
|
+
*/
|
|
92
|
+
async function readRepo(dir, read, logger) {
|
|
93
|
+
const started = Date.now();
|
|
94
|
+
const listed = await (0, runner_1.runGit)(dir, ['config', '--list', '-z', '--show-scope'], { timeoutMs: read.timeoutMs, logger });
|
|
95
|
+
if (!listed.ok)
|
|
96
|
+
return fail(listed.error);
|
|
97
|
+
if (listed.value.code !== 0)
|
|
98
|
+
return (0, result_1.err)(await readFailure(dir, listed.value));
|
|
99
|
+
if ((0, status_1.hasUndecodableFilterKey)(listed.value.stdoutBytes))
|
|
100
|
+
return fail('git_unreadable');
|
|
101
|
+
const { config, filterKeys } = (0, status_1.parseConfigList)(listed.value.stdout);
|
|
102
|
+
if (filterKeys.length > runner_1.MAX_BLANKED_FILTER_KEYS || filterKeys.some((k) => k.length > runner_1.MAX_FILTER_KEY))
|
|
103
|
+
return fail('git_unreadable');
|
|
104
|
+
const opts = { timeoutMs: Math.max(read.timeoutMs - (Date.now() - started), 1), blankFilterKeys: filterKeys, logger };
|
|
105
|
+
const skipped = Promise.resolve((0, result_1.ok)({ code: 0, stdout: '', stdoutBytes: Buffer.alloc(0), stderr: '' }));
|
|
106
|
+
const full = read.commitAndOperation;
|
|
107
|
+
const runs = await Promise.all([
|
|
108
|
+
full ? (0, runner_1.runGit)(dir, ['rev-parse', '--absolute-git-dir'], opts) : skipped,
|
|
109
|
+
// Submodules are compared by commit only: checking their worktrees would run git, and its filters, inside each one.
|
|
110
|
+
(0, runner_1.runGit)(dir, ['status', '--porcelain=v2', '--branch', '-z', '--ignore-submodules=dirty', `--untracked-files=${read.untracked}`], opts),
|
|
111
|
+
// --no-show-signature: log.showSignature would run the repository's gpg.program.
|
|
112
|
+
full ? (0, runner_1.runGit)(dir, ['log', '-1', '-z', '--no-show-signature', `--format=${COMMIT_FORMAT}`], opts) : skipped,
|
|
113
|
+
]);
|
|
114
|
+
for (const r of runs)
|
|
115
|
+
if (!r.ok)
|
|
116
|
+
return fail(r.error);
|
|
117
|
+
const [gitDir, status, log] = runs.map((r) => (r.ok ? r.value : null));
|
|
118
|
+
if (gitDir.code !== 0)
|
|
119
|
+
return (0, result_1.err)(await readFailure(dir, gitDir));
|
|
120
|
+
if (status.code !== 0)
|
|
121
|
+
return (0, result_1.err)(await readFailure(dir, status));
|
|
122
|
+
const parsed = (0, status_1.parseStatusV2)(status.stdout);
|
|
123
|
+
if (parsed.oid === null && parsed.upstream !== null)
|
|
124
|
+
parsed.behind = await unbornBehind(dir, opts);
|
|
125
|
+
return (0, result_1.ok)((0, status_1.buildStatus)({
|
|
126
|
+
parsed,
|
|
127
|
+
config,
|
|
128
|
+
lastCommit: full && log.code === 0 ? parseCommitInfo(log.stdout) : null,
|
|
129
|
+
operation: full ? await operationIn(gitDir.stdout.trim()) : 'none',
|
|
130
|
+
}));
|
|
131
|
+
}
|
|
132
|
+
/** git prints no `branch.ab` for an unborn branch, so count what a pull would bring: every commit the tracking branch has, or 0 without one. */
|
|
133
|
+
async function unbornBehind(dir, opts) {
|
|
134
|
+
const count = await (0, runner_1.runGit)(dir, ['rev-list', '--count', '@{upstream}', '--'], opts);
|
|
135
|
+
return count.ok && count.value.code === 0 ? Number(count.value.stdout.trim()) || 0 : 0;
|
|
136
|
+
}
|
|
137
|
+
/** The detailed read: every untracked file, the last commit and any operation in progress. `dir` must be a real folder under the root. */
|
|
138
|
+
function readStatus(dir, logger) {
|
|
139
|
+
return readRepo(dir, DETAIL_READ, logger);
|
|
140
|
+
}
|
|
141
|
+
/** The cheaper read for a summary or a chat's context note: an untracked folder counts once, and no last commit or operation. */
|
|
142
|
+
function readStatusSummary(dir, logger) {
|
|
143
|
+
return readRepo(dir, SUMMARY_READ, logger);
|
|
144
|
+
}
|
|
145
|
+
/** Git status of the folder `rel` names under `root`. The root itself is refused. */
|
|
146
|
+
async function getStatus(root, rel, logger) {
|
|
147
|
+
const dir = await (0, fs_2.resolveDir)(root, rel);
|
|
148
|
+
return dir.ok ? readStatus(dir.value, logger) : fail(dir.error);
|
|
149
|
+
}
|
|
150
|
+
/** Every folder directly under `rel` with a `.git`, keyed by name; null when its status timed out or failed. Others are left out. */
|
|
151
|
+
async function getSummaries(root, rel, logger) {
|
|
152
|
+
const list = await (0, fs_2.listDir)(root, rel);
|
|
153
|
+
if (!list.ok)
|
|
154
|
+
return fail(list.error);
|
|
155
|
+
const repos = list.value.entries.filter((e) => e.is_git);
|
|
156
|
+
const reads = await (0, fs_2.mapLimit)(repos, SUMMARY_CONCURRENCY, async (e) => {
|
|
157
|
+
const dir = await (0, fs_2.resolveDir)(root, e.path);
|
|
158
|
+
return dir.ok ? readStatusSummary(dir.value, logger) : fail(dir.error);
|
|
159
|
+
});
|
|
160
|
+
const noGit = reads.find((r) => !r.ok && r.error.code === 'git_unavailable');
|
|
161
|
+
if (noGit && !noGit.ok)
|
|
162
|
+
return fail(noGit.error.code);
|
|
163
|
+
const results = reads.map((r) => (r.ok ? (0, status_1.toSummary)(r.value) : null));
|
|
164
|
+
return (0, result_1.ok)({ summaries: Object.fromEntries(repos.map((e, i) => [e.name, results[i]])) });
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=read.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read.js","sourceRoot":"","sources":["../../src/git/read.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwDA,0CAGC;AA+ED,8CAEC;AAGD,8BAGC;AAGD,oCAYC;AAjKD,2BAAqC;AACrC,2CAA6B;AAC7B,oCAA4D;AAC5D,qCAAuH;AACvH,qCAUkB;AAGlB,4CAAkD;AAiBlD,MAAM,IAAI,GAAG,CAAC,IAAmC,EAAE,EAAE,CAAC,IAAA,YAAG,EAAC,EAAE,IAAI,EAAE,CAAC,CAAC;AAEpE,MAAM,mBAAmB,GAAG,CAAC,CAAC;AAC9B,MAAM,aAAa,GAAG,wBAAwB,CAAC;AAE/C,kEAAkE;AAClE,MAAM,iBAAiB,GAAkC;IACvD,CAAC,cAAc,EAAE,QAAQ,CAAC;IAC1B,CAAC,cAAc,EAAE,QAAQ,CAAC;IAC1B,CAAC,YAAY,EAAE,OAAO,CAAC;IACvB,CAAC,kBAAkB,EAAE,aAAa,CAAC;IACnC,CAAC,aAAa,EAAE,QAAQ,CAAC;IACzB,CAAC,YAAY,EAAE,QAAQ,CAAC;CACzB,CAAC;AAEF,KAAK,UAAU,WAAW,CAAC,MAAc;IACvC,KAAK,MAAM,CAAC,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AAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Result } from '../utils/result';
|
|
2
|
+
import type { Logger } from '../types';
|
|
3
|
+
export declare const GIT_READ_TIMEOUT_MS = 3000;
|
|
4
|
+
export interface GitOutput {
|
|
5
|
+
/** Exit code; a non-zero exit is data for the caller to classify, not a failure here. */
|
|
6
|
+
code: number;
|
|
7
|
+
stdout: string;
|
|
8
|
+
/** The bytes behind `stdout`, for output whose text is not guaranteed to be UTF-8. */
|
|
9
|
+
stdoutBytes: Buffer;
|
|
10
|
+
stderr: string;
|
|
11
|
+
}
|
|
12
|
+
export type GitRunFailure = 'timeout' | 'git_failed' | 'git_unavailable';
|
|
13
|
+
/**
|
|
14
|
+
* The environment git runs with: an allowlist of process.env, and no GIT_DIR/GIT_WORK_TREE that would aim git at
|
|
15
|
+
* another repository. Built from process.env explicitly: jest gives tests a copy that child_process ignores.
|
|
16
|
+
*
|
|
17
|
+
* `GIT_ALLOW_PROTOCOL` set empty allows no transport at all, and unlike `protocol.<name>.allow` in the repository's
|
|
18
|
+
* config it cannot be overridden by the repository. Git can start a fetch on its own during a read, to fetch a missing
|
|
19
|
+
* object of a partial clone, so this is what keeps a repository's `core.sshCommand`, `uploadpack`, `ext::` URL or
|
|
20
|
+
* credential helper from ever running. `GIT_NO_LAZY_FETCH` (git 2.44 and later) stops that fetch from being tried.
|
|
21
|
+
*/
|
|
22
|
+
export declare function gitEnv(): NodeJS.ProcessEnv;
|
|
23
|
+
/** `filter.*` keys a status read may blank; more than this, or a longer key, and the repository is refused. */
|
|
24
|
+
export declare const MAX_BLANKED_FILTER_KEYS = 64;
|
|
25
|
+
export declare const MAX_FILTER_KEY = 1024;
|
|
26
|
+
/**
|
|
27
|
+
* The command line and environment every git call of the gateway uses, reads and `git init` alike. `core.fsmonitor`
|
|
28
|
+
* is a command from the repository's config, so it is turned off for every call. A call that can run a clean filter
|
|
29
|
+
* (status) names the repository's `filter.*` keys in `blankFilterKeys` so no driver runs.
|
|
30
|
+
*/
|
|
31
|
+
export declare function hardenedGit(cwd: string, args: string[], blankFilterKeys?: readonly string[]): {
|
|
32
|
+
argv: string[];
|
|
33
|
+
env: NodeJS.ProcessEnv;
|
|
34
|
+
};
|
|
35
|
+
export interface RunOptions {
|
|
36
|
+
timeoutMs: number;
|
|
37
|
+
logger: Logger;
|
|
38
|
+
/** The repository's own `filter.*` keys, to blank for this call. */
|
|
39
|
+
blankFilterKeys?: readonly string[];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Runs git in the folder `cwd`. Discovery stops at `cwd`, so a folder inside some
|
|
43
|
+
* other repository never reads as a repo itself.
|
|
44
|
+
*/
|
|
45
|
+
export declare function runGit(cwd: string, args: string[], opts: RunOptions): Promise<Result<GitOutput, GitRunFailure>>;
|
|
46
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/git/runner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAElD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,eAAO,MAAM,mBAAmB,OAAQ,CAAC;AAIzC,MAAM,WAAW,SAAS;IACxB,yFAAyF;IACzF,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,sFAAsF;IACtF,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,YAAY,GAAG,iBAAiB,CAAC;AAYzE;;;;;;;;GAQG;AACH,wBAAgB,MAAM,IAAI,MAAM,C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