@halonicjs/testing 0.1.1 → 0.1.2
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/dist/adapters/http-kit/src/connector-host-class.d.ts +14 -0
- package/dist/adapters/http-kit/src/connector-host-class.js +34 -0
- package/dist/adapters/http-kit/src/index.d.ts +2 -0
- package/dist/adapters/http-kit/src/index.js +2 -0
- package/dist/adapters/http-kit/src/ollama-tags.d.ts +20 -0
- package/dist/adapters/http-kit/src/ollama-tags.js +38 -0
- package/dist/adapters/integration-kit/src/index.d.ts +2 -1
- package/dist/adapters/integration-kit/src/index.js +1 -0
- package/dist/adapters/integration-kit/src/loader.d.ts +2 -12
- package/dist/adapters/integration-kit/src/loader.js +3 -20
- package/dist/adapters/integration-kit/src/workspace-choices.d.ts +37 -0
- package/dist/adapters/integration-kit/src/workspace-choices.js +37 -0
- package/dist/core/events/src/connector-listing-failed.d.ts +18 -0
- package/dist/core/events/src/connector-listing-failed.js +1 -0
- package/dist/core/events/src/home-path.d.ts +4 -1
- package/dist/core/events/src/home-path.js +14 -3
- package/dist/core/events/src/index.d.ts +4 -2
- package/dist/core/events/src/index.js +2 -0
- package/dist/core/events/src/provider-notes.d.ts +16 -0
- package/dist/core/events/src/provider-notes.js +24 -0
- package/dist/core/events/src/run-basics.d.ts +103 -5
- package/dist/core/events/src/run-event.d.ts +72 -7
- package/dist/core/events/src/run-summary.d.ts +11 -1
- package/dist/core/events/src/sandbox-opened-read.d.ts +2 -1
- package/dist/core/events/src/sandbox-opened-read.js +27 -2
- package/dist/core/events/src/sandbox-opened.d.ts +37 -4
- package/dist/core/events/src/sandbox-opened.js +13 -3
- package/dist/core/events/src/summarize.js +3 -0
- package/dist/core/events/src/tool-failure-cause.d.ts +25 -0
- package/dist/core/events/src/tool-failure-cause.js +66 -0
- package/dist/core/format/src/index.d.ts +3 -2
- package/dist/core/format/src/index.js +3 -1
- package/dist/core/format/src/kinds/agent/harness-limits.d.ts +14 -0
- package/dist/core/format/src/kinds/agent/harness-limits.js +27 -0
- package/dist/core/format/src/kinds/agent/schema.d.ts +5 -0
- package/dist/core/format/src/kinds/agent/schema.js +3 -0
- package/dist/core/format/src/kinds/connector/kind.js +24 -3
- package/dist/core/format/src/kinds/connector/schema.d.ts +14 -0
- package/dist/core/format/src/kinds/connector/schema.js +18 -0
- package/dist/core/format/src/kinds/integration/schema.js +1 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.d.ts +2 -1
- package/dist/core/format/src/kinds/integration/sign-in-checks.js +33 -3
- package/dist/core/format/src/kinds/plugin/checks.d.ts +3 -2
- package/dist/core/format/src/kinds/plugin/checks.js +17 -5
- package/dist/core/format/src/kinds/plugin/schema.js +24 -4
- package/dist/core/format/src/kinds/provider/kind.js +40 -1
- package/dist/core/format/src/kinds/provider/types.d.ts +19 -0
- package/dist/core/format/src/kinds/provider/types.js +22 -0
- package/dist/core/format/src/kinds/routine/schema.d.ts +10 -5
- package/dist/core/format/src/kinds/routine/schema.js +21 -15
- package/dist/core/format/src/kinds/workspace/schema.js +5 -4
- package/dist/core/format/src/parse-file.js +3 -1
- package/dist/core/format/src/shared/fields.d.ts +9 -2
- package/dist/core/format/src/shared/fields.js +15 -6
- package/dist/core/format/src/shared/guard.d.ts +8 -0
- package/dist/core/format/src/shared/guard.js +50 -1
- package/dist/core/format/src/shared/missing-keys.d.ts +17 -0
- package/dist/core/format/src/shared/missing-keys.js +110 -0
- package/dist/core/ports/src/chat.d.ts +8 -0
- package/dist/core/ports/src/connector-start-failure.d.ts +31 -0
- package/dist/core/ports/src/connector-start-failure.js +32 -0
- package/dist/core/ports/src/connector-tool-error.d.ts +33 -0
- package/dist/core/ports/src/connector-tool-error.js +40 -0
- package/dist/core/ports/src/definition-store-left-out.d.ts +46 -0
- package/dist/core/ports/src/definition-store-left-out.js +47 -0
- package/dist/core/ports/src/definition-store.d.ts +13 -3
- package/dist/core/ports/src/definition-store.js +1 -1
- package/dist/core/ports/src/deploy-target.d.ts +358 -0
- package/dist/core/ports/src/deploy-target.js +2 -0
- package/dist/core/ports/src/harness-bridge-server.d.ts +55 -4
- package/dist/core/ports/src/harness.d.ts +33 -2
- package/dist/core/ports/src/host-too-old.d.ts +23 -0
- package/dist/core/ports/src/host-too-old.js +27 -0
- package/dist/core/ports/src/index.d.ts +16 -5
- package/dist/core/ports/src/index.js +15 -3
- package/dist/core/ports/src/llm-provider.d.ts +37 -6
- package/dist/core/ports/src/llm-provider.js +43 -3
- package/dist/core/ports/src/pairing-codes.d.ts +111 -0
- package/dist/core/ports/src/pairing-codes.js +336 -0
- package/dist/core/ports/src/pairing-qr-bytes.d.ts +32 -0
- package/dist/core/ports/src/pairing-qr-bytes.js +116 -0
- package/dist/core/ports/src/port-versions.d.ts +6 -2
- package/dist/core/ports/src/port-versions.js +8 -0
- package/dist/core/ports/src/remote-control.d.ts +159 -0
- package/dist/core/ports/src/remote-control.js +26 -0
- package/dist/core/ports/src/remote-gateway-protocol.d.ts +220 -0
- package/dist/core/ports/src/remote-gateway-protocol.js +62 -0
- package/dist/core/ports/src/remote-gateway-session.d.ts +194 -0
- package/dist/core/ports/src/remote-gateway-session.js +241 -0
- package/dist/core/ports/src/run-executor.d.ts +39 -3
- package/dist/core/ports/src/run-executor.js +1 -1
- package/dist/core/ports/src/sandbox.d.ts +19 -0
- package/dist/core/ports/src/sandbox.js +14 -0
- package/dist/core/ports/src/secrets.d.ts +32 -1
- package/dist/core/ports/src/secrets.js +19 -2
- package/dist/core/ports/src/tunnel-provider.d.ts +117 -0
- package/dist/core/ports/src/tunnel-provider.js +65 -0
- package/dist/core/ports/src/tunnel-resolver.d.ts +83 -0
- package/dist/core/ports/src/tunnel-resolver.js +36 -0
- package/dist/core/ports/src/vcs.d.ts +30 -0
- package/dist/core/schema-kit/src/builders.d.ts +5 -0
- package/dist/core/schema-kit/src/builders.js +5 -0
- package/dist/core/std/src/hidden-characters.d.ts +9 -0
- package/dist/core/std/src/hidden-characters.js +18 -0
- package/dist/core/std/src/index.d.ts +3 -1
- package/dist/core/std/src/index.js +3 -1
- package/dist/core/std/src/path-overlap.d.ts +22 -0
- package/dist/core/std/src/path-overlap.js +57 -0
- package/dist/core/std/src/public-suffixes.generated.d.ts +1 -1
- package/dist/core/std/src/public-suffixes.generated.js +0 -1
- package/dist/core/std/src/word-diff.d.ts +28 -0
- package/dist/core/std/src/word-diff.js +77 -0
- package/dist/core/yaml/src/edit-data.d.ts +7 -0
- package/dist/core/yaml/src/edit-data.js +62 -3
- package/dist/core/yaml/src/edit.d.ts +7 -0
- package/dist/core/yaml/src/edit.js +34 -3
- package/dist/core/yaml/src/splice-node.d.ts +6 -0
- package/dist/core/yaml/src/splice-node.js +10 -0
- package/dist/core/yaml/src/splice.js +20 -10
- package/dist/testing/integration/src/checks.d.ts +5 -3
- package/dist/testing/integration/src/checks.js +31 -3
- package/package.json +9 -2
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { TunnelEndpoint } from "./tunnel-provider.js";
|
|
2
|
+
/** Version of the {@link TunnelResolver} port. A breaking change bumps it and comes with an ADR. */
|
|
3
|
+
export declare const tunnelResolverVersion = 1;
|
|
4
|
+
/**
|
|
5
|
+
* How a transport waits between tries to reconnect: `firstDelayMs` after the
|
|
6
|
+
* first drop, times `factor` after each failed try, a base of at most
|
|
7
|
+
* `maxDelayMs`, each delay moved by up to `jitter` of itself either way (so
|
|
8
|
+
* up to 36 s). A connection that stays
|
|
9
|
+
* open for `resetAfterMs` starts again from `firstDelayMs`.
|
|
10
|
+
*/
|
|
11
|
+
export declare const tunnelBackoff: {
|
|
12
|
+
readonly firstDelayMs: 500;
|
|
13
|
+
readonly factor: 2;
|
|
14
|
+
readonly maxDelayMs: 30000;
|
|
15
|
+
readonly jitter: 0.2;
|
|
16
|
+
readonly resetAfterMs: 30000;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* The delay before reconnect try `attempt` (1 for the first try after a
|
|
20
|
+
* drop), by {@link tunnelBackoff}. `random` is a number from 0 up to (not
|
|
21
|
+
* including) 1, such as `Math.random()`; 0.5 gives the delay without jitter.
|
|
22
|
+
* Any other `random` (NaN, negative, 1 or more) throws a `RangeError`, since
|
|
23
|
+
* a timer would read the NaN or negative delay as 0 and reconnect in a tight
|
|
24
|
+
* loop. Every transport uses this one rule, so phones and the fake provider
|
|
25
|
+
* back off alike.
|
|
26
|
+
*/
|
|
27
|
+
export declare function tunnelReconnectDelayMs(attempt: number, random: number): number;
|
|
28
|
+
/**
|
|
29
|
+
* A transport's state. `paused` means the app went to the background: the
|
|
30
|
+
* transport closed its connection and doesn't try again until `resume`.
|
|
31
|
+
*/
|
|
32
|
+
export type TunnelTransportState = "connecting" | "open" | "reconnecting" | "paused" | "closed";
|
|
33
|
+
/**
|
|
34
|
+
* A byte pipe from the phone to one host's remote gateway, reconnecting by
|
|
35
|
+
* itself. It carries the end-to-end session's frames and never reads them.
|
|
36
|
+
*
|
|
37
|
+
* **Reconnect.** When the connection drops, the state goes to `reconnecting`
|
|
38
|
+
* and the transport tries again after {@link tunnelReconnectDelayMs}, without
|
|
39
|
+
* a limit on tries, for as long as the app is in the foreground. A frame sent
|
|
40
|
+
* while not `open` rejects; frames are never queued or sent again after a
|
|
41
|
+
* reconnect. Each reconnect is a new connection: the session layer starts a
|
|
42
|
+
* new handshake and the gateway protocol resumes its sessions from the last
|
|
43
|
+
* event it saw.
|
|
44
|
+
*
|
|
45
|
+
* **Foreground only.** `pause` closes the connection and stops every timer,
|
|
46
|
+
* because a phone (iOS above all) may freeze a background app at any moment.
|
|
47
|
+
* `resume` connects at once, with no delay, and starts the backoff from the
|
|
48
|
+
* first try.
|
|
49
|
+
*/
|
|
50
|
+
export interface TunnelTransport {
|
|
51
|
+
readonly state: TunnelTransportState;
|
|
52
|
+
/** Calls `listener` on each change of state; returns a function that stops it. */
|
|
53
|
+
onState(listener: (state: TunnelTransportState) => void): () => void;
|
|
54
|
+
/** Sends one frame. Rejects unless the state is `open`. */
|
|
55
|
+
send(frame: Uint8Array): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Every frame received, in order, across reconnects. The stream ends when
|
|
58
|
+
* the transport is closed.
|
|
59
|
+
*/
|
|
60
|
+
frames(): AsyncIterable<Uint8Array>;
|
|
61
|
+
/** Closes the connection and stops reconnecting until {@link resume}. */
|
|
62
|
+
pause(): void;
|
|
63
|
+
/** Connects again at once after {@link pause}; does nothing in any other state. */
|
|
64
|
+
resume(): void;
|
|
65
|
+
/** Closes the transport for good; the state becomes `closed`. */
|
|
66
|
+
close(): Promise<void>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Turns an endpoint from a pairing into a transport, on the phone (tunnel
|
|
70
|
+
* phase A; requirement `ports.tunnel-resolver`). It refuses with a
|
|
71
|
+
* `RangeError` an endpoint whose URL scheme isn't `https:`, `wss:` or `tcp:`.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* const transport = await resolver.resolve(pairing.endpoint);
|
|
75
|
+
* app.onBackground(() => transport.pause());
|
|
76
|
+
*/
|
|
77
|
+
export interface TunnelResolver {
|
|
78
|
+
/**
|
|
79
|
+
* Resolves once the first connection is `open`, or rejects when the first
|
|
80
|
+
* try fails; only a connection that was open once reconnects by itself.
|
|
81
|
+
*/
|
|
82
|
+
resolve(endpoint: TunnelEndpoint): Promise<TunnelTransport>;
|
|
83
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** Version of the {@link TunnelResolver} port. A breaking change bumps it and comes with an ADR. */
|
|
2
|
+
export const tunnelResolverVersion = 1;
|
|
3
|
+
/**
|
|
4
|
+
* How a transport waits between tries to reconnect: `firstDelayMs` after the
|
|
5
|
+
* first drop, times `factor` after each failed try, a base of at most
|
|
6
|
+
* `maxDelayMs`, each delay moved by up to `jitter` of itself either way (so
|
|
7
|
+
* up to 36 s). A connection that stays
|
|
8
|
+
* open for `resetAfterMs` starts again from `firstDelayMs`.
|
|
9
|
+
*/
|
|
10
|
+
export const tunnelBackoff = {
|
|
11
|
+
firstDelayMs: 500,
|
|
12
|
+
factor: 2,
|
|
13
|
+
maxDelayMs: 30_000,
|
|
14
|
+
jitter: 0.2,
|
|
15
|
+
resetAfterMs: 30_000,
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* The delay before reconnect try `attempt` (1 for the first try after a
|
|
19
|
+
* drop), by {@link tunnelBackoff}. `random` is a number from 0 up to (not
|
|
20
|
+
* including) 1, such as `Math.random()`; 0.5 gives the delay without jitter.
|
|
21
|
+
* Any other `random` (NaN, negative, 1 or more) throws a `RangeError`, since
|
|
22
|
+
* a timer would read the NaN or negative delay as 0 and reconnect in a tight
|
|
23
|
+
* loop. Every transport uses this one rule, so phones and the fake provider
|
|
24
|
+
* back off alike.
|
|
25
|
+
*/
|
|
26
|
+
export function tunnelReconnectDelayMs(attempt, random) {
|
|
27
|
+
if (!Number.isInteger(attempt) || attempt < 1) {
|
|
28
|
+
throw new RangeError(`attempt must be a whole number from 1: ${attempt}`);
|
|
29
|
+
}
|
|
30
|
+
if (!(random >= 0 && random < 1)) {
|
|
31
|
+
throw new RangeError(`random must be from 0 up to (not including) 1: ${random}`);
|
|
32
|
+
}
|
|
33
|
+
const { firstDelayMs, factor, maxDelayMs, jitter } = tunnelBackoff;
|
|
34
|
+
const base = Math.min(maxDelayMs, firstDelayMs * factor ** (attempt - 1));
|
|
35
|
+
return Math.round(base * (1 + jitter * (2 * random - 1)));
|
|
36
|
+
}
|
|
@@ -85,6 +85,25 @@ export interface VcsFileDiff {
|
|
|
85
85
|
/** Unified diff of the file, in git's format. */
|
|
86
86
|
diff: string;
|
|
87
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Where this branch and its upstream stand when both have commits the other
|
|
90
|
+
* lacks, and the items both changed.
|
|
91
|
+
*/
|
|
92
|
+
export interface VcsDivergence {
|
|
93
|
+
/** This branch's last commit. */
|
|
94
|
+
ours: string;
|
|
95
|
+
/** The upstream's last commit, as fetched: a full commit id `readAt` takes. */
|
|
96
|
+
theirs: string;
|
|
97
|
+
/** The last commit both have: where they parted. */
|
|
98
|
+
base: string;
|
|
99
|
+
/**
|
|
100
|
+
* Paths, sorted, that both sides changed since `base` (added, edited or
|
|
101
|
+
* deleted) and now hold differently: the items a person must choose for.
|
|
102
|
+
* A file only one side changed, or both changed the same way, isn't listed.
|
|
103
|
+
* Private entries are left out.
|
|
104
|
+
*/
|
|
105
|
+
items: string[];
|
|
106
|
+
}
|
|
88
107
|
/** How `applyPatch` applies a patch. */
|
|
89
108
|
export interface VcsApplyOptions {
|
|
90
109
|
/** Undo the patch instead: what discarding one hunk does. */
|
|
@@ -384,6 +403,17 @@ export interface Vcs {
|
|
|
384
403
|
* @throws when the branch and its upstream have both moved on; nothing is merged
|
|
385
404
|
*/
|
|
386
405
|
pull(): Promise<void>;
|
|
406
|
+
/**
|
|
407
|
+
* Fetches the upstream, then says where the branch and it parted, when
|
|
408
|
+
* `pull` would refuse because both have new commits; `null` when it
|
|
409
|
+
* wouldn't (nothing new either way, or only one side has commits). Changes
|
|
410
|
+
* no branch, no file and no index; only the fetched commits are new. The
|
|
411
|
+
* remote and the branch come from the repository, as for `pull`.
|
|
412
|
+
*
|
|
413
|
+
* @throws when there is no upstream, the fetch fails, or the two share no
|
|
414
|
+
* commit
|
|
415
|
+
*/
|
|
416
|
+
diverged(): Promise<VcsDivergence | null>;
|
|
387
417
|
/**
|
|
388
418
|
* Sends the branch's commits to its upstream, or to the first remote (which
|
|
389
419
|
* becomes the upstream) when it has none.
|
|
@@ -45,6 +45,11 @@ export declare const s: {
|
|
|
45
45
|
readonly lazy: typeof z.lazy;
|
|
46
46
|
/** Any JSON value: null, a boolean, a finite number, text, or a list or map of JSON values. */
|
|
47
47
|
readonly json: typeof z.json;
|
|
48
|
+
/**
|
|
49
|
+
* Changes the input before the schema checks it, such as a number into
|
|
50
|
+
* text, so the schema's own message applies. JSON Schema describes the schema.
|
|
51
|
+
*/
|
|
52
|
+
readonly preprocess: typeof z.preprocess;
|
|
48
53
|
/** An absolute `http` or `https` URL as `URL` writes it; see `URL_PATTERN`. */
|
|
49
54
|
readonly url: () => z.ZodString;
|
|
50
55
|
};
|
|
@@ -67,6 +67,11 @@ export const s = {
|
|
|
67
67
|
lazy: z.lazy,
|
|
68
68
|
/** Any JSON value: null, a boolean, a finite number, text, or a list or map of JSON values. */
|
|
69
69
|
json: z.json,
|
|
70
|
+
/**
|
|
71
|
+
* Changes the input before the schema checks it, such as a number into
|
|
72
|
+
* text, so the schema's own message applies. JSON Schema describes the schema.
|
|
73
|
+
*/
|
|
74
|
+
preprocess: z.preprocess,
|
|
70
75
|
/** An absolute `http` or `https` URL as `URL` writes it; see `URL_PATTERN`. */
|
|
71
76
|
url: () => z.string().regex(URL_PATTERN, "must be an http or https URL as URL writes it"),
|
|
72
77
|
};
|
|
@@ -17,3 +17,12 @@ export declare function isHiddenCharacter(codePoint: number): boolean;
|
|
|
17
17
|
* escapeHidden(JSON.stringify(`Refund${String.fromCodePoint(0x202e)}for Sam`)); // '"Refund\\u202efor Sam"'
|
|
18
18
|
*/
|
|
19
19
|
export declare function escapeHidden(json: string): string;
|
|
20
|
+
/**
|
|
21
|
+
* A short text, such as a name or a path, as one string with every hidden character written out
|
|
22
|
+
* as a marker like `⟦U+202E⟧`, so it can't act on the text around it. A Windows line end
|
|
23
|
+
* (`\r\n`) counts as a newline; a `\r` on its own is marked.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* markHiddenName(`create${String.fromCodePoint(0x200b)}note`); // "create⟦U+200B⟧note"
|
|
27
|
+
*/
|
|
28
|
+
export declare function markHiddenName(value: string): string;
|
|
@@ -52,3 +52,21 @@ export function escapeHidden(json) {
|
|
|
52
52
|
}
|
|
53
53
|
return escaped;
|
|
54
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* A short text, such as a name or a path, as one string with every hidden character written out
|
|
57
|
+
* as a marker like `⟦U+202E⟧`, so it can't act on the text around it. A Windows line end
|
|
58
|
+
* (`\r\n`) counts as a newline; a `\r` on its own is marked.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* markHiddenName(`create${String.fromCodePoint(0x200b)}note`); // "create⟦U+200B⟧note"
|
|
62
|
+
*/
|
|
63
|
+
export function markHiddenName(value) {
|
|
64
|
+
let marked = "";
|
|
65
|
+
for (const character of value.replace(/\r\n/g, "\n")) {
|
|
66
|
+
const point = character.codePointAt(0) ?? 0;
|
|
67
|
+
marked += isHiddenCharacter(point)
|
|
68
|
+
? `⟦U+${point.toString(16).toUpperCase().padStart(4, "0")}⟧`
|
|
69
|
+
: character;
|
|
70
|
+
}
|
|
71
|
+
return marked;
|
|
72
|
+
}
|
|
@@ -11,11 +11,12 @@ export { deepEqual } from "./deep-equal.js";
|
|
|
11
11
|
export { Emitter, type Listener } from "./emitter.js";
|
|
12
12
|
export { type ErrorKind, errorKindOf, errorKinds, isErrorKind, KindedError, } from "./error-kind.js";
|
|
13
13
|
export { bytesToHex } from "./hex.js";
|
|
14
|
-
export { escapeHidden, isHiddenCharacter } from "./hidden-characters.js";
|
|
14
|
+
export { escapeHidden, isHiddenCharacter, markHiddenName } from "./hidden-characters.js";
|
|
15
15
|
export { fixedIds, type IdGenerator, type RandomBytes, randomIds } from "./ids.js";
|
|
16
16
|
export { KeyedQueue } from "./keyed-queue.js";
|
|
17
17
|
export { applyLineChanges, type DiffLinesOptions, diffLines, type LineChange, MAX_COMPARED_LINE_PAIRS, splitLines, } from "./line-diff.js";
|
|
18
18
|
export { hasConflicts, type MergeLinesOptions, type MergeRegion, mergedText, mergeLines, } from "./line-merge.js";
|
|
19
|
+
export { absolutePathsOverlap, insideOrSame } from "./path-overlap.js";
|
|
19
20
|
export { describeObject, isPlainObject, keyPath } from "./plain-data.js";
|
|
20
21
|
export { posixPath } from "./posix-path.js";
|
|
21
22
|
export { type Err, err, mapResult, type Ok, ok, type Result, unwrap } from "./result.js";
|
|
@@ -28,3 +29,4 @@ export { slugify, uniqueName } from "./text.js";
|
|
|
28
29
|
export { type UrlHost, urlHost } from "./url-host.js";
|
|
29
30
|
export { decodeUtf8, encodeUtf8 } from "./utf8.js";
|
|
30
31
|
export { compareVersions, formatVersion, isAtLeast, readVersion, type Version } from "./version.js";
|
|
32
|
+
export { diffWords, type WordDiff, type WordPiece } from "./word-diff.js";
|
|
@@ -12,11 +12,12 @@ export { deepEqual } from "./deep-equal.js";
|
|
|
12
12
|
export { Emitter } from "./emitter.js";
|
|
13
13
|
export { errorKindOf, errorKinds, isErrorKind, KindedError, } from "./error-kind.js";
|
|
14
14
|
export { bytesToHex } from "./hex.js";
|
|
15
|
-
export { escapeHidden, isHiddenCharacter } from "./hidden-characters.js";
|
|
15
|
+
export { escapeHidden, isHiddenCharacter, markHiddenName } from "./hidden-characters.js";
|
|
16
16
|
export { fixedIds, randomIds } from "./ids.js";
|
|
17
17
|
export { KeyedQueue } from "./keyed-queue.js";
|
|
18
18
|
export { applyLineChanges, diffLines, MAX_COMPARED_LINE_PAIRS, splitLines, } from "./line-diff.js";
|
|
19
19
|
export { hasConflicts, mergedText, mergeLines, } from "./line-merge.js";
|
|
20
|
+
export { absolutePathsOverlap, insideOrSame } from "./path-overlap.js";
|
|
20
21
|
export { describeObject, isPlainObject, keyPath } from "./plain-data.js";
|
|
21
22
|
export { posixPath } from "./posix-path.js";
|
|
22
23
|
export { err, mapResult, ok, unwrap } from "./result.js";
|
|
@@ -29,3 +30,4 @@ export { slugify, uniqueName } from "./text.js";
|
|
|
29
30
|
export { urlHost } from "./url-host.js";
|
|
30
31
|
export { decodeUtf8, encodeUtf8 } from "./utf8.js";
|
|
31
32
|
export { compareVersions, formatVersion, isAtLeast, readVersion } from "./version.js";
|
|
33
|
+
export { diffWords } from "./word-diff.js";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether `a` is on, above or inside `b`: the same path, a folder holding
|
|
3
|
+
* it, or a path inside it, after `.` and `..` are resolved. Both paths are
|
|
4
|
+
* absolute, such as `/person/.ssh` or `C:/Work`.
|
|
5
|
+
*
|
|
6
|
+
* The paths are compared as Windows reads them, on every system: letter
|
|
7
|
+
* case is ignored and `/` and `\` both separate folders. Elsewhere that
|
|
8
|
+
* finds a few more paths overlapping than it must, never fewer. Links are
|
|
9
|
+
* not followed.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* absolutePathsOverlap("/person", "/person/.ssh"); // true: it holds it
|
|
13
|
+
* absolutePathsOverlap("/person/.ssh-notes", "/person/.ssh"); // false
|
|
14
|
+
* absolutePathsOverlap("C:/Work/Acme", "c:/WORK/acme/x"); // true
|
|
15
|
+
*/
|
|
16
|
+
export declare function absolutePathsOverlap(a: string, b: string): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Whether `child` is `parent` or lies inside it, as Windows reads paths:
|
|
19
|
+
* without regard to letter case, with `/` and `\` both as separators. Both
|
|
20
|
+
* paths should be resolved first.
|
|
21
|
+
*/
|
|
22
|
+
export declare function insideOrSame(parent: string, child: string): boolean;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Whether two absolute paths overlap, the way Windows reads them, on every
|
|
2
|
+
// system: the one rule for a folder near a place it must stay clear of. Pure,
|
|
3
|
+
// so the core can use it too; `@halonicjs/adapter-system-node` resolves
|
|
4
|
+
// relative paths and links around it (`pathsOverlap`, `bothSpellings`).
|
|
5
|
+
/**
|
|
6
|
+
* Whether `a` is on, above or inside `b`: the same path, a folder holding
|
|
7
|
+
* it, or a path inside it, after `.` and `..` are resolved. Both paths are
|
|
8
|
+
* absolute, such as `/person/.ssh` or `C:/Work`.
|
|
9
|
+
*
|
|
10
|
+
* The paths are compared as Windows reads them, on every system: letter
|
|
11
|
+
* case is ignored and `/` and `\` both separate folders. Elsewhere that
|
|
12
|
+
* finds a few more paths overlapping than it must, never fewer. Links are
|
|
13
|
+
* not followed.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* absolutePathsOverlap("/person", "/person/.ssh"); // true: it holds it
|
|
17
|
+
* absolutePathsOverlap("/person/.ssh-notes", "/person/.ssh"); // false
|
|
18
|
+
* absolutePathsOverlap("C:/Work/Acme", "c:/WORK/acme/x"); // true
|
|
19
|
+
*/
|
|
20
|
+
export function absolutePathsOverlap(a, b) {
|
|
21
|
+
const first = asWindowsReadsIt(a);
|
|
22
|
+
const second = asWindowsReadsIt(b);
|
|
23
|
+
return insideOrSame(first, second) || insideOrSame(second, first);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Whether `child` is `parent` or lies inside it, as Windows reads paths:
|
|
27
|
+
* without regard to letter case, with `/` and `\` both as separators. Both
|
|
28
|
+
* paths should be resolved first.
|
|
29
|
+
*/
|
|
30
|
+
export function insideOrSame(parent, child) {
|
|
31
|
+
const base = parent.toLowerCase();
|
|
32
|
+
const path = child.toLowerCase();
|
|
33
|
+
return path === base || path.startsWith(base.endsWith("\\") ? base : `${base}\\`);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* An absolute path with `\` between its names, `.`, `..` and repeated
|
|
37
|
+
* separators resolved, and no `\` at the end but for a root: `/a/./b/` is
|
|
38
|
+
* `\a\b`. The leading separators are kept, so a `\\server\share` path stays
|
|
39
|
+
* one, and a `..` never takes away a drive such as `C:`.
|
|
40
|
+
*/
|
|
41
|
+
function asWindowsReadsIt(path) {
|
|
42
|
+
const unified = path.replaceAll("/", "\\");
|
|
43
|
+
const lead = /^\\*/u.exec(unified)?.[0] ?? "";
|
|
44
|
+
const names = [];
|
|
45
|
+
for (const name of unified.slice(lead.length).split("\\")) {
|
|
46
|
+
if (name === "" || name === ".")
|
|
47
|
+
continue;
|
|
48
|
+
if (name === "..") {
|
|
49
|
+
if (names.length > 1 || (names.length === 1 && !names[0]?.endsWith(":")))
|
|
50
|
+
names.pop();
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
names.push(name);
|
|
54
|
+
}
|
|
55
|
+
const drive = names.length === 1 && names[0]?.endsWith(":") === true;
|
|
56
|
+
return lead + names.join("\\") + (drive ? "\\" : "");
|
|
57
|
+
}
|