@agent-watch-ai/edge 0.6.0 → 0.7.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 +288 -9
- package/README.md +307 -5
- package/dist/billing/billing-mode.d.ts +37 -5
- package/dist/billing/billing-mode.js +28 -19
- package/dist/billing/constants/billing.constants.d.ts +0 -2
- package/dist/billing/constants/billing.constants.js +0 -2
- package/dist/billing/index.d.ts +2 -1
- package/dist/billing/index.js +1 -1
- package/dist/billing/session-billing.d.ts +7 -3
- package/dist/billing/session-billing.js +34 -13
- package/dist/billing/types/billing.types.d.ts +7 -0
- package/dist/capture/capture-env.d.ts +147 -0
- package/dist/capture/capture-env.js +301 -0
- package/dist/capture/captured-step.d.ts +88 -0
- package/dist/capture/captured-step.js +503 -0
- package/dist/capture/constants/capture.constants.d.ts +85 -0
- package/dist/capture/constants/capture.constants.js +87 -0
- package/dist/capture/launched-runs.d.ts +43 -0
- package/dist/capture/launched-runs.js +157 -0
- package/dist/capture/node.cjs +697 -0
- package/dist/capture/node.d.cts +32 -0
- package/dist/capture/python/sitecustomize.py +832 -0
- package/dist/capture/schemas/capture.schema.d.ts +35 -0
- package/dist/capture/schemas/capture.schema.js +31 -0
- package/dist/capture/types/capture.types.d.ts +20 -0
- package/dist/capture/venv-loader.d.ts +68 -0
- package/dist/capture/venv-loader.js +189 -0
- package/dist/cli/constants/cli.constants.d.ts +23 -6
- package/dist/cli/constants/cli.constants.js +24 -7
- package/dist/cli/context.d.ts +19 -22
- package/dist/cli/context.js +23 -54
- package/dist/cli/doctor-run-capture.d.ts +21 -0
- package/dist/cli/doctor-run-capture.js +33 -0
- package/dist/cli/doctor.js +21 -68
- package/dist/cli/hook-check.d.ts +7 -2
- package/dist/cli/hook-check.js +30 -15
- package/dist/cli/hook.d.ts +14 -0
- package/dist/cli/hook.js +82 -1
- package/dist/cli/index.d.ts +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/cli/misc.js +10 -2
- package/dist/cli/npm-global.d.ts +24 -0
- package/dist/cli/npm-global.js +77 -0
- package/dist/cli/npx-install.js +22 -6
- package/dist/cli/replay.d.ts +33 -0
- package/dist/cli/replay.js +228 -0
- package/dist/cli/setup.d.ts +10 -2
- package/dist/cli/setup.js +200 -31
- package/dist/cli/status.js +45 -5
- package/dist/cli/toggle.js +10 -0
- package/dist/cli/types/cli.types.d.ts +15 -1
- package/dist/cli/uninstall.js +42 -23
- package/dist/cli/update.js +3 -2
- package/dist/cli.js +104 -17
- package/dist/config/config-store.d.ts +15 -4
- package/dist/config/config-store.js +31 -7
- package/dist/config/config.d.ts +0 -2
- package/dist/config/config.js +0 -1
- package/dist/config/constants/config.constants.d.ts +8 -1
- package/dist/config/constants/config.constants.js +10 -1
- package/dist/config/events-transport.d.ts +15 -0
- package/dist/config/events-transport.js +29 -0
- package/dist/config/index.d.ts +2 -1
- package/dist/config/index.js +1 -0
- package/dist/config/root-config.d.ts +12 -0
- package/dist/config/root-config.js +24 -0
- package/dist/config/schemas/config.schema.d.ts +15 -2
- package/dist/config/schemas/config.schema.js +52 -8
- package/dist/config/types/config.types.d.ts +7 -0
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/version.d.ts +9 -0
- package/dist/core/version.js +14 -0
- package/dist/core/which.d.ts +11 -0
- package/dist/core/which.js +18 -0
- package/dist/credentials/cloud-claim.d.ts +34 -0
- package/dist/credentials/cloud-claim.js +61 -0
- package/dist/credentials/constants/credentials.constants.d.ts +16 -1
- package/dist/credentials/constants/credentials.constants.js +17 -2
- package/dist/credentials/credential-status.js +1 -1
- package/dist/credentials/credentials.d.ts +3 -3
- package/dist/credentials/credentials.js +26 -12
- package/dist/credentials/device-api.d.ts +15 -1
- package/dist/credentials/device-api.js +12 -1
- package/dist/credentials/identity.d.ts +2 -2
- package/dist/credentials/identity.js +2 -2
- package/dist/credentials/install-key.d.ts +31 -0
- package/dist/credentials/install-key.js +58 -0
- package/dist/credentials/migration.d.ts +9 -7
- package/dist/credentials/migration.js +58 -18
- package/dist/credentials/secret-store.d.ts +12 -0
- package/dist/credentials/secret-store.js +18 -1
- package/dist/credentials/sign-in.d.ts +27 -0
- package/dist/credentials/sign-in.js +31 -1
- package/dist/credentials/token-refresher.d.ts +5 -1
- package/dist/credentials/token-refresher.js +10 -2
- package/dist/enforcement/enforcement.js +1 -1
- package/dist/events/constants/events.constants.d.ts +5 -2
- package/dist/events/constants/events.constants.js +4 -1
- package/dist/events/enrich.d.ts +14 -0
- package/dist/events/enrich.js +1 -1
- package/dist/events/index.d.ts +1 -0
- package/dist/events/product-event.d.ts +6 -3
- package/dist/events/types/events.types.d.ts +6 -0
- package/dist/events/types/replay-progress.types.d.ts +26 -0
- package/dist/events/types/replay-progress.types.js +1 -0
- package/dist/events/types/repo-tree.types.d.ts +2 -1
- package/dist/feature/ticket-candidates.d.ts +1 -1
- package/dist/git/checkout-root.d.ts +15 -0
- package/dist/git/checkout-root.js +18 -0
- package/dist/git/code-state.d.ts +2 -16
- package/dist/git/code-state.js +11 -12
- package/dist/git/constants/git.constants.d.ts +33 -11
- package/dist/git/constants/git.constants.js +45 -12
- package/dist/git/fingerprint.d.ts +3 -6
- package/dist/git/fingerprint.js +5 -8
- package/dist/git/git-context.js +5 -1
- package/dist/git/index.d.ts +1 -2
- package/dist/git/index.js +1 -1
- package/dist/git/repo-snapshot.d.ts +13 -4
- package/dist/git/repo-snapshot.js +53 -9
- package/dist/git/types/snapshot.types.d.ts +6 -0
- package/dist/pipeline/constants/pipeline.constants.d.ts +3 -0
- package/dist/pipeline/constants/pipeline.constants.js +3 -0
- package/dist/pipeline/hook-pipeline.js +82 -57
- package/dist/privacy/product-capture.js +2 -0
- package/dist/providers/antigravity/antigravity.capture.d.ts +2 -0
- package/dist/providers/antigravity/antigravity.capture.js +5 -0
- package/dist/providers/antigravity/antigravity.detect.js +8 -22
- package/dist/providers/antigravity/antigravity.provider.js +10 -3
- package/dist/providers/antigravity/constants/antigravity.constants.d.ts +1 -0
- package/dist/providers/antigravity/constants/antigravity.constants.js +1 -0
- package/dist/providers/claude/claude.adapter.js +9 -6
- package/dist/providers/claude/claude.detect.js +2 -17
- package/dist/providers/claude/claude.otel.d.ts +21 -3
- package/dist/providers/claude/claude.otel.js +216 -61
- package/dist/providers/claude/claude.provider.js +21 -1
- package/dist/providers/claude/claude.version.d.ts +9 -0
- package/dist/providers/claude/claude.version.js +28 -0
- package/dist/providers/claude/constants/claude.constants.d.ts +27 -0
- package/dist/providers/claude/constants/claude.constants.js +27 -0
- package/dist/providers/claude/constants/claude.otel.constants.d.ts +27 -0
- package/dist/providers/claude/constants/claude.otel.constants.js +45 -5
- package/dist/providers/claude/types/claude.types.d.ts +13 -0
- package/dist/providers/codex/codex.capture.d.ts +76 -0
- package/dist/providers/codex/codex.capture.js +454 -0
- package/dist/providers/codex/codex.detect.js +2 -4
- package/dist/providers/codex/codex.otel.d.ts +38 -2
- package/dist/providers/codex/codex.otel.js +50 -6
- package/dist/providers/codex/codex.provider.js +8 -0
- package/dist/providers/codex/codex.surface.d.ts +9 -0
- package/dist/{turns/codex-originator.js → providers/codex/codex.surface.js} +17 -3
- package/dist/providers/codex/codex.titles.d.ts +14 -0
- package/dist/providers/codex/codex.titles.js +35 -0
- package/dist/providers/codex/constants/codex.constants.d.ts +4 -0
- package/dist/providers/codex/constants/codex.constants.js +4 -0
- package/dist/providers/cursor/constants/cursor.constants.d.ts +17 -4
- package/dist/providers/cursor/constants/cursor.constants.js +25 -5
- package/dist/providers/cursor/cursor-mcp-memo.d.ts +34 -0
- package/dist/providers/cursor/cursor-mcp-memo.js +94 -0
- package/dist/providers/cursor/cursor.adapter.js +20 -82
- package/dist/providers/cursor/cursor.capture.d.ts +1 -0
- package/dist/providers/cursor/cursor.capture.js +4 -0
- package/dist/providers/cursor/cursor.detect.d.ts +5 -1
- package/dist/providers/cursor/cursor.detect.js +11 -26
- package/dist/providers/cursor/cursor.hooks.js +2 -2
- package/dist/providers/cursor/cursor.provider.js +16 -7
- package/dist/providers/cursor/cursor.titles.d.ts +14 -0
- package/dist/providers/cursor/cursor.titles.js +20 -0
- package/dist/providers/cursor/schemas/cursor.schema.d.ts +3 -3
- package/dist/providers/cursor/schemas/cursor.schema.js +5 -3
- package/dist/providers/gemini/constants/gemini.constants.d.ts +16 -0
- package/dist/providers/gemini/constants/gemini.constants.js +17 -0
- package/dist/providers/gemini/gemini.capture.d.ts +81 -0
- package/dist/providers/gemini/gemini.capture.js +210 -0
- package/dist/providers/gemini/gemini.detect.js +57 -24
- package/dist/providers/gemini/gemini.otel.d.ts +38 -2
- package/dist/providers/gemini/gemini.otel.js +56 -125
- package/dist/providers/gemini/gemini.provider.js +5 -0
- package/dist/providers/index.d.ts +1 -0
- package/dist/providers/index.js +1 -0
- package/dist/providers/provider.d.ts +8 -0
- package/dist/providers/provider.js +9 -0
- package/dist/providers/registry.d.ts +14 -0
- package/dist/providers/registry.js +14 -0
- package/dist/providers/shared/constants/hook-config.constants.d.ts +2 -0
- package/dist/providers/shared/constants/hook-config.constants.js +2 -0
- package/dist/providers/shared/constants/terminal-capture.constants.d.ts +6 -0
- package/dist/providers/shared/constants/terminal-capture.constants.js +6 -0
- package/dist/providers/shared/editor-paths.d.ts +8 -0
- package/dist/providers/shared/editor-paths.js +18 -0
- package/dist/providers/shared/hook-config.d.ts +5 -0
- package/dist/providers/shared/hook-config.js +39 -1
- package/dist/providers/shared/hooks-marker.d.ts +14 -0
- package/dist/providers/shared/hooks-marker.js +23 -0
- package/dist/providers/shared/install-record.d.ts +29 -0
- package/dist/providers/shared/install-record.js +52 -0
- package/dist/providers/shared/session-title-store.d.ts +23 -0
- package/dist/providers/shared/session-title-store.js +50 -0
- package/dist/providers/shared/terminal-capture.d.ts +41 -0
- package/dist/providers/shared/terminal-capture.js +109 -0
- package/dist/providers/shared/tooling.d.ts +21 -0
- package/dist/providers/shared/tooling.js +36 -1
- package/dist/providers/types/provider.types.d.ts +57 -4
- package/dist/replay/checkout-resolver.d.ts +56 -0
- package/dist/replay/checkout-resolver.js +173 -0
- package/dist/replay/codex-turns.d.ts +24 -0
- package/dist/replay/codex-turns.js +221 -0
- package/dist/replay/constants/replay.constants.d.ts +99 -0
- package/dist/replay/constants/replay.constants.js +102 -0
- package/dist/replay/describe.d.ts +10 -0
- package/dist/replay/describe.js +31 -0
- package/dist/replay/gemini-turns.d.ts +36 -0
- package/dist/replay/gemini-turns.js +192 -0
- package/dist/replay/machine.d.ts +34 -0
- package/dist/replay/machine.js +68 -0
- package/dist/replay/progress-event.d.ts +21 -0
- package/dist/replay/progress-event.js +45 -0
- package/dist/replay/replay-runner.d.ts +60 -0
- package/dist/replay/replay-runner.js +581 -0
- package/dist/replay/replay-scan.d.ts +84 -0
- package/dist/replay/replay-scan.js +182 -0
- package/dist/replay/replay-state.d.ts +108 -0
- package/dist/replay/replay-state.js +199 -0
- package/dist/replay/resume.d.ts +18 -0
- package/dist/replay/resume.js +34 -0
- package/dist/replay/start.d.ts +23 -0
- package/dist/replay/start.js +39 -0
- package/dist/replay/throttle.d.ts +36 -0
- package/dist/replay/throttle.js +44 -0
- package/dist/replay/transcript-turns.d.ts +35 -0
- package/dist/replay/transcript-turns.js +241 -0
- package/dist/replay/turn-event.d.ts +40 -0
- package/dist/replay/turn-event.js +127 -0
- package/dist/replay/types/replay.types.d.ts +198 -0
- package/dist/replay/types/replay.types.js +1 -0
- package/dist/replay/window.d.ts +28 -0
- package/dist/replay/window.js +41 -0
- package/dist/replay/worktree-map.d.ts +42 -0
- package/dist/replay/worktree-map.js +134 -0
- package/dist/snapshot/branch-selection.d.ts +40 -23
- package/dist/snapshot/branch-selection.js +71 -41
- package/dist/snapshot/constants/snapshot-stages.constants.d.ts +3 -1
- package/dist/snapshot/constants/snapshot-stages.constants.js +3 -1
- package/dist/snapshot/constants/snapshot.constants.d.ts +34 -7
- package/dist/snapshot/constants/snapshot.constants.js +34 -7
- package/dist/snapshot/index.d.ts +2 -2
- package/dist/snapshot/index.js +1 -1
- package/dist/snapshot/snapshot-pipeline.js +100 -26
- package/dist/snapshot/snapshot-state.js +6 -2
- package/dist/snapshot/tree-pipeline.d.ts +1 -1
- package/dist/snapshot/tree-pipeline.js +34 -15
- package/dist/snapshot/types/snapshot.types.d.ts +22 -3
- package/dist/storage/schemas/storage.schema.d.ts +2 -0
- package/dist/storage/schemas/storage.schema.js +6 -0
- package/dist/transport/delivery-stats.d.ts +13 -1
- package/dist/transport/delivery-stats.js +18 -2
- package/dist/transport/delivery.d.ts +4 -3
- package/dist/transport/delivery.js +21 -7
- package/dist/transport/identity-delivery.d.ts +20 -0
- package/dist/transport/identity-delivery.js +41 -0
- package/dist/transport/index.d.ts +2 -0
- package/dist/transport/index.js +1 -0
- package/dist/transport/types/delivery-flow.types.d.ts +7 -0
- package/dist/turns/claude-transcript.js +4 -12
- package/dist/turns/codex-transcript.d.ts +9 -0
- package/dist/turns/codex-transcript.js +27 -19
- package/dist/turns/constants/turns.constants.d.ts +29 -12
- package/dist/turns/constants/turns.constants.js +31 -19
- package/dist/turns/gemini-transcript.d.ts +19 -1
- package/dist/turns/gemini-transcript.js +29 -18
- package/dist/turns/index.d.ts +3 -4
- package/dist/turns/index.js +2 -3
- package/dist/turns/run-state.d.ts +71 -0
- package/dist/turns/run-state.js +114 -0
- package/dist/turns/tool-events.d.ts +11 -1
- package/dist/turns/tool-events.js +32 -9
- package/dist/turns/transcript.d.ts +15 -14
- package/dist/turns/transcript.js +23 -4
- package/dist/turns/turn-state.d.ts +82 -7
- package/dist/turns/turn-state.js +157 -10
- package/dist/turns/turn-summary.js +7 -2
- package/dist/turns/turn-tracker.d.ts +9 -16
- package/dist/turns/turn-tracker.js +163 -87
- package/dist/turns/types/transcript.types.d.ts +11 -1
- package/dist/turns/types/turn-provider.types.d.ts +33 -0
- package/dist/turns/types/turn-provider.types.js +1 -0
- package/dist/turns/types/turn-state.types.d.ts +9 -0
- package/dist/turns/types/turn-summary.types.d.ts +17 -1
- package/dist/turns/types/turn-tracker.types.d.ts +3 -1
- package/dist/turns/work-checkout.js +1 -2
- package/docs/AUDIT_PROMPT.md +10 -0
- package/docs/DATA_HANDLING.md +201 -13
- package/docs/ENTERPRISE_DEPLOYMENT.md +3 -3
- package/docs/PERFORMANCE.md +10 -0
- package/package.json +3 -2
- package/dist/events/canonical-event.d.ts +0 -10
- package/dist/events/canonical-event.js +0 -9
- package/dist/git/repository-root.d.ts +0 -39
- package/dist/git/repository-root.js +0 -131
- package/dist/git/types/repository-root.types.d.ts +0 -11
- package/dist/transport/transport.d.ts +0 -6
- package/dist/turns/codex-originator.d.ts +0 -11
- package/dist/turns/cursor-transcript.d.ts +0 -21
- package/dist/turns/cursor-transcript.js +0 -66
- package/dist/turns/native-session-titles.d.ts +0 -26
- package/dist/turns/native-session-titles.js +0 -102
- /package/dist/{git/types/repository-root.types.js → billing/types/billing.types.js} +0 -0
- /package/dist/{transport/transport.js → capture/types/capture.types.js} +0 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The words of one command segment, its `VAR=value` prefixes gone unread: a value
|
|
3
|
+
* set on a command line is often the very key this code must never hold.
|
|
4
|
+
*
|
|
5
|
+
* @param segment - One `&&`/`;`/`|`-separated part of a command.
|
|
6
|
+
* @returns The words, unquoted.
|
|
7
|
+
*/
|
|
8
|
+
export declare function wordsOf(segment: string): string[];
|
|
9
|
+
/**
|
|
10
|
+
* A command's `&&`/`||`/`;`/`|`/newline parts, split only outside quotes and `$(...)`:
|
|
11
|
+
* a separator inside a quoted value would otherwise cut that value into a "command".
|
|
12
|
+
*
|
|
13
|
+
* @param command - The shell command, read in memory only.
|
|
14
|
+
* @returns The parts, trimmed; never an empty one.
|
|
15
|
+
*/
|
|
16
|
+
export declare function segmentsOf(command: string): string[];
|
|
17
|
+
/**
|
|
18
|
+
* The name a shell call's captured calls are labelled with.
|
|
19
|
+
*
|
|
20
|
+
* The first segment that runs a program, by the same closed list the untraced
|
|
21
|
+
* notice uses, else the command's first word: a captured call may come from a run
|
|
22
|
+
* that list does not know (`./eval.py`, `make eval`) and still belongs to this
|
|
23
|
+
* call's turn. A script is named relative to its checkout, by file name alone
|
|
24
|
+
* outside one, and only by the runner's name when file names are off. Scrubbed
|
|
25
|
+
* here, as a turn summary's paths are: only this leaves the command.
|
|
26
|
+
*
|
|
27
|
+
* @param command - The shell command, read in memory only.
|
|
28
|
+
* @param directory - Where it runs.
|
|
29
|
+
* @param filesAllowed - Whether capture policy allows file names.
|
|
30
|
+
* @returns The entry, or undefined for an empty command.
|
|
31
|
+
*/
|
|
32
|
+
export declare function runEntry(command: string, directory: string, filesAllowed: boolean): Promise<string | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* The folder the chosen segment runs in. A `cd` this cannot follow (`$DIR`, `~`) ends the
|
|
35
|
+
* walk: the script is then named from where the walk stopped, or by its name alone.
|
|
36
|
+
*
|
|
37
|
+
* @param segments - The command's segments, from `segmentsOf`.
|
|
38
|
+
* @param chosen - The index of the segment whose folder is asked for: by index, as a
|
|
39
|
+
* command can repeat a segment after a `cd`.
|
|
40
|
+
* @param directory - Where the command starts.
|
|
41
|
+
* @returns The folder.
|
|
42
|
+
*/
|
|
43
|
+
export declare function afterCds(segments: readonly string[], chosen: number, directory: string): string;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { checkoutOf } from '../git/checkout-root.js';
|
|
3
|
+
import { sanitizeText } from '../privacy/sanitizer.js';
|
|
4
|
+
import { NOT_A_RUN, RUN_COMMAND } from '../untraced/constants/untraced.constants.js';
|
|
5
|
+
import { INLINE_FLAGS, MAX_RUN_ENTRY_LENGTH, MODULE_FLAG, RE_CD, RE_SHELL_EXPANDED, RE_COMMAND_WORD, RE_ENV_ASSIGNMENT, RE_MODULE_NAME, RE_NOT_A_NAME, RE_PYTHON, RE_SCRIPT_FILE, RE_SCRIPT_RUNNER, RE_SEPARATOR_CHAR, RE_SETUP_COMMAND, RE_SUBSTITUTION, RE_WORD_QUOTES, UNNAMED_COMMAND } from './constants/capture.constants.js';
|
|
6
|
+
/**
|
|
7
|
+
* The words of one command segment, its `VAR=value` prefixes gone unread: a value
|
|
8
|
+
* set on a command line is often the very key this code must never hold.
|
|
9
|
+
*
|
|
10
|
+
* @param segment - One `&&`/`;`/`|`-separated part of a command.
|
|
11
|
+
* @returns The words, unquoted.
|
|
12
|
+
*/
|
|
13
|
+
export function wordsOf(segment) {
|
|
14
|
+
const raw = segment.match(RE_COMMAND_WORD) ?? [];
|
|
15
|
+
const words = raw.map((word) => word.replace(RE_WORD_QUOTES, ''));
|
|
16
|
+
const firstReal = words.findIndex((word) => !RE_ENV_ASSIGNMENT.test(word));
|
|
17
|
+
if (firstReal === -1)
|
|
18
|
+
return [];
|
|
19
|
+
// A substitution in a value can nest past what these words can follow, so what
|
|
20
|
+
// comes after it may still be that value: nothing here is safe to name.
|
|
21
|
+
return raw.slice(0, firstReal).some((word) => RE_SUBSTITUTION.test(word)) ? [UNNAMED_COMMAND] : words.slice(firstReal);
|
|
22
|
+
}
|
|
23
|
+
function isScript(word) {
|
|
24
|
+
return RE_SCRIPT_FILE.test(word) && !RE_NOT_A_NAME.test(word);
|
|
25
|
+
}
|
|
26
|
+
function nameOr(word) {
|
|
27
|
+
return RE_MODULE_NAME.test(word) ? word : UNNAMED_COMMAND;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A command's `&&`/`||`/`;`/`|`/newline parts, split only outside quotes and `$(...)`:
|
|
31
|
+
* a separator inside a quoted value would otherwise cut that value into a "command".
|
|
32
|
+
*
|
|
33
|
+
* @param command - The shell command, read in memory only.
|
|
34
|
+
* @returns The parts, trimmed; never an empty one.
|
|
35
|
+
*/
|
|
36
|
+
export function segmentsOf(command) {
|
|
37
|
+
const segments = [];
|
|
38
|
+
let quote;
|
|
39
|
+
let depth = 0;
|
|
40
|
+
let start = 0;
|
|
41
|
+
for (let index = 0; index < command.length; index++) {
|
|
42
|
+
const char = command[index];
|
|
43
|
+
if (char === '\\' && quote !== '\'') {
|
|
44
|
+
index++;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (quote !== undefined) {
|
|
48
|
+
if (char === quote)
|
|
49
|
+
quote = undefined;
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
if (char === '"' || char === '\'' || char === '`') {
|
|
53
|
+
quote = char;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
if (char === '$' && command[index + 1] === '(')
|
|
57
|
+
depth++;
|
|
58
|
+
if (char === ')' && depth > 0)
|
|
59
|
+
depth--;
|
|
60
|
+
if (depth > 0 || !RE_SEPARATOR_CHAR.test(char))
|
|
61
|
+
continue;
|
|
62
|
+
segments.push(command.slice(start, index));
|
|
63
|
+
start = index + 1;
|
|
64
|
+
}
|
|
65
|
+
return [...segments, command.slice(start)].map((part) => part.trim()).filter((part) => part !== '');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* What a command runs, before it is made relative.
|
|
69
|
+
*
|
|
70
|
+
* Closed on purpose: arguments are where secrets sit (`make X=key`, `--token=key`,
|
|
71
|
+
* `postgres://user:pass@host`), so a word becomes the name only as a script file, a
|
|
72
|
+
* module, or a package script, and anything else falls back to the program's name.
|
|
73
|
+
*
|
|
74
|
+
* @param words - The segment's words.
|
|
75
|
+
* @param runsCode - Whether the segment is a run by the closed list.
|
|
76
|
+
* @returns A script path to resolve, or a name to use as it stands.
|
|
77
|
+
*/
|
|
78
|
+
function programOf(words, runsCode) {
|
|
79
|
+
const first = words[0] ?? '';
|
|
80
|
+
const program = path.basename(first);
|
|
81
|
+
if (isScript(first))
|
|
82
|
+
return { file: first };
|
|
83
|
+
if (RE_SCRIPT_RUNNER.test(first)) {
|
|
84
|
+
const script = words.slice(1, words[1] === 'run' ? 3 : 2);
|
|
85
|
+
return { name: script.every((word) => RE_MODULE_NAME.test(word) && !word.startsWith('-')) ? [first, ...script].join(' ') : first };
|
|
86
|
+
}
|
|
87
|
+
if (!runsCode && !RE_PYTHON.test(program))
|
|
88
|
+
return { name: nameOr(program) };
|
|
89
|
+
for (let index = 1; index < words.length; index++) {
|
|
90
|
+
const word = words[index];
|
|
91
|
+
if (INLINE_FLAGS.has(word))
|
|
92
|
+
return { name: nameOr(program) };
|
|
93
|
+
if (word === MODULE_FLAG)
|
|
94
|
+
return { name: RE_MODULE_NAME.test(words[index + 1] ?? '') ? words[index + 1] : nameOr(program) };
|
|
95
|
+
if (isScript(word))
|
|
96
|
+
return { file: word };
|
|
97
|
+
}
|
|
98
|
+
return { name: nameOr(program) };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The name a shell call's captured calls are labelled with.
|
|
102
|
+
*
|
|
103
|
+
* The first segment that runs a program, by the same closed list the untraced
|
|
104
|
+
* notice uses, else the command's first word: a captured call may come from a run
|
|
105
|
+
* that list does not know (`./eval.py`, `make eval`) and still belongs to this
|
|
106
|
+
* call's turn. A script is named relative to its checkout, by file name alone
|
|
107
|
+
* outside one, and only by the runner's name when file names are off. Scrubbed
|
|
108
|
+
* here, as a turn summary's paths are: only this leaves the command.
|
|
109
|
+
*
|
|
110
|
+
* @param command - The shell command, read in memory only.
|
|
111
|
+
* @param directory - Where it runs.
|
|
112
|
+
* @param filesAllowed - Whether capture policy allows file names.
|
|
113
|
+
* @returns The entry, or undefined for an empty command.
|
|
114
|
+
*/
|
|
115
|
+
export async function runEntry(command, directory, filesAllowed) {
|
|
116
|
+
const segments = segmentsOf(command);
|
|
117
|
+
const running = segments.find((part) => RUN_COMMAND.test(part) && !NOT_A_RUN.test(part));
|
|
118
|
+
const chosen = running ?? segments.find((part) => !RE_SETUP_COMMAND.test(part)) ?? segments[0] ?? '';
|
|
119
|
+
const words = wordsOf(chosen);
|
|
120
|
+
if (words.length === 0)
|
|
121
|
+
return undefined;
|
|
122
|
+
const program = programOf(words, running !== undefined);
|
|
123
|
+
// With file names off, a script that is itself the command has no runner to name.
|
|
124
|
+
if (program.file === undefined || !filesAllowed) {
|
|
125
|
+
// `./deploy-acme.sh`: a program given by path is a file too, whatever its extension.
|
|
126
|
+
const namesAFile = !filesAllowed && program.name === path.basename(words[0]) && words[0].includes('/') && !RE_PYTHON.test(program.name);
|
|
127
|
+
return clean(namesAFile ? UNNAMED_COMMAND : (program.name ?? (program.file === words[0] ? UNNAMED_COMMAND : nameOr(path.basename(words[0])))));
|
|
128
|
+
}
|
|
129
|
+
const absolute = path.resolve(afterCds(segments, segments.indexOf(chosen), directory), program.file);
|
|
130
|
+
const checkout = await checkoutOf(absolute);
|
|
131
|
+
return clean(checkout && !checkout.relative.startsWith('..') ? checkout.relative : path.basename(absolute));
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* The folder the chosen segment runs in. A `cd` this cannot follow (`$DIR`, `~`) ends the
|
|
135
|
+
* walk: the script is then named from where the walk stopped, or by its name alone.
|
|
136
|
+
*
|
|
137
|
+
* @param segments - The command's segments, from `segmentsOf`.
|
|
138
|
+
* @param chosen - The index of the segment whose folder is asked for: by index, as a
|
|
139
|
+
* command can repeat a segment after a `cd`.
|
|
140
|
+
* @param directory - Where the command starts.
|
|
141
|
+
* @returns The folder.
|
|
142
|
+
*/
|
|
143
|
+
export function afterCds(segments, chosen, directory) {
|
|
144
|
+
let current = directory;
|
|
145
|
+
for (const segment of segments.slice(0, chosen)) {
|
|
146
|
+
const target = RE_CD.exec(segment)?.[1]?.replace(RE_WORD_QUOTES, '');
|
|
147
|
+
if (target === undefined)
|
|
148
|
+
continue;
|
|
149
|
+
if (RE_SHELL_EXPANDED.test(target))
|
|
150
|
+
break;
|
|
151
|
+
current = path.resolve(current, target);
|
|
152
|
+
}
|
|
153
|
+
return current;
|
|
154
|
+
}
|
|
155
|
+
function clean(entry) {
|
|
156
|
+
return sanitizeText(entry).slice(0, MAX_RUN_ENTRY_LENGTH);
|
|
157
|
+
}
|