@agent-watch-ai/edge 0.2.5 → 0.3.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/CHANGELOG.md +512 -0
- package/README.md +217 -96
- package/SECURITY.md +69 -0
- package/dist/billing/session-billing.d.ts +19 -0
- package/dist/billing/session-billing.js +52 -0
- package/dist/cli/args.d.ts +10 -0
- package/dist/cli/args.js +20 -0
- package/dist/cli/constants/cli.constants.d.ts +50 -4
- package/dist/cli/constants/cli.constants.js +54 -5
- package/dist/cli/context.d.ts +33 -2
- package/dist/cli/context.js +84 -14
- package/dist/cli/doctor.js +309 -32
- package/dist/cli/hook-check.d.ts +23 -0
- package/dist/cli/hook-check.js +114 -0
- package/dist/cli/hook.js +118 -7
- package/dist/cli/index.d.ts +3 -1
- package/dist/cli/index.js +3 -1
- package/dist/cli/misc.d.ts +11 -0
- package/dist/cli/misc.js +80 -4
- package/dist/cli/npx-install.d.ts +37 -0
- package/dist/cli/npx-install.js +79 -0
- package/dist/cli/open-browser.d.ts +39 -0
- package/dist/cli/open-browser.js +62 -0
- package/dist/cli/setup.d.ts +17 -8
- package/dist/cli/setup.js +439 -98
- package/dist/cli/status.js +82 -13
- package/dist/cli/toggle.d.ts +9 -0
- package/dist/cli/toggle.js +113 -0
- package/dist/cli/types/cli.types.d.ts +37 -3
- package/dist/cli/ui.d.ts +7 -0
- package/dist/cli/ui.js +10 -1
- package/dist/cli/uninstall.js +39 -2
- package/dist/cli/update.d.ts +17 -0
- package/dist/cli/update.js +76 -0
- package/dist/cli.js +100 -13
- package/dist/config/config-store.d.ts +57 -0
- package/dist/config/config-store.js +250 -12
- package/dist/config/config.d.ts +53 -6
- package/dist/config/config.js +66 -6
- package/dist/config/constants/config.constants.d.ts +113 -6
- package/dist/config/constants/config.constants.js +126 -8
- package/dist/config/destination.d.ts +24 -0
- package/dist/config/destination.js +33 -0
- package/dist/config/index.d.ts +7 -4
- package/dist/config/index.js +5 -3
- package/dist/config/repo-config.d.ts +11 -7
- package/dist/config/repo-config.js +64 -15
- package/dist/config/root-config.d.ts +72 -0
- package/dist/config/root-config.js +170 -0
- package/dist/config/schemas/config.schema.d.ts +721 -84
- package/dist/config/schemas/config.schema.js +388 -15
- package/dist/config/types/config.types.d.ts +15 -1
- package/dist/config/types/destination.types.d.ts +8 -0
- package/dist/core/async.d.ts +36 -0
- package/dist/core/async.js +68 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/object.d.ts +5 -0
- package/dist/core/object.js +9 -4
- package/dist/core/pipe.d.ts +0 -13
- package/dist/core/pipe.js +1 -9
- package/dist/core/types/core.types.d.ts +9 -0
- package/dist/core/types/core.types.js +0 -3
- package/dist/core/which.d.ts +14 -0
- package/dist/core/which.js +43 -3
- package/dist/credentials/budget.d.ts +9 -0
- package/dist/credentials/budget.js +16 -0
- package/dist/credentials/command-runner.d.ts +16 -0
- package/dist/credentials/command-runner.js +37 -0
- package/dist/credentials/constants/credentials.constants.d.ts +111 -0
- package/dist/credentials/constants/credentials.constants.js +112 -0
- package/dist/credentials/credential-status.d.ts +14 -0
- package/dist/credentials/credential-status.js +34 -0
- package/dist/credentials/credentials.d.ts +72 -0
- package/dist/credentials/credentials.js +253 -0
- package/dist/credentials/device-api.d.ts +64 -0
- package/dist/credentials/device-api.js +150 -0
- package/dist/credentials/device-state.d.ts +31 -0
- package/dist/credentials/device-state.js +51 -0
- package/dist/credentials/identity.d.ts +62 -0
- package/dist/credentials/identity.js +90 -0
- package/dist/credentials/index.d.ts +7 -0
- package/dist/credentials/index.js +5 -0
- package/dist/credentials/migration.d.ts +46 -0
- package/dist/credentials/migration.js +164 -0
- package/dist/credentials/schemas/device-api.schema.d.ts +77 -0
- package/dist/credentials/schemas/device-api.schema.js +33 -0
- package/dist/credentials/schemas/device-state.schema.d.ts +51 -0
- package/dist/credentials/schemas/device-state.schema.js +20 -0
- package/dist/credentials/secret-store.d.ts +54 -0
- package/dist/credentials/secret-store.js +217 -0
- package/dist/credentials/sign-in.d.ts +18 -0
- package/dist/credentials/sign-in.js +86 -0
- package/dist/credentials/token-refresher.d.ts +39 -0
- package/dist/credentials/token-refresher.js +185 -0
- package/dist/credentials/types/credentials.types.d.ts +195 -0
- package/dist/credentials/types/credentials.types.js +1 -0
- package/dist/enforcement/constants/enforcement.constants.d.ts +47 -1
- package/dist/enforcement/constants/enforcement.constants.js +56 -0
- package/dist/enforcement/decision-cache.d.ts +20 -1
- package/dist/enforcement/decision-cache.js +65 -2
- package/dist/enforcement/decision-client.d.ts +9 -8
- package/dist/enforcement/decision-client.js +62 -16
- package/dist/enforcement/enforcement.d.ts +23 -2
- package/dist/enforcement/enforcement.js +103 -15
- package/dist/enforcement/index.d.ts +4 -3
- package/dist/enforcement/index.js +3 -2
- package/dist/enforcement/types/enforcement.types.d.ts +64 -0
- package/dist/enrollment/constants/enrollment.constants.d.ts +2 -6
- package/dist/enrollment/constants/enrollment.constants.js +2 -6
- package/dist/enrollment/enrollment.d.ts +16 -0
- package/dist/enrollment/enrollment.js +54 -0
- package/dist/enrollment/index.d.ts +3 -7
- package/dist/enrollment/index.js +1 -1
- package/dist/enrollment/types/enrollment.types.d.ts +9 -13
- package/dist/events/constants/enrich.constants.d.ts +15 -0
- package/dist/events/constants/enrich.constants.js +15 -0
- package/dist/events/constants/events.constants.d.ts +6 -2
- package/dist/events/constants/events.constants.js +5 -1
- package/dist/events/enrich.js +92 -10
- package/dist/events/event-id.d.ts +0 -8
- package/dist/events/event-id.js +0 -10
- package/dist/events/index.d.ts +2 -2
- package/dist/events/index.js +1 -1
- package/dist/events/product-event.d.ts +9 -6
- package/dist/events/types/repo-snapshot.types.d.ts +7 -0
- package/dist/events/types/session-billing.types.d.ts +16 -0
- package/dist/events/types/session-billing.types.js +1 -0
- package/dist/feature/constants/feature.constants.d.ts +7 -0
- package/dist/feature/constants/feature.constants.js +7 -0
- package/dist/feature/index.d.ts +1 -1
- package/dist/feature/index.js +1 -1
- package/dist/feature/ticket-candidates.d.ts +14 -0
- package/dist/feature/ticket-candidates.js +26 -8
- package/dist/git/blob-hash.d.ts +21 -0
- package/dist/git/blob-hash.js +69 -0
- package/dist/git/checkout-root.d.ts +27 -0
- package/dist/git/checkout-root.js +75 -0
- package/dist/git/constants/git.constants.d.ts +160 -0
- package/dist/git/constants/git.constants.js +181 -0
- package/dist/git/fingerprint.d.ts +74 -0
- package/dist/git/fingerprint.js +219 -0
- package/dist/git/gate-checkout.d.ts +44 -0
- package/dist/git/gate-checkout.js +201 -0
- package/dist/git/git-context.d.ts +45 -0
- package/dist/git/git-context.js +61 -3
- package/dist/git/index.d.ts +4 -2
- package/dist/git/index.js +2 -1
- package/dist/git/manifest-repository.d.ts +13 -0
- package/dist/git/manifest-repository.js +92 -0
- package/dist/git/repo-snapshot.d.ts +29 -3
- package/dist/git/repo-snapshot.js +110 -7
- package/dist/git/repository-root.d.ts +39 -0
- package/dist/git/repository-root.js +131 -0
- package/dist/git/types/git.types.d.ts +55 -0
- package/dist/git/types/repository-root.types.d.ts +11 -0
- package/dist/git/types/repository-root.types.js +1 -0
- package/dist/git/types/snapshot.types.d.ts +9 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +7 -0
- package/dist/pipeline/constants/pipeline.constants.js +7 -0
- package/dist/pipeline/hook-pipeline.js +360 -32
- package/dist/pipeline/types/pipeline.types.d.ts +39 -4
- package/dist/privacy/constants/privacy.constants.js +15 -1
- package/dist/privacy/index.d.ts +1 -0
- package/dist/privacy/index.js +1 -0
- package/dist/privacy/product-capture.d.ts +12 -0
- package/dist/privacy/product-capture.js +73 -0
- package/dist/privacy/sanitizer.d.ts +21 -3
- package/dist/privacy/sanitizer.js +52 -8
- package/dist/process/ancestors.d.ts +39 -0
- package/dist/process/ancestors.js +121 -0
- package/dist/process/constants/process.constants.d.ts +34 -0
- package/dist/process/constants/process.constants.js +34 -0
- package/dist/process/index.d.ts +7 -0
- package/dist/process/index.js +2 -0
- package/dist/process/types/process.types.d.ts +23 -0
- package/dist/process/types/process.types.js +1 -0
- package/dist/providers/antigravity/antigravity.adapter.d.ts +12 -1
- package/dist/providers/antigravity/antigravity.adapter.js +21 -3
- package/dist/providers/antigravity/antigravity.detect.d.ts +0 -9
- package/dist/providers/antigravity/antigravity.detect.js +1 -1
- package/dist/providers/antigravity/antigravity.provider.js +3 -2
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +2 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +2 -0
- package/dist/providers/claude/claude.adapter.d.ts +11 -1
- package/dist/providers/claude/claude.adapter.js +26 -5
- package/dist/providers/claude/claude.otel.d.ts +32 -18
- package/dist/providers/claude/claude.otel.js +81 -6
- package/dist/providers/claude/claude.provider.js +5 -2
- package/dist/providers/claude/constants/claude.constants.d.ts +2 -0
- package/dist/providers/claude/constants/claude.constants.js +2 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +4 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +8 -0
- package/dist/providers/codex/codex.adapter.d.ts +15 -1
- package/dist/providers/codex/codex.adapter.js +29 -5
- package/dist/providers/codex/codex.otel.d.ts +24 -2
- package/dist/providers/codex/codex.otel.js +147 -30
- package/dist/providers/codex/codex.provider.js +5 -2
- package/dist/providers/codex/constants/codex.constants.d.ts +2 -0
- package/dist/providers/codex/constants/codex.constants.js +16 -0
- package/dist/providers/codex/constants/codex.otel.constants.d.ts +5 -0
- package/dist/providers/codex/constants/codex.otel.constants.js +5 -0
- package/dist/providers/constants/provider.constants.d.ts +0 -3
- package/dist/providers/constants/provider.constants.js +0 -3
- package/dist/providers/cursor/constants/cursor.constants.d.ts +7 -0
- package/dist/providers/cursor/constants/cursor.constants.js +7 -0
- package/dist/providers/cursor/cursor.adapter.d.ts +33 -1
- package/dist/providers/cursor/cursor.adapter.js +52 -3
- package/dist/providers/cursor/cursor.detect.d.ts +0 -7
- package/dist/providers/cursor/cursor.detect.js +1 -1
- package/dist/providers/cursor/cursor.provider.js +5 -2
- package/dist/providers/gemini/constants/gemini.constants.d.ts +9 -0
- package/dist/providers/gemini/constants/gemini.constants.js +9 -0
- package/dist/providers/gemini/constants/gemini.otel.constants.d.ts +3 -1
- package/dist/providers/gemini/constants/gemini.otel.constants.js +3 -0
- package/dist/providers/gemini/gemini.adapter.d.ts +14 -1
- package/dist/providers/gemini/gemini.adapter.js +25 -5
- package/dist/providers/gemini/gemini.detect.d.ts +0 -7
- package/dist/providers/gemini/gemini.detect.js +1 -1
- package/dist/providers/gemini/gemini.otel.d.ts +19 -20
- package/dist/providers/gemini/gemini.otel.js +121 -17
- package/dist/providers/gemini/gemini.provider.js +2 -1
- package/dist/providers/index.d.ts +1 -1
- package/dist/providers/index.js +1 -1
- package/dist/providers/loaders.d.ts +10 -0
- package/dist/providers/loaders.js +40 -0
- package/dist/providers/provider.d.ts +11 -0
- package/dist/providers/provider.js +1 -1
- package/dist/providers/registry.d.ts +11 -8
- package/dist/providers/registry.js +11 -15
- package/dist/providers/shared/constants/hook-refusal.constants.d.ts +7 -0
- package/dist/providers/shared/constants/hook-refusal.constants.js +7 -0
- package/dist/providers/shared/constants/shell-directories.constants.d.ts +30 -0
- package/dist/providers/shared/constants/shell-directories.constants.js +39 -0
- package/dist/providers/shared/constants/tooling.constants.d.ts +18 -2
- package/dist/providers/shared/constants/tooling.constants.js +19 -3
- package/dist/providers/shared/event-builder.d.ts +12 -14
- package/dist/providers/shared/event-builder.js +20 -14
- package/dist/providers/shared/exporter-allowlist.d.ts +20 -0
- package/dist/providers/shared/exporter-allowlist.js +49 -0
- package/dist/providers/shared/hook-config.d.ts +2 -21
- package/dist/providers/shared/hook-config.js +5 -4
- package/dist/providers/shared/hook-refusal.d.ts +12 -0
- package/dist/providers/shared/hook-refusal.js +17 -1
- package/dist/providers/shared/install-record.d.ts +12 -2
- package/dist/providers/shared/install-record.js +5 -2
- package/dist/providers/shared/shell-directories.d.ts +24 -0
- package/dist/providers/shared/shell-directories.js +90 -0
- package/dist/providers/shared/tooling.d.ts +12 -1
- package/dist/providers/shared/tooling.js +18 -0
- package/dist/providers/shared/types/adapter.types.d.ts +1 -2
- package/dist/providers/types/provider.types.d.ts +57 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +32 -0
- package/dist/snapshot/constants/snapshot.constants.js +33 -0
- package/dist/snapshot/snapshot-event.js +52 -11
- package/dist/snapshot/snapshot-pipeline.js +1 -1
- package/dist/snapshot/types/snapshot.types.d.ts +2 -0
- package/dist/storage/atomic-file.d.ts +7 -0
- package/dist/storage/atomic-file.js +1 -1
- package/dist/storage/constants/storage.constants.d.ts +17 -0
- package/dist/storage/constants/storage.constants.js +17 -0
- package/dist/storage/disabled.d.ts +13 -0
- package/dist/storage/disabled.js +24 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +2 -0
- package/dist/storage/paths.js +3 -2
- package/dist/storage/schemas/storage.schema.d.ts +72 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/storage/sweep-marker.d.ts +19 -0
- package/dist/storage/sweep-marker.js +55 -0
- package/dist/storage/types/storage.types.d.ts +2 -0
- package/dist/storage/uninstalled.d.ts +58 -0
- package/dist/storage/uninstalled.js +107 -0
- package/dist/transport/auth-block.d.ts +66 -0
- package/dist/transport/auth-block.js +129 -0
- package/dist/transport/constants/transport.constants.d.ts +82 -3
- package/dist/transport/constants/transport.constants.js +83 -4
- package/dist/transport/cooldown.js +8 -1
- package/dist/transport/delivery.d.ts +14 -6
- package/dist/transport/delivery.js +80 -55
- package/dist/transport/http-transport.d.ts +1 -0
- package/dist/transport/http-transport.js +52 -10
- package/dist/transport/index.d.ts +6 -3
- package/dist/transport/index.js +3 -0
- package/dist/transport/queue-partition.d.ts +91 -0
- package/dist/transport/queue-partition.js +143 -0
- package/dist/transport/queue.d.ts +99 -20
- package/dist/transport/queue.js +210 -69
- package/dist/transport/response-body.d.ts +25 -0
- package/dist/transport/response-body.js +64 -0
- package/dist/transport/send.d.ts +11 -0
- package/dist/transport/send.js +17 -0
- package/dist/transport/types/delivery-flow.types.d.ts +19 -0
- package/dist/transport/types/delivery-flow.types.js +1 -0
- package/dist/transport/types/transport.types.d.ts +45 -0
- package/dist/turns/claude-transcript.d.ts +19 -1
- package/dist/turns/claude-transcript.js +46 -1
- package/dist/turns/codex-originator.d.ts +11 -0
- package/dist/turns/codex-originator.js +31 -0
- package/dist/turns/codex-transcript.d.ts +30 -0
- package/dist/turns/codex-transcript.js +88 -0
- package/dist/turns/constants/turns.constants.d.ts +141 -5
- package/dist/turns/constants/turns.constants.js +155 -5
- package/dist/turns/file-identity.d.ts +27 -0
- package/dist/turns/file-identity.js +48 -0
- package/dist/turns/gemini-transcript.d.ts +30 -0
- package/dist/turns/gemini-transcript.js +96 -0
- package/dist/turns/index.d.ts +3 -3
- package/dist/turns/index.js +1 -1
- package/dist/turns/inherited-checkout.d.ts +54 -0
- package/dist/turns/inherited-checkout.js +155 -0
- package/dist/turns/native-session-titles.d.ts +26 -0
- package/dist/turns/native-session-titles.js +102 -0
- package/dist/turns/transcript.d.ts +3 -2
- package/dist/turns/transcript.js +5 -1
- package/dist/turns/turn-state.d.ts +224 -3
- package/dist/turns/turn-state.js +456 -21
- package/dist/turns/turn-summary.d.ts +1 -14
- package/dist/turns/turn-summary.js +87 -51
- package/dist/turns/turn-tracker.d.ts +21 -2
- package/dist/turns/turn-tracker.js +379 -56
- package/dist/turns/types/transcript.types.d.ts +5 -0
- package/dist/turns/types/turn-state.types.d.ts +116 -5
- package/dist/turns/types/turn-summary.types.d.ts +64 -14
- package/dist/turns/types/turn-tracker.types.d.ts +27 -1
- package/dist/turns/work-checkout.d.ts +65 -0
- package/dist/turns/work-checkout.js +666 -0
- package/dist/untraced/constants/untraced.constants.d.ts +31 -0
- package/dist/untraced/constants/untraced.constants.js +63 -0
- package/dist/untraced/untraced.d.ts +35 -0
- package/dist/untraced/untraced.js +105 -0
- package/dist/update/constants/update.constants.d.ts +18 -0
- package/dist/update/constants/update.constants.js +20 -0
- package/dist/update/update-check.d.ts +52 -0
- package/dist/update/update-check.js +113 -0
- package/docs/AUDIT_PROMPT.md +129 -0
- package/docs/DATA_HANDLING.md +648 -0
- package/docs/ENTERPRISE_DEPLOYMENT.md +179 -0
- package/docs/PERFORMANCE.md +81 -0
- package/package.json +14 -4
- package/dist/enrollment/enrollment-provider.d.ts +0 -5
- package/dist/enrollment/manual-enrollment.d.ts +0 -32
- package/dist/enrollment/manual-enrollment.js +0 -72
- package/example/README.md +0 -43
- package/example/server.mjs +0 -240
- /package/dist/{enrollment/enrollment-provider.js → config/types/destination.types.js} +0 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { normalizeRemote } from './remote-sanitize.js';
|
|
4
|
+
const MANIFESTS = [
|
|
5
|
+
['package.json', fromPackageJson],
|
|
6
|
+
['composer.json', fromComposerJson],
|
|
7
|
+
['go.mod', fromGoMod],
|
|
8
|
+
['Cargo.toml', fromCargoToml],
|
|
9
|
+
['pyproject.toml', fromPyproject]
|
|
10
|
+
];
|
|
11
|
+
/** Hosts whose `owner/repo` shorthand npm understands. */
|
|
12
|
+
const SHORTHAND_HOSTS = { github: 'github.com', gitlab: 'gitlab.com', bitbucket: 'bitbucket.org' };
|
|
13
|
+
/**
|
|
14
|
+
* The repository address named by the nearest project manifest at or above a folder.
|
|
15
|
+
*
|
|
16
|
+
* Reads only the address field of each manifest; nothing else from it is kept.
|
|
17
|
+
* ponytail: the TOML files are scanned line by line, not parsed: enough for the
|
|
18
|
+
* one `key = "string"` we want, wrong for multi-line or inline-table forms,
|
|
19
|
+
* which yield nothing rather than a guess. Upgrade path: a TOML parser.
|
|
20
|
+
*
|
|
21
|
+
* @param start - Folder to start from.
|
|
22
|
+
* @param home - The user's home; the walk stops before it (or at the filesystem root).
|
|
23
|
+
* @returns The address as `host/owner/repo`, or undefined.
|
|
24
|
+
*/
|
|
25
|
+
export async function manifestRepository(start, home) {
|
|
26
|
+
// Canonical, so a home spelled /var/... still stops a walk that runs through /private/var/....
|
|
27
|
+
const [from, stop] = await Promise.all([canonical(start), home === undefined ? undefined : canonical(home)]);
|
|
28
|
+
for (let dir = from; dir !== stop; dir = path.dirname(dir)) {
|
|
29
|
+
for (const [name, parse] of MANIFESTS) {
|
|
30
|
+
const text = await fs.readFile(path.join(dir, name), 'utf8').catch(() => undefined);
|
|
31
|
+
const address = text === undefined ? undefined : cleaned(parse, text);
|
|
32
|
+
if (address)
|
|
33
|
+
return address;
|
|
34
|
+
}
|
|
35
|
+
if (path.dirname(dir) === dir)
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
async function canonical(dir) {
|
|
41
|
+
return fs.realpath(dir).catch(() => dir);
|
|
42
|
+
}
|
|
43
|
+
function cleaned(parse, text) {
|
|
44
|
+
try {
|
|
45
|
+
const raw = parse(text)?.trim().replace(/^git\+/, '');
|
|
46
|
+
return raw ? normalizeRemote(raw) : undefined;
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function fromPackageJson(text) {
|
|
53
|
+
const repository = JSON.parse(text).repository;
|
|
54
|
+
const value = typeof repository === 'string' ? repository : repository?.url;
|
|
55
|
+
if (typeof value !== 'string')
|
|
56
|
+
return undefined;
|
|
57
|
+
const shorthand = /^(?:(github|gitlab|bitbucket):)?(\w[\w.-]*\/[\w.-]+)$/.exec(value);
|
|
58
|
+
return shorthand ? `https://${SHORTHAND_HOSTS[shorthand[1] ?? 'github']}/${shorthand[2]}` : value;
|
|
59
|
+
}
|
|
60
|
+
function fromComposerJson(text) {
|
|
61
|
+
const source = JSON.parse(text).support?.source;
|
|
62
|
+
return typeof source === 'string' ? source : undefined;
|
|
63
|
+
}
|
|
64
|
+
function fromGoMod(text) {
|
|
65
|
+
const module = /^module\s+(\S+)/m.exec(text)?.[1];
|
|
66
|
+
const [host, owner, repo] = module?.split('/') ?? [];
|
|
67
|
+
return host?.includes('.') && owner && repo ? `https://${host}/${owner}/${repo}` : undefined;
|
|
68
|
+
}
|
|
69
|
+
function fromCargoToml(text) {
|
|
70
|
+
return tomlValue(text, ['package'], ['repository']);
|
|
71
|
+
}
|
|
72
|
+
function fromPyproject(text) {
|
|
73
|
+
return (tomlValue(text, ['project.urls'], ['repository', 'source', 'source code', 'sourcecode', 'github', 'code'])
|
|
74
|
+
?? tomlValue(text, ['tool.poetry'], ['repository']));
|
|
75
|
+
}
|
|
76
|
+
/** The first `key = "value"` under one of the sections, key matched case-insensitively. */
|
|
77
|
+
function tomlValue(text, sections, keys) {
|
|
78
|
+
let section = '';
|
|
79
|
+
for (const line of text.split(/\r?\n/)) {
|
|
80
|
+
const header = /^\s*\[([^\]]+)\]\s*$/.exec(line);
|
|
81
|
+
if (header) {
|
|
82
|
+
section = header[1].trim();
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!sections.includes(section))
|
|
86
|
+
continue;
|
|
87
|
+
const pair = /^\s*"?([\w .-]+?)"?\s*=\s*"([^"]*)"/.exec(line);
|
|
88
|
+
if (pair && keys.includes(pair[1].toLowerCase()))
|
|
89
|
+
return pair[2];
|
|
90
|
+
}
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { GitRunner } from './types/git.types.js';
|
|
2
|
-
import type { BranchCommit, BranchRef, CollectCommitsOptions, CollectRefsOptions } from './types/snapshot.types.js';
|
|
3
|
-
export type { BranchCommit, BranchRef, SnapshotBranch } from './types/snapshot.types.js';
|
|
2
|
+
import type { BranchCommit, BranchRef, CollectCommitsOptions, CollectRefsOptions, CommitFile } from './types/snapshot.types.js';
|
|
3
|
+
export type { BranchCommit, BranchRef, CommitFile, SnapshotBranch } from './types/snapshot.types.js';
|
|
4
4
|
/**
|
|
5
5
|
* The recently committed branches and their heads, in one git process.
|
|
6
6
|
*
|
|
@@ -28,7 +28,14 @@ export declare function collectBranchRefs(options: CollectRefsOptions, run: GitR
|
|
|
28
28
|
*/
|
|
29
29
|
export declare function resolveDefaultBranch(cwd: string, run: GitRunner): Promise<string | undefined>;
|
|
30
30
|
/**
|
|
31
|
-
* The commits one branch has that its default branch does not
|
|
31
|
+
* The commits one branch has that its default branch does not, as the remote
|
|
32
|
+
* knows it (`origin/<default>`) and as the clone has it when there is none,
|
|
33
|
+
* each with the files it changed.
|
|
34
|
+
*
|
|
35
|
+
* The files are a second process over the same range, not flags on the first:
|
|
36
|
+
* one commit that rewrote ten thousand files would overrun the output ceiling,
|
|
37
|
+
* and taken together that would cost the branch the subjects of every commit
|
|
38
|
+
* older than it. Apart, the worst a huge commit does is lose some paths.
|
|
32
39
|
*
|
|
33
40
|
* @param branch - Branch to describe.
|
|
34
41
|
* @param options - Where to look, the base branch and the commit cap.
|
|
@@ -38,3 +45,22 @@ export declare function resolveDefaultBranch(cwd: string, run: GitRunner): Promi
|
|
|
38
45
|
* trunk's commits as this branch's work.
|
|
39
46
|
*/
|
|
40
47
|
export declare function collectBranchCommits(branch: string, options: CollectCommitsOptions, run: GitRunner): Promise<BranchCommit[]>;
|
|
48
|
+
/**
|
|
49
|
+
* The files of each commit in one `log -z --name-status --format=%H` listing.
|
|
50
|
+
*
|
|
51
|
+
* Read as NUL-separated tokens, never by splitting on anything a path can hold:
|
|
52
|
+
* with `-z` git prints a name raw, newlines and all, and NUL is the one byte no
|
|
53
|
+
* path contains. A commit is its sha; after it come `<letter>` `<path>` pairs,
|
|
54
|
+
* the first letter prefixed by a newline. A letter is always followed by
|
|
55
|
+
* exactly one path, so a path that looks like a sha or a letter is still a path.
|
|
56
|
+
*
|
|
57
|
+
* A listing the runner salvaged after the output ceiling was cut at its last
|
|
58
|
+
* newline. Cut inside a path, it no longer ends on NUL, and its last commit is
|
|
59
|
+
* left out; cut after a header, it ends on a commit with no files, which is left
|
|
60
|
+
* out too — unknown, not empty — at the price of an oldest commit that really
|
|
61
|
+
* changed nothing.
|
|
62
|
+
*
|
|
63
|
+
* @param output - The listing.
|
|
64
|
+
* @returns Files by commit sha, in git's order.
|
|
65
|
+
*/
|
|
66
|
+
export declare function parseCommitFiles(output: string): Map<string, CommitFile[]>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASSUMED_DEFAULT_BRANCHES, GIT_FIELD_SEPARATOR, GIT_ORIGIN_HEAD_ARGS, GIT_TIMEOUT_MS, gitBranchDeltaArgs, gitRecentBranchesArgs, gitVerifyRefArgs } from './constants/git.constants.js';
|
|
1
|
+
import { ASSUMED_DEFAULT_BRANCHES, GIT_FIELD_SEPARATOR, GIT_ORIGIN_HEAD_ARGS, GIT_TIMEOUT_MS, RE_LEADING_NEWLINE, RE_NAME_STATUS, RE_OBJECT_ID, gitBranchDeltaArgs, gitBranchFilesArgs, gitRecentBranchesArgs, gitVerifyRefArgs } from './constants/git.constants.js';
|
|
2
2
|
/** `origin/HEAD` is reported as `origin/main`; the branch is what comes after. */
|
|
3
3
|
const REMOTE_PREFIX = 'origin/';
|
|
4
4
|
/**
|
|
@@ -45,7 +45,14 @@ export async function resolveDefaultBranch(cwd, run) {
|
|
|
45
45
|
return undefined;
|
|
46
46
|
}
|
|
47
47
|
/**
|
|
48
|
-
* The commits one branch has that its default branch does not
|
|
48
|
+
* The commits one branch has that its default branch does not, as the remote
|
|
49
|
+
* knows it (`origin/<default>`) and as the clone has it when there is none,
|
|
50
|
+
* each with the files it changed.
|
|
51
|
+
*
|
|
52
|
+
* The files are a second process over the same range, not flags on the first:
|
|
53
|
+
* one commit that rewrote ten thousand files would overrun the output ceiling,
|
|
54
|
+
* and taken together that would cost the branch the subjects of every commit
|
|
55
|
+
* older than it. Apart, the worst a huge commit does is lose some paths.
|
|
49
56
|
*
|
|
50
57
|
* @param branch - Branch to describe.
|
|
51
58
|
* @param options - Where to look, the base branch and the commit cap.
|
|
@@ -55,15 +62,111 @@ export async function resolveDefaultBranch(cwd, run) {
|
|
|
55
62
|
* trunk's commits as this branch's work.
|
|
56
63
|
*/
|
|
57
64
|
export async function collectBranchCommits(branch, options, run) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const output = await run(gitBranchDeltaArgs(options.defaultBranch, branch, options.commitCount), options.cwd, GIT_TIMEOUT_MS);
|
|
61
|
-
if (!output)
|
|
65
|
+
const delta = await branchDelta(branch, options, run);
|
|
66
|
+
if (!delta?.output)
|
|
62
67
|
return [];
|
|
63
|
-
|
|
68
|
+
const commits = delta.output
|
|
64
69
|
.split('\n')
|
|
65
70
|
.map((line) => parseCommit(line))
|
|
66
71
|
.filter((commit) => commit !== undefined);
|
|
72
|
+
if (commits.length === 0 || options.withFiles === false)
|
|
73
|
+
return commits;
|
|
74
|
+
const listing = await run(gitBranchFilesArgs(delta.base, branch, options.commitCount), options.cwd, GIT_TIMEOUT_MS);
|
|
75
|
+
// A listing that failed or ran out of budget leaves every commit without
|
|
76
|
+
// files, which is what an edge from before files existed sent.
|
|
77
|
+
const files = listing === undefined ? undefined : parseCommitFiles(listing);
|
|
78
|
+
// A sha missing from the listing was cut off by the output ceiling: no
|
|
79
|
+
// files, rather than a claim that it changed none.
|
|
80
|
+
return commits.map((commit) => {
|
|
81
|
+
const changed = files?.get(commit.sha);
|
|
82
|
+
return changed ? { ...commit, files: changed } : commit;
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* The delta's log output and the base it was taken against.
|
|
87
|
+
*
|
|
88
|
+
* @param branch - Branch to describe.
|
|
89
|
+
* @param options - Where to look, the base branch and the commit cap.
|
|
90
|
+
* @param run - Git runner.
|
|
91
|
+
* @returns The output and its base, or undefined when there is no base or git failed.
|
|
92
|
+
*/
|
|
93
|
+
async function branchDelta(branch, options, run) {
|
|
94
|
+
if (!options.defaultBranch || options.defaultBranch === branch)
|
|
95
|
+
return undefined;
|
|
96
|
+
// The remote-tracking trunk first: a local `main` nobody pulled is behind it,
|
|
97
|
+
// and the trunk commits between the two would read as this branch's work.
|
|
98
|
+
const remoteBase = `${REMOTE_PREFIX}${options.defaultBranch}`;
|
|
99
|
+
const remote = await run(gitBranchDeltaArgs(remoteBase, branch, options.commitCount), options.cwd, GIT_TIMEOUT_MS);
|
|
100
|
+
if (remote !== undefined)
|
|
101
|
+
return { base: remoteBase, output: remote };
|
|
102
|
+
const local = await localDelta(remoteBase, branch, options, run);
|
|
103
|
+
return local === undefined ? undefined : { base: options.defaultBranch, output: local };
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The local-trunk delta, taken only when `origin/<default>` is absent.
|
|
107
|
+
*
|
|
108
|
+
* A failed `log` against a remote ref that exists (a timeout) must not retry
|
|
109
|
+
* against the possibly stale local trunk, which would bring its commits back.
|
|
110
|
+
*
|
|
111
|
+
* ponytail: a repository with no `origin/<trunk>` pays two failed git calls per
|
|
112
|
+
* branch; probing once in resolveDefaultBranch would save them but needs the
|
|
113
|
+
* base carried through the snapshot types.
|
|
114
|
+
*
|
|
115
|
+
* @param remoteBase - `origin/<default>`, already tried.
|
|
116
|
+
* @param branch - Branch to describe.
|
|
117
|
+
* @param options - Where to look, the base branch and the commit cap.
|
|
118
|
+
* @param run - Git runner.
|
|
119
|
+
* @returns The log output, or undefined when the remote ref exists but failed.
|
|
120
|
+
*/
|
|
121
|
+
async function localDelta(remoteBase, branch, options, run) {
|
|
122
|
+
if (await run(gitVerifyRefArgs(remoteBase), options.cwd, GIT_TIMEOUT_MS))
|
|
123
|
+
return undefined;
|
|
124
|
+
return run(gitBranchDeltaArgs(options.defaultBranch, branch, options.commitCount), options.cwd, GIT_TIMEOUT_MS);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The files of each commit in one `log -z --name-status --format=%H` listing.
|
|
128
|
+
*
|
|
129
|
+
* Read as NUL-separated tokens, never by splitting on anything a path can hold:
|
|
130
|
+
* with `-z` git prints a name raw, newlines and all, and NUL is the one byte no
|
|
131
|
+
* path contains. A commit is its sha; after it come `<letter>` `<path>` pairs,
|
|
132
|
+
* the first letter prefixed by a newline. A letter is always followed by
|
|
133
|
+
* exactly one path, so a path that looks like a sha or a letter is still a path.
|
|
134
|
+
*
|
|
135
|
+
* A listing the runner salvaged after the output ceiling was cut at its last
|
|
136
|
+
* newline. Cut inside a path, it no longer ends on NUL, and its last commit is
|
|
137
|
+
* left out; cut after a header, it ends on a commit with no files, which is left
|
|
138
|
+
* out too — unknown, not empty — at the price of an oldest commit that really
|
|
139
|
+
* changed nothing.
|
|
140
|
+
*
|
|
141
|
+
* @param output - The listing.
|
|
142
|
+
* @returns Files by commit sha, in git's order.
|
|
143
|
+
*/
|
|
144
|
+
export function parseCommitFiles(output) {
|
|
145
|
+
const bySha = new Map();
|
|
146
|
+
const tokens = output.split('\0');
|
|
147
|
+
const complete = output.endsWith('\0');
|
|
148
|
+
let current;
|
|
149
|
+
let last;
|
|
150
|
+
// The token after the final NUL is empty in a complete listing and a cut fragment otherwise.
|
|
151
|
+
tokens.pop();
|
|
152
|
+
for (let index = 0; index < tokens.length; index += 1) {
|
|
153
|
+
const token = (tokens[index] ?? '').replace(RE_LEADING_NEWLINE, '');
|
|
154
|
+
if (RE_NAME_STATUS.test(token) && current) {
|
|
155
|
+
const path = tokens[index + 1];
|
|
156
|
+
index += 1;
|
|
157
|
+
if (path)
|
|
158
|
+
current.push({ status: token, path });
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (!RE_OBJECT_ID.test(token))
|
|
162
|
+
continue;
|
|
163
|
+
current = [];
|
|
164
|
+
last = token;
|
|
165
|
+
bySha.set(token, current);
|
|
166
|
+
}
|
|
167
|
+
if (last && (!complete || bySha.get(last)?.length === 0))
|
|
168
|
+
bySha.delete(last);
|
|
169
|
+
return bySha;
|
|
67
170
|
}
|
|
68
171
|
/**
|
|
69
172
|
* One `for-each-ref` record.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { RepositoryRootFinder } from './types/repository-root.types.js';
|
|
2
|
+
export type { RepositoryRootFinder } from './types/repository-root.types.js';
|
|
3
|
+
/**
|
|
4
|
+
* A finder for the repository each file belongs to, when the session's own
|
|
5
|
+
* folder is not one.
|
|
6
|
+
*
|
|
7
|
+
* Bounded by `boundary` — the folder the session started in — for two reasons:
|
|
8
|
+
* a repository outside it is another project's, possibly another tenant's, and
|
|
9
|
+
* a bounded walk is a handful of `stat` calls rather than an unbounded climb to
|
|
10
|
+
* the filesystem root.
|
|
11
|
+
*
|
|
12
|
+
* ponytail: presence of a `.git` entry is the whole test, and the answer is the
|
|
13
|
+
* *nearest* ancestor that has one — so a file inside a submodule or a vendored
|
|
14
|
+
* checkout belongs to that inner repository, which is also what git itself
|
|
15
|
+
* would answer from that directory. It does not understand `GIT_DIR`, a bare
|
|
16
|
+
* repository, or a `.git` file pointing outside the tree. The upgrade path is
|
|
17
|
+
* `git rev-parse --show-toplevel` behind this same cache — deliberately not the
|
|
18
|
+
* implementation: a subprocess per tool call would sit on the coding agent's
|
|
19
|
+
* critical path.
|
|
20
|
+
*
|
|
21
|
+
* @param boundary - Folder the walk stops at, inclusive.
|
|
22
|
+
* @returns A finder whose answers are memoized per directory.
|
|
23
|
+
*/
|
|
24
|
+
export declare function repositoryRootFinder(boundary: string): RepositoryRootFinder;
|
|
25
|
+
/**
|
|
26
|
+
* Whether a path is a directory or lies inside it.
|
|
27
|
+
*
|
|
28
|
+
* The two answers that disqualify it are a relative path that climbs out and
|
|
29
|
+
* one that stays absolute (a different drive or root). A sibling named
|
|
30
|
+
* `..foo` climbs nowhere, which is why the separator is part of the test.
|
|
31
|
+
*
|
|
32
|
+
* Exported because the same question is asked of a repository path read back
|
|
33
|
+
* out of local turn state: one answer, not two that could disagree.
|
|
34
|
+
*
|
|
35
|
+
* @param boundary - Folder that bounds the walk.
|
|
36
|
+
* @param target - Path to test against it.
|
|
37
|
+
* @returns True when the target is the boundary or beneath it.
|
|
38
|
+
*/
|
|
39
|
+
export declare function isBeneath(boundary: string, target: string): boolean;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { GIT_ENTRY_ABSENT_CODES, GIT_ENTRY_NAME } from './constants/git.constants.js';
|
|
4
|
+
/**
|
|
5
|
+
* A finder for the repository each file belongs to, when the session's own
|
|
6
|
+
* folder is not one.
|
|
7
|
+
*
|
|
8
|
+
* Bounded by `boundary` — the folder the session started in — for two reasons:
|
|
9
|
+
* a repository outside it is another project's, possibly another tenant's, and
|
|
10
|
+
* a bounded walk is a handful of `stat` calls rather than an unbounded climb to
|
|
11
|
+
* the filesystem root.
|
|
12
|
+
*
|
|
13
|
+
* ponytail: presence of a `.git` entry is the whole test, and the answer is the
|
|
14
|
+
* *nearest* ancestor that has one — so a file inside a submodule or a vendored
|
|
15
|
+
* checkout belongs to that inner repository, which is also what git itself
|
|
16
|
+
* would answer from that directory. It does not understand `GIT_DIR`, a bare
|
|
17
|
+
* repository, or a `.git` file pointing outside the tree. The upgrade path is
|
|
18
|
+
* `git rev-parse --show-toplevel` behind this same cache — deliberately not the
|
|
19
|
+
* implementation: a subprocess per tool call would sit on the coding agent's
|
|
20
|
+
* critical path.
|
|
21
|
+
*
|
|
22
|
+
* @param boundary - Folder the walk stops at, inclusive.
|
|
23
|
+
* @returns A finder whose answers are memoized per directory.
|
|
24
|
+
*/
|
|
25
|
+
export function repositoryRootFinder(boundary) {
|
|
26
|
+
// Directory → its repository root, or undefined for "none, and asked".
|
|
27
|
+
// One turn touches the same handful of directories over and over.
|
|
28
|
+
const cache = new Map();
|
|
29
|
+
return { find: (filePath) => rootFor(path.dirname(filePath), boundary, cache) };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The repository root at or above one directory, memoizing every level.
|
|
33
|
+
*
|
|
34
|
+
* @param dir - Directory to resolve.
|
|
35
|
+
* @param boundary - Folder the walk stops at, inclusive.
|
|
36
|
+
* @param cache - Directory answers resolved so far.
|
|
37
|
+
* @returns The root, or undefined when there is none inside the boundary.
|
|
38
|
+
*/
|
|
39
|
+
async function rootFor(dir, boundary, cache) {
|
|
40
|
+
if (cache.has(dir))
|
|
41
|
+
return cache.get(dir);
|
|
42
|
+
// A file outside the start folder contributes no repository at all: its
|
|
43
|
+
// repository is not the session's business and could be another tenant's.
|
|
44
|
+
if (!isBeneath(boundary, dir))
|
|
45
|
+
return undefined;
|
|
46
|
+
const root = await walkUp(dir, boundary, cache);
|
|
47
|
+
cache.set(dir, root);
|
|
48
|
+
return root;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* One rung of the walk: this directory, else its parent.
|
|
52
|
+
*
|
|
53
|
+
* @param dir - Directory to test.
|
|
54
|
+
* @param boundary - Folder the walk stops at, inclusive.
|
|
55
|
+
* @param cache - Directory answers resolved so far.
|
|
56
|
+
* @returns The root, or undefined once the boundary is passed.
|
|
57
|
+
*/
|
|
58
|
+
async function walkUp(dir, boundary, cache) {
|
|
59
|
+
const entry = await gitEntry(dir);
|
|
60
|
+
if (entry === 'present')
|
|
61
|
+
return (await isReallyBeneath(boundary, dir)) ? dir : undefined;
|
|
62
|
+
// A `.git` that could not be checked may well be there: climbing past it
|
|
63
|
+
// would hand the file to an enclosing repository — the wrong branch, the
|
|
64
|
+
// wrong config. No repository is the answer this walk gives when unsure.
|
|
65
|
+
if (entry === 'unknown')
|
|
66
|
+
return undefined;
|
|
67
|
+
const parent = path.dirname(dir);
|
|
68
|
+
// `dir === boundary` ends the walk; `parent === dir` is the filesystem root,
|
|
69
|
+
// which only happens when the boundary is not an ancestor at all.
|
|
70
|
+
if (dir === boundary || parent === dir)
|
|
71
|
+
return undefined;
|
|
72
|
+
return rootFor(parent, boundary, cache);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* `isBeneath`, asked of where the two really are.
|
|
76
|
+
*
|
|
77
|
+
* A symlink inside the start folder can point at a checkout anywhere on the
|
|
78
|
+
* machine, and `.git` is found through it: lexically beneath, on disk another
|
|
79
|
+
* project's. Asked only once a root is found, so the walk itself stays `stat`s.
|
|
80
|
+
* A refused root ends the walk rather than climbing past it — the file belongs
|
|
81
|
+
* to that repository, whoever's it is. A path that cannot be resolved — a link
|
|
82
|
+
* removed or retargeted since the `.git` check — is refused too: its real
|
|
83
|
+
* location was never proven to be inside.
|
|
84
|
+
*
|
|
85
|
+
* @param boundary - Folder that bounds the walk.
|
|
86
|
+
* @param dir - Directory a `.git` entry was found in.
|
|
87
|
+
* @returns True when the directory really lies within the boundary.
|
|
88
|
+
*/
|
|
89
|
+
async function isReallyBeneath(boundary, dir) {
|
|
90
|
+
try {
|
|
91
|
+
const [realBoundary, realDir] = await Promise.all([fs.realpath(boundary), fs.realpath(dir)]);
|
|
92
|
+
return isBeneath(realBoundary, realDir);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Whether a `.git` entry sits directly in a directory.
|
|
100
|
+
*
|
|
101
|
+
* @param dir - Directory to test.
|
|
102
|
+
* @returns `present`, `absent`, or `unknown` when the check itself failed.
|
|
103
|
+
*/
|
|
104
|
+
async function gitEntry(dir) {
|
|
105
|
+
try {
|
|
106
|
+
await fs.access(path.join(dir, GIT_ENTRY_NAME));
|
|
107
|
+
return 'present';
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
const code = error.code;
|
|
111
|
+
return code !== undefined && GIT_ENTRY_ABSENT_CODES.has(code) ? 'absent' : 'unknown';
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Whether a path is a directory or lies inside it.
|
|
116
|
+
*
|
|
117
|
+
* The two answers that disqualify it are a relative path that climbs out and
|
|
118
|
+
* one that stays absolute (a different drive or root). A sibling named
|
|
119
|
+
* `..foo` climbs nowhere, which is why the separator is part of the test.
|
|
120
|
+
*
|
|
121
|
+
* Exported because the same question is asked of a repository path read back
|
|
122
|
+
* out of local turn state: one answer, not two that could disagree.
|
|
123
|
+
*
|
|
124
|
+
* @param boundary - Folder that bounds the walk.
|
|
125
|
+
* @param target - Path to test against it.
|
|
126
|
+
* @returns True when the target is the boundary or beneath it.
|
|
127
|
+
*/
|
|
128
|
+
export function isBeneath(boundary, target) {
|
|
129
|
+
const relative = path.relative(boundary, target);
|
|
130
|
+
return !path.isAbsolute(relative) && relative !== '..' && !relative.startsWith(`..${path.sep}`);
|
|
131
|
+
}
|
|
@@ -34,3 +34,58 @@ export interface RemoteParts {
|
|
|
34
34
|
readonly host: string;
|
|
35
35
|
readonly path: string;
|
|
36
36
|
}
|
|
37
|
+
/** Where a gated prompt is happening, when the working copy can say. */
|
|
38
|
+
export interface GateCheckout {
|
|
39
|
+
/** Canonical `host/owner/repo`, as `normalizeRemote` produces it. */
|
|
40
|
+
readonly repository: string;
|
|
41
|
+
readonly branch: string;
|
|
42
|
+
}
|
|
43
|
+
export interface GateCheckoutOptions {
|
|
44
|
+
/** Directory the payload happened in. */
|
|
45
|
+
readonly cwd: string;
|
|
46
|
+
/** Where remembered remotes live; `AgentWatchPaths.checkoutsDir`. */
|
|
47
|
+
readonly checkoutsDir: string;
|
|
48
|
+
readonly timeoutMs?: number;
|
|
49
|
+
/** Clock, injectable for tests. */
|
|
50
|
+
now?(): Date;
|
|
51
|
+
/** Git runner override, injectable for tests. */
|
|
52
|
+
readonly run?: GitRunner;
|
|
53
|
+
/**
|
|
54
|
+
* The repository already known for a checkout rooted exactly at `cwd`: no
|
|
55
|
+
* remote lookup, so no git process. A walk that finds no `.git` at `cwd`
|
|
56
|
+
* itself answers undefined rather than borrowing an enclosing repository's.
|
|
57
|
+
*/
|
|
58
|
+
readonly repository?: string;
|
|
59
|
+
}
|
|
60
|
+
/** One dirty entry of a checkout, stamped so a later edit to it shows. */
|
|
61
|
+
export interface DirtyEntry {
|
|
62
|
+
/** Porcelain status letters; `??` for untracked. */
|
|
63
|
+
readonly xy: string;
|
|
64
|
+
/** Absent when the file is gone from disk. */
|
|
65
|
+
readonly size?: number;
|
|
66
|
+
readonly mtimeMs?: number;
|
|
67
|
+
/** Change time and inode: a rewrite that keeps size and mtime still moves these. */
|
|
68
|
+
readonly ctimeMs?: number;
|
|
69
|
+
readonly ino?: number;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A checkout at one moment, as `git status --porcelain=v2 --branch` and `lstat`
|
|
73
|
+
* see it. Local turn state only; never sent.
|
|
74
|
+
*/
|
|
75
|
+
export interface Fingerprint {
|
|
76
|
+
/** HEAD; absent before the first commit. */
|
|
77
|
+
readonly oid?: string;
|
|
78
|
+
/** Git said HEAD is unborn (`(initial)`): the first commit is yet to come. */
|
|
79
|
+
readonly unborn?: boolean;
|
|
80
|
+
/** Checked-out branch; absent on a detached HEAD. */
|
|
81
|
+
readonly branch?: string;
|
|
82
|
+
/** The git dir every worktree of the repository shares, read from disk. */
|
|
83
|
+
readonly commonDir?: string;
|
|
84
|
+
/** Repository-relative path → its entry. */
|
|
85
|
+
readonly dirty: Readonly<Record<string, DirtyEntry>>;
|
|
86
|
+
}
|
|
87
|
+
/** A file's one-way content id: its path under the session folder and git's blob hash. */
|
|
88
|
+
export interface ContentHash {
|
|
89
|
+
readonly path: string;
|
|
90
|
+
readonly blob_sha: string;
|
|
91
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Finds the repository a file belongs to, bounded by one directory and
|
|
3
|
+
* memoized for the life of the finder.
|
|
4
|
+
*/
|
|
5
|
+
export interface RepositoryRootFinder {
|
|
6
|
+
/**
|
|
7
|
+
* The root of the repository containing `filePath`, or undefined when none
|
|
8
|
+
* lies between the file and the boundary.
|
|
9
|
+
*/
|
|
10
|
+
find(filePath: string): Promise<string | undefined>;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,11 +4,18 @@ export interface BranchRef {
|
|
|
4
4
|
readonly headSha: string;
|
|
5
5
|
readonly lastCommitAt?: string;
|
|
6
6
|
}
|
|
7
|
+
/** One file a commit changed: git's name-status letter and the repository-relative path. */
|
|
8
|
+
export interface CommitFile {
|
|
9
|
+
readonly status: string;
|
|
10
|
+
readonly path: string;
|
|
11
|
+
}
|
|
7
12
|
/** One commit in a branch's delta against its default branch. */
|
|
8
13
|
export interface BranchCommit {
|
|
9
14
|
readonly sha: string;
|
|
10
15
|
readonly subject: string;
|
|
11
16
|
readonly authoredAt?: string;
|
|
17
|
+
/** Absent when the listing failed, ran out of time or was cut short; empty for a merge or an empty commit. */
|
|
18
|
+
readonly files?: readonly CommitFile[];
|
|
12
19
|
}
|
|
13
20
|
/** A branch with the commits that are its own. */
|
|
14
21
|
export interface SnapshotBranch extends BranchRef {
|
|
@@ -20,6 +27,8 @@ export interface CollectRefsOptions {
|
|
|
20
27
|
}
|
|
21
28
|
export interface CollectCommitsOptions {
|
|
22
29
|
readonly cwd: string;
|
|
30
|
+
/** List the files each commit changed; false under `capture.files: false`. */
|
|
31
|
+
readonly withFiles?: boolean;
|
|
23
32
|
readonly defaultBranch?: string;
|
|
24
33
|
readonly commitCount: number;
|
|
25
34
|
}
|
|
@@ -2,6 +2,13 @@ import type { CanonicalEventType } from '../../events/types/events.types.js';
|
|
|
2
2
|
/** Stage names, used in the flow definition and in its debug trace. */
|
|
3
3
|
export declare const STAGE_RESOLVE_CONTEXT = "resolve-context";
|
|
4
4
|
export declare const STAGE_PARSE_EVENTS = "parse-events";
|
|
5
|
+
/** Open folders a tool hook nominates, at most: half of a turn's checkout slots. */
|
|
6
|
+
export declare const MAX_WORKSPACE_ROOTS = 4;
|
|
7
|
+
export declare const STAGE_NOMINATE = "nominate";
|
|
8
|
+
export declare const STAGE_UNTRACED = "untraced";
|
|
9
|
+
export declare const STAGE_UPDATE = "update";
|
|
10
|
+
/** SessionStart sources that are not a developer starting work: no update notice on them. */
|
|
11
|
+
export declare const QUIET_SESSION_SOURCES: ReadonlySet<string>;
|
|
5
12
|
export declare const STAGE_ENFORCE = "enforce";
|
|
6
13
|
export declare const STAGE_ENRICH = "enrich";
|
|
7
14
|
export declare const STAGE_TRACK_TURN = "track-turn";
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/** Stage names, used in the flow definition and in its debug trace. */
|
|
2
2
|
export const STAGE_RESOLVE_CONTEXT = 'resolve-context';
|
|
3
3
|
export const STAGE_PARSE_EVENTS = 'parse-events';
|
|
4
|
+
/** Open folders a tool hook nominates, at most: half of a turn's checkout slots. */
|
|
5
|
+
export const MAX_WORKSPACE_ROOTS = 4;
|
|
6
|
+
export const STAGE_NOMINATE = 'nominate';
|
|
7
|
+
export const STAGE_UNTRACED = 'untraced';
|
|
8
|
+
export const STAGE_UPDATE = 'update';
|
|
9
|
+
/** SessionStart sources that are not a developer starting work: no update notice on them. */
|
|
10
|
+
export const QUIET_SESSION_SOURCES = new Set(['clear', 'compact']);
|
|
4
11
|
export const STAGE_ENFORCE = 'enforce';
|
|
5
12
|
export const STAGE_ENRICH = 'enrich';
|
|
6
13
|
export const STAGE_TRACK_TURN = 'track-turn';
|