maka-agent 0.2.0-dev.30.20260912 → 0.2.0-dev.31.20260913
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/THIRD_PARTY_NOTICES.txt +392 -0
- package/dist/acp/maka-acp-agent.js +8 -2
- package/dist/acp/prompt-content.js +225 -0
- package/dist/acp/session-event-mapper.js +103 -0
- package/dist/acp/session-registry.js +654 -17
- package/dist/acp/stdio-server.js +10 -1
- package/dist/cli-core.js +1 -1
- package/dist/pi-transcript-tools.js +3 -2
- package/dist/pi-transcript.js +12 -2
- package/dist/runtime-host-session-channel.js +63 -9
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/artifacts.js +6 -0
- package/node_modules/@maka/core/dist/attachments.js +7 -2
- package/node_modules/@maka/core/dist/durable-tool-result-projection.js +3 -1
- package/node_modules/@maka/core/dist/events.js +21 -0
- package/node_modules/@maka/core/dist/goal.js +44 -2
- package/node_modules/@maka/core/dist/permission.js +0 -1
- package/node_modules/@maka/core/dist/runtime-boundary.js +73 -29
- package/node_modules/@maka/core/dist/runtime-event.js +6 -3
- package/node_modules/@maka/core/dist/runtime-handoff.js +10 -2
- package/node_modules/@maka/core/dist/runtime-logical-execution.js +39 -14
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +3 -1
- package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
- package/node_modules/@maka/core/dist/unified-diff.js +33 -26
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +49 -178
- package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +7 -2
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +15 -53
- package/node_modules/@maka/runtime/dist/bash-model-output.js +7 -1
- package/node_modules/@maka/runtime/dist/bash-tail-buffer.js +13 -52
- package/node_modules/@maka/runtime/dist/builtin-tools.js +59 -111
- package/node_modules/@maka/runtime/dist/child-fd-input.js +3 -2
- package/node_modules/@maka/runtime/dist/context-budget-policy.js +1 -11
- package/node_modules/@maka/runtime/dist/context-budget.js +12 -1
- package/node_modules/@maka/runtime/dist/conversation-copy.js +104 -9
- package/node_modules/@maka/runtime/dist/filesystem-executor.js +10 -6
- package/node_modules/@maka/runtime/dist/filesystem-worker/client.js +77 -19
- package/node_modules/@maka/runtime/dist/filesystem-worker/launch-spec.js +66 -55
- package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +34 -97
- package/node_modules/@maka/runtime/dist/filesystem-worker/protocol.js +25 -10
- package/node_modules/@maka/runtime/dist/filesystem-worker/worker-entry.js +2 -0
- package/node_modules/@maka/runtime/dist/glob-search.js +74 -0
- package/node_modules/@maka/runtime/dist/goal-continuation.js +78 -8
- package/node_modules/@maka/runtime/dist/goal-state.js +7 -0
- package/node_modules/@maka/runtime/dist/grep-search.js +155 -0
- package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +84 -94
- package/node_modules/@maka/runtime/dist/model-history.js +25 -3
- package/node_modules/@maka/runtime/dist/pipe-tail-collector.js +6 -9
- package/node_modules/@maka/runtime/dist/read-page.js +231 -0
- package/node_modules/@maka/runtime/dist/request-projection.js +2 -15
- package/node_modules/@maka/runtime/dist/ripgrep-executable.js +62 -0
- package/node_modules/@maka/runtime/dist/ripgrep-guidance.js +81 -0
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +187 -20
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +2 -1
- package/node_modules/@maka/runtime/dist/sandbox/linux-profile-path.js +7 -1
- package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +20 -5
- package/node_modules/@maka/runtime/dist/session-manager.js +6 -6
- package/node_modules/@maka/runtime/dist/session-recap.js +9 -5
- package/node_modules/@maka/runtime/dist/shell-exec.js +7 -25
- package/node_modules/@maka/runtime/dist/shell-run-manager.js +1 -1
- package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +1 -1
- package/node_modules/@maka/runtime/dist/shell-tools.js +6 -12
- package/node_modules/@maka/runtime/dist/tool-availability.js +0 -1
- package/node_modules/@maka/runtime/dist/tool-output.js +1 -1
- package/node_modules/@maka/runtime/dist/tool-result-archive-capability.js +24 -36
- package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +32 -527
- package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +17 -119
- package/node_modules/@maka/runtime/dist/tool-result-archive.js +7 -25
- package/node_modules/@maka/runtime/dist/tool-runtime.js +7 -5
- package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +6933 -3681
- package/node_modules/@maka/runtime/dist/workspace-executor.js +20 -24
- package/node_modules/@maka/runtime/package.json +2 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +185 -191
- package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +3 -0
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +5 -1
- package/node_modules/@maka/runtime-host/dist/protocol/message.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +2 -2
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +10 -2
- package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +38 -0
- package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +2 -8
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +2 -0
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +81 -7
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +13 -13
- package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +65 -0
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +5 -2
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +88 -72
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +21 -4
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +145 -1
- package/node_modules/@maka/storage/dist/agent-run-store.js +5 -2
- package/node_modules/@maka/storage/dist/execution-stores.js +2 -1
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +27 -14
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +69 -3
- package/node_modules/balanced-match/LICENSE.md +23 -0
- package/node_modules/balanced-match/README.md +57 -0
- package/node_modules/balanced-match/dist/commonjs/index.js +59 -0
- package/node_modules/balanced-match/dist/commonjs/package.json +3 -0
- package/node_modules/balanced-match/dist/esm/index.js +54 -0
- package/node_modules/balanced-match/dist/esm/package.json +3 -0
- package/node_modules/balanced-match/package.json +68 -0
- package/node_modules/brace-expansion/LICENSE +23 -0
- package/node_modules/brace-expansion/README.md +105 -0
- package/node_modules/brace-expansion/dist/commonjs/index.js +289 -0
- package/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
- package/node_modules/brace-expansion/dist/esm/index.js +285 -0
- package/node_modules/brace-expansion/dist/esm/package.json +3 -0
- package/node_modules/brace-expansion/package.json +64 -0
- package/node_modules/glob/LICENSE.md +63 -0
- package/node_modules/glob/README.md +1203 -0
- package/node_modules/glob/dist/commonjs/glob.js +248 -0
- package/node_modules/glob/dist/commonjs/has-magic.js +27 -0
- package/node_modules/glob/dist/commonjs/ignore.js +119 -0
- package/node_modules/glob/dist/commonjs/index.js +68 -0
- package/node_modules/glob/dist/commonjs/index.min.js +4 -0
- package/node_modules/glob/dist/commonjs/package.json +3 -0
- package/node_modules/glob/dist/commonjs/pattern.js +223 -0
- package/node_modules/glob/dist/commonjs/processor.js +301 -0
- package/node_modules/glob/dist/commonjs/walker.js +387 -0
- package/node_modules/glob/dist/esm/glob.js +244 -0
- package/node_modules/glob/dist/esm/has-magic.js +23 -0
- package/node_modules/glob/dist/esm/ignore.js +115 -0
- package/node_modules/glob/dist/esm/index.js +55 -0
- package/node_modules/glob/dist/esm/index.min.js +4 -0
- package/node_modules/glob/dist/esm/package.json +3 -0
- package/node_modules/glob/dist/esm/pattern.js +219 -0
- package/node_modules/glob/dist/esm/processor.js +294 -0
- package/node_modules/glob/dist/esm/walker.js +381 -0
- package/node_modules/glob/package.json +98 -0
- package/node_modules/minimatch/LICENSE.md +55 -0
- package/node_modules/minimatch/README.md +528 -0
- package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
- package/node_modules/minimatch/dist/commonjs/ast.js +845 -0
- package/node_modules/minimatch/dist/commonjs/brace-expressions.js +150 -0
- package/node_modules/minimatch/dist/commonjs/escape.js +30 -0
- package/node_modules/minimatch/dist/commonjs/index.js +1127 -0
- package/node_modules/minimatch/dist/commonjs/package.json +3 -0
- package/node_modules/minimatch/dist/commonjs/unescape.js +38 -0
- package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
- package/node_modules/minimatch/dist/esm/ast.js +841 -0
- package/node_modules/minimatch/dist/esm/brace-expressions.js +146 -0
- package/node_modules/minimatch/dist/esm/escape.js +26 -0
- package/node_modules/minimatch/dist/esm/index.js +1114 -0
- package/node_modules/minimatch/dist/esm/package.json +3 -0
- package/node_modules/minimatch/dist/esm/unescape.js +34 -0
- package/node_modules/minimatch/package.json +73 -0
- package/node_modules/minipass/LICENSE.md +55 -0
- package/node_modules/minipass/README.md +825 -0
- package/node_modules/minipass/dist/commonjs/index.js +1038 -0
- package/node_modules/minipass/dist/commonjs/package.json +3 -0
- package/node_modules/minipass/dist/esm/index.js +1020 -0
- package/node_modules/minipass/dist/esm/package.json +3 -0
- package/node_modules/minipass/package.json +77 -0
- package/node_modules/path-scurry/LICENSE.md +55 -0
- package/node_modules/path-scurry/README.md +636 -0
- package/node_modules/path-scurry/dist/commonjs/index.js +2018 -0
- package/node_modules/path-scurry/dist/commonjs/package.json +3 -0
- package/node_modules/path-scurry/dist/esm/index.js +1983 -0
- package/node_modules/path-scurry/dist/esm/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/LICENSE.md +55 -0
- package/node_modules/path-scurry/node_modules/lru-cache/README.md +469 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +3 -0
- package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
- package/node_modules/path-scurry/node_modules/lru-cache/package.json +154 -0
- package/node_modules/path-scurry/package.json +72 -0
- package/package.json +1 -1
- package/node_modules/@maka/runtime/dist/active-tool-result-prune.js +0 -248
- package/node_modules/@maka/runtime/dist/active-tool-result-working-set.js +0 -218
- package/node_modules/@maka/runtime/dist/archive-read-tool.js +0 -115
|
@@ -28,7 +28,7 @@ import { RunSealedError, RUNTIME_CONTINUATION_AUTHORITY_V1, TOOL_RECOVERY_BUNDLE
|
|
|
28
28
|
import { canonicalToolArgsHash, stableJsonStringify } from '@maka/core/tool-args-identity';
|
|
29
29
|
import { encodeCanonicalRuntimeEvent } from '@maka/core/canonical-runtime-event';
|
|
30
30
|
import { scanToolLedger, ToolLedgerCorruptionError, ToolLedgerRejectionError, validateGenericToolLedgerAppend, validateToolLedgerEventLane, validateToolLedgerTransition, } from '@maka/core/tool-ledger-scanner';
|
|
31
|
-
import { buildImmutableRuntimePrefix, continuationStartEventMatchesClaim, decodeContinuationClaim, } from '@maka/core/runtime-boundary';
|
|
31
|
+
import { buildImmutableRuntimePrefix, buildImmutableRuntimePrefixProof, continuationStartEventMatchesClaim, decodeContinuationClaim, } from '@maka/core/runtime-boundary';
|
|
32
32
|
import { assertToolRecoveryEventBundle, interpretScannedToolRecovery, } from '@maka/core/tool-recovery-bundle';
|
|
33
33
|
import { configureSqliteRuntimeDatabase, migrateSqliteRuntimeDatabase, readUserVersion, RUNTIME_RECOVERY_AUTHORITY_CAPABILITY, RUNTIME_RECOVERY_AUTHORITY_CAPABILITY_VERSION, RUNTIME_CONTINUATION_AUTHORITY_CAPABILITY, RUNTIME_CONTINUATION_AUTHORITY_CAPABILITY_VERSION, RUNTIME_WORKSPACE_VERSION_AUTHORITY_CAPABILITY, RUNTIME_WORKSPACE_VERSION_AUTHORITY_CAPABILITY_VERSION, runtimeEventKind, SQLITE_RUNTIME_SCHEMA_VERSION, } from './sqlite-runtime-schema.js';
|
|
34
34
|
import { registerWorkspaceBaselineAuthorityWriterInternal, } from './workspace-version-authority-internal.js';
|
|
@@ -46,6 +46,13 @@ function assertRuntimeEventScanBudget(budget) {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
+
function assertImmutableRuntimePrefixProofReadBudget(budget) {
|
|
50
|
+
for (const [name, value] of Object.entries(budget)) {
|
|
51
|
+
if (!Number.isSafeInteger(value) || value < 1) {
|
|
52
|
+
throw new Error(`Invalid immutable RuntimeEvent prefix proof ${name}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
49
56
|
function requireRuntimeEventScanCount(value) {
|
|
50
57
|
if (!Number.isSafeInteger(value) || value < 0) {
|
|
51
58
|
throw new Error('Invalid RuntimeEvent scan measurement');
|
|
@@ -294,10 +301,10 @@ export class SqliteRuntimeStore {
|
|
|
294
301
|
assertRuntimeStorageSafeId(sessionId, 'Invalid session id');
|
|
295
302
|
return this.readTransaction(() => this.transcriptQuery().highWater(sessionId));
|
|
296
303
|
}
|
|
297
|
-
async readTranscriptInvocations(sessionId, request) {
|
|
304
|
+
async readTranscriptInvocations(sessionId, request, project) {
|
|
298
305
|
assertRuntimeStorageSafeId(sessionId, 'Invalid session id');
|
|
299
306
|
assertInvocationSearchLimit(request.limit);
|
|
300
|
-
return this.readTransaction(() => this.transcriptQuery().invocations(sessionId, request));
|
|
307
|
+
return this.readTransaction(() => this.transcriptQuery().invocations(sessionId, request, project));
|
|
301
308
|
}
|
|
302
309
|
async readTranscriptLandmarks(sessionId, throughOrdinal, limit) {
|
|
303
310
|
assertRuntimeStorageSafeId(sessionId, 'Invalid session id');
|
|
@@ -798,6 +805,65 @@ export class SqliteRuntimeStore {
|
|
|
798
805
|
turnId: first.turnId,
|
|
799
806
|
}, decoded);
|
|
800
807
|
}
|
|
808
|
+
async readImmutableRuntimePrefixProof(input, budget) {
|
|
809
|
+
assertImmutableRuntimePrefixProofReadBudget(budget);
|
|
810
|
+
if (input.upToEventSeq !== undefined &&
|
|
811
|
+
(!Number.isSafeInteger(input.upToEventSeq) || input.upToEventSeq <= 0)) {
|
|
812
|
+
throw new Error('Invalid immutable RuntimeEvent prefix high-water');
|
|
813
|
+
}
|
|
814
|
+
const highWater = input.upToEventSeq ?? null;
|
|
815
|
+
const cursor = this.db
|
|
816
|
+
.prepare(`
|
|
817
|
+
SELECT event_id, session_id, invocation_id, run_id, turn_id, event_seq,
|
|
818
|
+
length(CAST(payload_json AS BLOB)) AS stored_bytes,
|
|
819
|
+
CASE WHEN length(CAST(payload_json AS BLOB)) <= ? THEN payload_json END AS payload_json
|
|
820
|
+
FROM runtime_events
|
|
821
|
+
WHERE session_id = ? AND run_id = ?
|
|
822
|
+
AND (? IS NULL OR event_seq <= ?)
|
|
823
|
+
ORDER BY event_seq ASC
|
|
824
|
+
`)
|
|
825
|
+
.iterate(budget.maxRecordBytes, input.sessionId, input.runId, highWater, highWater)[Symbol.iterator]();
|
|
826
|
+
const firstRow = cursor.next();
|
|
827
|
+
if (firstRow.done)
|
|
828
|
+
throw new Error('immutable RuntimeEvent prefix is empty');
|
|
829
|
+
let count = 0;
|
|
830
|
+
let bytes = 0;
|
|
831
|
+
let lastEventSeq = 0;
|
|
832
|
+
const decode = function* () {
|
|
833
|
+
let step = firstRow;
|
|
834
|
+
while (!step.done) {
|
|
835
|
+
const row = step.value;
|
|
836
|
+
count += 1;
|
|
837
|
+
if (count > budget.maxEvents) {
|
|
838
|
+
throw new Error('Immutable RuntimeEvent prefix proof exceeds its event limit');
|
|
839
|
+
}
|
|
840
|
+
const payloadJson = row.payload_json;
|
|
841
|
+
if (payloadJson === null) {
|
|
842
|
+
throw new Error('Immutable RuntimeEvent prefix proof exceeds its record byte limit');
|
|
843
|
+
}
|
|
844
|
+
bytes += requireRuntimeEventScanCount(row.stored_bytes);
|
|
845
|
+
if (bytes > budget.maxBytes) {
|
|
846
|
+
throw new Error('Immutable RuntimeEvent prefix proof exceeds its byte limit');
|
|
847
|
+
}
|
|
848
|
+
lastEventSeq = requireRuntimeEventScanCount(row.event_seq);
|
|
849
|
+
yield {
|
|
850
|
+
eventSeq: lastEventSeq,
|
|
851
|
+
event: decodeRuntimeEventStorageRow({ ...row, payload_json: payloadJson }),
|
|
852
|
+
};
|
|
853
|
+
step = cursor.next();
|
|
854
|
+
}
|
|
855
|
+
};
|
|
856
|
+
const proof = buildImmutableRuntimePrefixProof({
|
|
857
|
+
sessionId: firstRow.value.session_id,
|
|
858
|
+
invocationId: firstRow.value.invocation_id,
|
|
859
|
+
runId: firstRow.value.run_id,
|
|
860
|
+
turnId: firstRow.value.turn_id,
|
|
861
|
+
}, decode());
|
|
862
|
+
if (input.upToEventSeq !== undefined && lastEventSeq !== input.upToEventSeq) {
|
|
863
|
+
throw new Error(`immutable RuntimeEvent prefix high-water ${input.upToEventSeq} is unavailable`);
|
|
864
|
+
}
|
|
865
|
+
return proof;
|
|
866
|
+
}
|
|
801
867
|
async claimContinuation(input) {
|
|
802
868
|
const claim = decodeContinuationClaim(input.claim);
|
|
803
869
|
if (claim.target.sessionId === WORKSPACE_AUTHORITY_SESSION_ID ||
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
(MIT)
|
|
2
|
+
|
|
3
|
+
Original code Copyright Julian Gruber <julian@juliangruber.com>
|
|
4
|
+
|
|
5
|
+
Port to TypeScript Copyright Isaac Z. Schlueter <i@izs.me>
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
8
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
9
|
+
the Software without restriction, including without limitation the rights to
|
|
10
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
11
|
+
of the Software, and to permit persons to whom the Software is furnished to do
|
|
12
|
+
so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# balanced-match
|
|
2
|
+
|
|
3
|
+
Match balanced string pairs, like `{` and `}` or `<b>` and
|
|
4
|
+
`</b>`. Supports regular expressions as well!
|
|
5
|
+
|
|
6
|
+
## Example
|
|
7
|
+
|
|
8
|
+
Get the first matching pair of braces:
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
import { balanced } from 'balanced-match'
|
|
12
|
+
|
|
13
|
+
console.log(balanced('{', '}', 'pre{in{nested}}post'))
|
|
14
|
+
console.log(balanced('{', '}', 'pre{first}between{second}post'))
|
|
15
|
+
console.log(
|
|
16
|
+
balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'),
|
|
17
|
+
)
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
The matches are:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
$ node example.js
|
|
24
|
+
{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }
|
|
25
|
+
{ start: 3,
|
|
26
|
+
end: 9,
|
|
27
|
+
pre: 'pre',
|
|
28
|
+
body: 'first',
|
|
29
|
+
post: 'between{second}post' }
|
|
30
|
+
{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## API
|
|
34
|
+
|
|
35
|
+
### const m = balanced(a, b, str)
|
|
36
|
+
|
|
37
|
+
For the first non-nested matching pair of `a` and `b` in `str`, return an
|
|
38
|
+
object with those keys:
|
|
39
|
+
|
|
40
|
+
- **start** the index of the first match of `a`
|
|
41
|
+
- **end** the index of the matching `b`
|
|
42
|
+
- **pre** the preamble, `a` and `b` not included
|
|
43
|
+
- **body** the match, `a` and `b` not included
|
|
44
|
+
- **post** the postscript, `a` and `b` not included
|
|
45
|
+
|
|
46
|
+
If there's no match, `undefined` will be returned.
|
|
47
|
+
|
|
48
|
+
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.
|
|
49
|
+
|
|
50
|
+
### const r = balanced.range(a, b, str)
|
|
51
|
+
|
|
52
|
+
For the first non-nested matching pair of `a` and `b` in `str`, return an
|
|
53
|
+
array with indexes: `[ <a index>, <b index> ]`.
|
|
54
|
+
|
|
55
|
+
If there's no match, `undefined` will be returned.
|
|
56
|
+
|
|
57
|
+
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `[ 1, 3 ]` and `{a}}` will match `[0, 2]`.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.range = exports.balanced = void 0;
|
|
4
|
+
const balanced = (a, b, str) => {
|
|
5
|
+
const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
|
|
6
|
+
const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
|
|
7
|
+
const r = ma !== null && mb != null && (0, exports.range)(ma, mb, str);
|
|
8
|
+
return (r && {
|
|
9
|
+
start: r[0],
|
|
10
|
+
end: r[1],
|
|
11
|
+
pre: str.slice(0, r[0]),
|
|
12
|
+
body: str.slice(r[0] + ma.length, r[1]),
|
|
13
|
+
post: str.slice(r[1] + mb.length),
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
exports.balanced = balanced;
|
|
17
|
+
const maybeMatch = (reg, str) => {
|
|
18
|
+
const m = str.match(reg);
|
|
19
|
+
return m ? m[0] : null;
|
|
20
|
+
};
|
|
21
|
+
const range = (a, b, str) => {
|
|
22
|
+
let begs, beg, left, right = undefined, result;
|
|
23
|
+
let ai = str.indexOf(a);
|
|
24
|
+
let bi = str.indexOf(b, ai + 1);
|
|
25
|
+
let i = ai;
|
|
26
|
+
if (ai >= 0 && bi > 0) {
|
|
27
|
+
if (a === b) {
|
|
28
|
+
return [ai, bi];
|
|
29
|
+
}
|
|
30
|
+
begs = [];
|
|
31
|
+
left = str.length;
|
|
32
|
+
while (i >= 0 && !result) {
|
|
33
|
+
if (i === ai) {
|
|
34
|
+
begs.push(i);
|
|
35
|
+
ai = str.indexOf(a, i + 1);
|
|
36
|
+
}
|
|
37
|
+
else if (begs.length === 1) {
|
|
38
|
+
const r = begs.pop();
|
|
39
|
+
if (r !== undefined)
|
|
40
|
+
result = [r, bi];
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
beg = begs.pop();
|
|
44
|
+
if (beg !== undefined && beg < left) {
|
|
45
|
+
left = beg;
|
|
46
|
+
right = bi;
|
|
47
|
+
}
|
|
48
|
+
bi = str.indexOf(b, i + 1);
|
|
49
|
+
}
|
|
50
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
|
51
|
+
}
|
|
52
|
+
if (begs.length && right !== undefined) {
|
|
53
|
+
result = [left, right];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return result;
|
|
57
|
+
};
|
|
58
|
+
exports.range = range;
|
|
59
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export const balanced = (a, b, str) => {
|
|
2
|
+
const ma = a instanceof RegExp ? maybeMatch(a, str) : a;
|
|
3
|
+
const mb = b instanceof RegExp ? maybeMatch(b, str) : b;
|
|
4
|
+
const r = ma !== null && mb != null && range(ma, mb, str);
|
|
5
|
+
return (r && {
|
|
6
|
+
start: r[0],
|
|
7
|
+
end: r[1],
|
|
8
|
+
pre: str.slice(0, r[0]),
|
|
9
|
+
body: str.slice(r[0] + ma.length, r[1]),
|
|
10
|
+
post: str.slice(r[1] + mb.length),
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
const maybeMatch = (reg, str) => {
|
|
14
|
+
const m = str.match(reg);
|
|
15
|
+
return m ? m[0] : null;
|
|
16
|
+
};
|
|
17
|
+
export const range = (a, b, str) => {
|
|
18
|
+
let begs, beg, left, right = undefined, result;
|
|
19
|
+
let ai = str.indexOf(a);
|
|
20
|
+
let bi = str.indexOf(b, ai + 1);
|
|
21
|
+
let i = ai;
|
|
22
|
+
if (ai >= 0 && bi > 0) {
|
|
23
|
+
if (a === b) {
|
|
24
|
+
return [ai, bi];
|
|
25
|
+
}
|
|
26
|
+
begs = [];
|
|
27
|
+
left = str.length;
|
|
28
|
+
while (i >= 0 && !result) {
|
|
29
|
+
if (i === ai) {
|
|
30
|
+
begs.push(i);
|
|
31
|
+
ai = str.indexOf(a, i + 1);
|
|
32
|
+
}
|
|
33
|
+
else if (begs.length === 1) {
|
|
34
|
+
const r = begs.pop();
|
|
35
|
+
if (r !== undefined)
|
|
36
|
+
result = [r, bi];
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
beg = begs.pop();
|
|
40
|
+
if (beg !== undefined && beg < left) {
|
|
41
|
+
left = beg;
|
|
42
|
+
right = bi;
|
|
43
|
+
}
|
|
44
|
+
bi = str.indexOf(b, i + 1);
|
|
45
|
+
}
|
|
46
|
+
i = ai < bi && ai >= 0 ? ai : bi;
|
|
47
|
+
}
|
|
48
|
+
if (begs.length && right !== undefined) {
|
|
49
|
+
result = [left, right];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "balanced-match",
|
|
3
|
+
"description": "Match balanced character pairs, like \"{\" and \"}\"",
|
|
4
|
+
"version": "4.0.4",
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git://github.com/juliangruber/balanced-match.git"
|
|
11
|
+
},
|
|
12
|
+
"exports": {
|
|
13
|
+
"./package.json": "./package.json",
|
|
14
|
+
".": {
|
|
15
|
+
"import": {
|
|
16
|
+
"types": "./dist/esm/index.d.ts",
|
|
17
|
+
"default": "./dist/esm/index.js"
|
|
18
|
+
},
|
|
19
|
+
"require": {
|
|
20
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
21
|
+
"default": "./dist/commonjs/index.js"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"type": "module",
|
|
26
|
+
"scripts": {
|
|
27
|
+
"preversion": "npm test",
|
|
28
|
+
"postversion": "npm publish",
|
|
29
|
+
"prepublishOnly": "git push origin --follow-tags",
|
|
30
|
+
"prepare": "tshy",
|
|
31
|
+
"pretest": "npm run prepare",
|
|
32
|
+
"presnap": "npm run prepare",
|
|
33
|
+
"test": "tap",
|
|
34
|
+
"snap": "tap",
|
|
35
|
+
"format": "prettier --write .",
|
|
36
|
+
"benchmark": "node benchmark/index.js",
|
|
37
|
+
"typedoc": "typedoc --tsconfig .tshy/esm.json ./src/*.ts"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/brace-expansion": "^1.1.2",
|
|
41
|
+
"@types/node": "^25.2.1",
|
|
42
|
+
"mkdirp": "^3.0.1",
|
|
43
|
+
"prettier": "^3.3.2",
|
|
44
|
+
"tap": "^21.6.2",
|
|
45
|
+
"tshy": "^3.0.2",
|
|
46
|
+
"typedoc": "^0.28.5"
|
|
47
|
+
},
|
|
48
|
+
"keywords": [
|
|
49
|
+
"match",
|
|
50
|
+
"regexp",
|
|
51
|
+
"test",
|
|
52
|
+
"balanced",
|
|
53
|
+
"parse"
|
|
54
|
+
],
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": "18 || 20 || >=22"
|
|
58
|
+
},
|
|
59
|
+
"tshy": {
|
|
60
|
+
"exports": {
|
|
61
|
+
"./package.json": "./package.json",
|
|
62
|
+
".": "./src/index.ts"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"main": "./dist/commonjs/index.js",
|
|
66
|
+
"types": "./dist/commonjs/index.d.ts",
|
|
67
|
+
"module": "./dist/esm/index.js"
|
|
68
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright Julian Gruber <julian@juliangruber.com>
|
|
4
|
+
|
|
5
|
+
TypeScript port Copyright Isaac Z. Schlueter <i@izs.me>
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# brace-expansion
|
|
2
|
+
|
|
3
|
+
[Brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html),
|
|
4
|
+
as known from sh/bash, in JavaScript.
|
|
5
|
+
|
|
6
|
+
[](https://github.com/juliangruber/brace-expansion/actions/workflows/ci.yml)
|
|
7
|
+
[](https://www.npmjs.org/package/brace-expansion)
|
|
8
|
+
|
|
9
|
+
## Example
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { expand } from 'brace-expansion'
|
|
13
|
+
|
|
14
|
+
expand('file-{a,b,c}.jpg')
|
|
15
|
+
// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
|
|
16
|
+
|
|
17
|
+
expand('-v{,,}')
|
|
18
|
+
// => ['-v', '-v', '-v']
|
|
19
|
+
|
|
20
|
+
expand('file{0..2}.jpg')
|
|
21
|
+
// => ['file0.jpg', 'file1.jpg', 'file2.jpg']
|
|
22
|
+
|
|
23
|
+
expand('file-{a..c}.jpg')
|
|
24
|
+
// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
|
|
25
|
+
|
|
26
|
+
expand('file{2..0}.jpg')
|
|
27
|
+
// => ['file2.jpg', 'file1.jpg', 'file0.jpg']
|
|
28
|
+
|
|
29
|
+
expand('file{0..4..2}.jpg')
|
|
30
|
+
// => ['file0.jpg', 'file2.jpg', 'file4.jpg']
|
|
31
|
+
|
|
32
|
+
expand('file-{a..e..2}.jpg')
|
|
33
|
+
// => ['file-a.jpg', 'file-c.jpg', 'file-e.jpg']
|
|
34
|
+
|
|
35
|
+
expand('file{00..10..5}.jpg')
|
|
36
|
+
// => ['file00.jpg', 'file05.jpg', 'file10.jpg']
|
|
37
|
+
|
|
38
|
+
expand('{{A..C},{a..c}}')
|
|
39
|
+
// => ['A', 'B', 'C', 'a', 'b', 'c']
|
|
40
|
+
|
|
41
|
+
expand('ppp{,config,oe{,conf}}')
|
|
42
|
+
// => ['ppp', 'pppconfig', 'pppoe', 'pppoeconf']
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## API
|
|
46
|
+
|
|
47
|
+
```js
|
|
48
|
+
import { expand } from 'brace-expansion'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### const expanded = expand(str, [options])
|
|
52
|
+
|
|
53
|
+
Return an array of all possible and valid expansions of `str`. If
|
|
54
|
+
none are found, `[str]` is returned.
|
|
55
|
+
|
|
56
|
+
The `options` object can provide a `max` value to cap the number
|
|
57
|
+
of expansions allowed. This is limited to `100_000` by default,
|
|
58
|
+
to prevent DoS attacks.
|
|
59
|
+
|
|
60
|
+
```js
|
|
61
|
+
const expansions = expand('{1..100}'.repeat(5), {
|
|
62
|
+
max: 100,
|
|
63
|
+
})
|
|
64
|
+
// expansions.length will be 100, not 100^5
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
The `options` object can also provide a `maxLength` value to cap the
|
|
68
|
+
total number of characters across all expansions. This is limited to
|
|
69
|
+
`4_000_000` by default, to prevent memory exhaustion from inputs whose
|
|
70
|
+
result count stays under `max` while each result grows very long.
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
const expansions = expand('{a,b}'.repeat(1500), {
|
|
74
|
+
maxLength: 10_000,
|
|
75
|
+
})
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Valid expansions are:
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
;/^(.*,)+(.+)?$/
|
|
82
|
+
// {a,b,...}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
A comma separated list of options, like `{a,b}` or `{a,{b,c}}` or `{,a,}`.
|
|
86
|
+
|
|
87
|
+
```js
|
|
88
|
+
;/^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
|
|
89
|
+
// {x..y[..incr]}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
A numeric sequence from `x` to `y` inclusive, with optional increment.
|
|
93
|
+
If `x` or `y` start with a leading `0`, all the numbers will be padded
|
|
94
|
+
to have equal length. Negative numbers and backwards iteration work too.
|
|
95
|
+
|
|
96
|
+
```js
|
|
97
|
+
;/^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
|
|
98
|
+
// {x..y[..incr]}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
An alphabetic sequence from `x` to `y` inclusive, with optional increment.
|
|
102
|
+
`x` and `y` must be exactly one character, and if given, `incr` must be a
|
|
103
|
+
number.
|
|
104
|
+
|
|
105
|
+
For compatibility reasons, the string `${` is not eligible for brace expansion.
|