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.
Files changed (194) hide show
  1. package/THIRD_PARTY_NOTICES.txt +392 -0
  2. package/dist/acp/maka-acp-agent.js +8 -2
  3. package/dist/acp/prompt-content.js +225 -0
  4. package/dist/acp/session-event-mapper.js +103 -0
  5. package/dist/acp/session-registry.js +654 -17
  6. package/dist/acp/stdio-server.js +10 -1
  7. package/dist/cli-core.js +1 -1
  8. package/dist/pi-transcript-tools.js +3 -2
  9. package/dist/pi-transcript.js +12 -2
  10. package/dist/runtime-host-session-channel.js +63 -9
  11. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  12. package/node_modules/@maka/core/dist/artifacts.js +6 -0
  13. package/node_modules/@maka/core/dist/attachments.js +7 -2
  14. package/node_modules/@maka/core/dist/durable-tool-result-projection.js +3 -1
  15. package/node_modules/@maka/core/dist/events.js +21 -0
  16. package/node_modules/@maka/core/dist/goal.js +44 -2
  17. package/node_modules/@maka/core/dist/permission.js +0 -1
  18. package/node_modules/@maka/core/dist/runtime-boundary.js +73 -29
  19. package/node_modules/@maka/core/dist/runtime-event.js +6 -3
  20. package/node_modules/@maka/core/dist/runtime-handoff.js +10 -2
  21. package/node_modules/@maka/core/dist/runtime-logical-execution.js +39 -14
  22. package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +3 -1
  23. package/node_modules/@maka/core/dist/tool-result-record-schema.js +2 -1
  24. package/node_modules/@maka/core/dist/unified-diff.js +33 -26
  25. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +49 -178
  26. package/node_modules/@maka/runtime/dist/ai-sdk-message-projection.js +7 -2
  27. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +15 -53
  28. package/node_modules/@maka/runtime/dist/bash-model-output.js +7 -1
  29. package/node_modules/@maka/runtime/dist/bash-tail-buffer.js +13 -52
  30. package/node_modules/@maka/runtime/dist/builtin-tools.js +59 -111
  31. package/node_modules/@maka/runtime/dist/child-fd-input.js +3 -2
  32. package/node_modules/@maka/runtime/dist/context-budget-policy.js +1 -11
  33. package/node_modules/@maka/runtime/dist/context-budget.js +12 -1
  34. package/node_modules/@maka/runtime/dist/conversation-copy.js +104 -9
  35. package/node_modules/@maka/runtime/dist/filesystem-executor.js +10 -6
  36. package/node_modules/@maka/runtime/dist/filesystem-worker/client.js +77 -19
  37. package/node_modules/@maka/runtime/dist/filesystem-worker/launch-spec.js +66 -55
  38. package/node_modules/@maka/runtime/dist/filesystem-worker/operations.js +34 -97
  39. package/node_modules/@maka/runtime/dist/filesystem-worker/protocol.js +25 -10
  40. package/node_modules/@maka/runtime/dist/filesystem-worker/worker-entry.js +2 -0
  41. package/node_modules/@maka/runtime/dist/glob-search.js +74 -0
  42. package/node_modules/@maka/runtime/dist/goal-continuation.js +78 -8
  43. package/node_modules/@maka/runtime/dist/goal-state.js +7 -0
  44. package/node_modules/@maka/runtime/dist/grep-search.js +155 -0
  45. package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +84 -94
  46. package/node_modules/@maka/runtime/dist/model-history.js +25 -3
  47. package/node_modules/@maka/runtime/dist/pipe-tail-collector.js +6 -9
  48. package/node_modules/@maka/runtime/dist/read-page.js +231 -0
  49. package/node_modules/@maka/runtime/dist/request-projection.js +2 -15
  50. package/node_modules/@maka/runtime/dist/ripgrep-executable.js +62 -0
  51. package/node_modules/@maka/runtime/dist/ripgrep-guidance.js +81 -0
  52. package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +187 -20
  53. package/node_modules/@maka/runtime/dist/runtime-read-model.js +2 -1
  54. package/node_modules/@maka/runtime/dist/sandbox/linux-profile-path.js +7 -1
  55. package/node_modules/@maka/runtime/dist/sandbox/linux-sandbox.js +20 -5
  56. package/node_modules/@maka/runtime/dist/session-manager.js +6 -6
  57. package/node_modules/@maka/runtime/dist/session-recap.js +9 -5
  58. package/node_modules/@maka/runtime/dist/shell-exec.js +7 -25
  59. package/node_modules/@maka/runtime/dist/shell-run-manager.js +1 -1
  60. package/node_modules/@maka/runtime/dist/shell-run-tool-result.js +1 -1
  61. package/node_modules/@maka/runtime/dist/shell-tools.js +6 -12
  62. package/node_modules/@maka/runtime/dist/tool-availability.js +0 -1
  63. package/node_modules/@maka/runtime/dist/tool-output.js +1 -1
  64. package/node_modules/@maka/runtime/dist/tool-result-archive-capability.js +24 -36
  65. package/node_modules/@maka/runtime/dist/tool-result-archive-resource.js +32 -527
  66. package/node_modules/@maka/runtime/dist/tool-result-archive-transition.js +17 -119
  67. package/node_modules/@maka/runtime/dist/tool-result-archive.js +7 -25
  68. package/node_modules/@maka/runtime/dist/tool-runtime.js +7 -5
  69. package/node_modules/@maka/runtime/dist/workers/filesystem-worker.js +6933 -3681
  70. package/node_modules/@maka/runtime/dist/workspace-executor.js +20 -24
  71. package/node_modules/@maka/runtime/package.json +2 -0
  72. package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +185 -191
  73. package/node_modules/@maka/runtime-host/dist/client/reconnecting-connection.js +3 -0
  74. package/node_modules/@maka/runtime-host/dist/protocol/index.js +5 -1
  75. package/node_modules/@maka/runtime-host/dist/protocol/message.js +2 -2
  76. package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
  77. package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +2 -2
  78. package/node_modules/@maka/runtime-host/dist/protocol/turn.js +10 -2
  79. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +38 -0
  80. package/node_modules/@maka/runtime-host/dist/server/execution-artifacts.js +2 -8
  81. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +2 -0
  82. package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +81 -7
  83. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +13 -13
  84. package/node_modules/@maka/runtime-host/dist/server/interaction-coordinator.js +65 -0
  85. package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +1 -0
  86. package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +5 -2
  87. package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +88 -72
  88. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-action-gate.js +21 -4
  89. package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +145 -1
  90. package/node_modules/@maka/storage/dist/agent-run-store.js +5 -2
  91. package/node_modules/@maka/storage/dist/execution-stores.js +2 -1
  92. package/node_modules/@maka/storage/dist/runtime-transcript-query.js +27 -14
  93. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +69 -3
  94. package/node_modules/balanced-match/LICENSE.md +23 -0
  95. package/node_modules/balanced-match/README.md +57 -0
  96. package/node_modules/balanced-match/dist/commonjs/index.js +59 -0
  97. package/node_modules/balanced-match/dist/commonjs/package.json +3 -0
  98. package/node_modules/balanced-match/dist/esm/index.js +54 -0
  99. package/node_modules/balanced-match/dist/esm/package.json +3 -0
  100. package/node_modules/balanced-match/package.json +68 -0
  101. package/node_modules/brace-expansion/LICENSE +23 -0
  102. package/node_modules/brace-expansion/README.md +105 -0
  103. package/node_modules/brace-expansion/dist/commonjs/index.js +289 -0
  104. package/node_modules/brace-expansion/dist/commonjs/package.json +3 -0
  105. package/node_modules/brace-expansion/dist/esm/index.js +285 -0
  106. package/node_modules/brace-expansion/dist/esm/package.json +3 -0
  107. package/node_modules/brace-expansion/package.json +64 -0
  108. package/node_modules/glob/LICENSE.md +63 -0
  109. package/node_modules/glob/README.md +1203 -0
  110. package/node_modules/glob/dist/commonjs/glob.js +248 -0
  111. package/node_modules/glob/dist/commonjs/has-magic.js +27 -0
  112. package/node_modules/glob/dist/commonjs/ignore.js +119 -0
  113. package/node_modules/glob/dist/commonjs/index.js +68 -0
  114. package/node_modules/glob/dist/commonjs/index.min.js +4 -0
  115. package/node_modules/glob/dist/commonjs/package.json +3 -0
  116. package/node_modules/glob/dist/commonjs/pattern.js +223 -0
  117. package/node_modules/glob/dist/commonjs/processor.js +301 -0
  118. package/node_modules/glob/dist/commonjs/walker.js +387 -0
  119. package/node_modules/glob/dist/esm/glob.js +244 -0
  120. package/node_modules/glob/dist/esm/has-magic.js +23 -0
  121. package/node_modules/glob/dist/esm/ignore.js +115 -0
  122. package/node_modules/glob/dist/esm/index.js +55 -0
  123. package/node_modules/glob/dist/esm/index.min.js +4 -0
  124. package/node_modules/glob/dist/esm/package.json +3 -0
  125. package/node_modules/glob/dist/esm/pattern.js +219 -0
  126. package/node_modules/glob/dist/esm/processor.js +294 -0
  127. package/node_modules/glob/dist/esm/walker.js +381 -0
  128. package/node_modules/glob/package.json +98 -0
  129. package/node_modules/minimatch/LICENSE.md +55 -0
  130. package/node_modules/minimatch/README.md +528 -0
  131. package/node_modules/minimatch/dist/commonjs/assert-valid-pattern.js +14 -0
  132. package/node_modules/minimatch/dist/commonjs/ast.js +845 -0
  133. package/node_modules/minimatch/dist/commonjs/brace-expressions.js +150 -0
  134. package/node_modules/minimatch/dist/commonjs/escape.js +30 -0
  135. package/node_modules/minimatch/dist/commonjs/index.js +1127 -0
  136. package/node_modules/minimatch/dist/commonjs/package.json +3 -0
  137. package/node_modules/minimatch/dist/commonjs/unescape.js +38 -0
  138. package/node_modules/minimatch/dist/esm/assert-valid-pattern.js +10 -0
  139. package/node_modules/minimatch/dist/esm/ast.js +841 -0
  140. package/node_modules/minimatch/dist/esm/brace-expressions.js +146 -0
  141. package/node_modules/minimatch/dist/esm/escape.js +26 -0
  142. package/node_modules/minimatch/dist/esm/index.js +1114 -0
  143. package/node_modules/minimatch/dist/esm/package.json +3 -0
  144. package/node_modules/minimatch/dist/esm/unescape.js +34 -0
  145. package/node_modules/minimatch/package.json +73 -0
  146. package/node_modules/minipass/LICENSE.md +55 -0
  147. package/node_modules/minipass/README.md +825 -0
  148. package/node_modules/minipass/dist/commonjs/index.js +1038 -0
  149. package/node_modules/minipass/dist/commonjs/package.json +3 -0
  150. package/node_modules/minipass/dist/esm/index.js +1020 -0
  151. package/node_modules/minipass/dist/esm/package.json +3 -0
  152. package/node_modules/minipass/package.json +77 -0
  153. package/node_modules/path-scurry/LICENSE.md +55 -0
  154. package/node_modules/path-scurry/README.md +636 -0
  155. package/node_modules/path-scurry/dist/commonjs/index.js +2018 -0
  156. package/node_modules/path-scurry/dist/commonjs/package.json +3 -0
  157. package/node_modules/path-scurry/dist/esm/index.js +1983 -0
  158. package/node_modules/path-scurry/dist/esm/package.json +3 -0
  159. package/node_modules/path-scurry/node_modules/lru-cache/LICENSE.md +55 -0
  160. package/node_modules/path-scurry/node_modules/lru-cache/README.md +469 -0
  161. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/diagnostics-channel.js +7 -0
  162. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.js +1726 -0
  163. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/index.min.js +2 -0
  164. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/browser/perf.js +10 -0
  165. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel-cjs.d.cts.map +1 -0
  166. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/diagnostics-channel.js +7 -0
  167. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.js +1726 -0
  168. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/index.min.js +2 -0
  169. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/diagnostics-channel.js +9 -0
  170. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.js +1726 -0
  171. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/index.min.js +2 -0
  172. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/node/perf.js +10 -0
  173. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/package.json +3 -0
  174. package/node_modules/path-scurry/node_modules/lru-cache/dist/commonjs/perf.js +10 -0
  175. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/diagnostics-channel.js +4 -0
  176. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.js +1722 -0
  177. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/index.min.js +2 -0
  178. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/browser/perf.js +7 -0
  179. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel-esm.d.mts.map +1 -0
  180. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/diagnostics-channel.js +19 -0
  181. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.js +1722 -0
  182. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/index.min.js +2 -0
  183. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/diagnostics-channel.js +6 -0
  184. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.js +1722 -0
  185. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/index.min.js +2 -0
  186. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/node/perf.js +7 -0
  187. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/package.json +3 -0
  188. package/node_modules/path-scurry/node_modules/lru-cache/dist/esm/perf.js +7 -0
  189. package/node_modules/path-scurry/node_modules/lru-cache/package.json +154 -0
  190. package/node_modules/path-scurry/package.json +72 -0
  191. package/package.json +1 -1
  192. package/node_modules/@maka/runtime/dist/active-tool-result-prune.js +0 -248
  193. package/node_modules/@maka/runtime/dist/active-tool-result-working-set.js +0 -218
  194. 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,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -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,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -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
+ [![CI](https://github.com/juliangruber/brace-expansion/actions/workflows/ci.yml/badge.svg)](https://github.com/juliangruber/brace-expansion/actions/workflows/ci.yml)
7
+ [![downloads](https://img.shields.io/npm/dm/brace-expansion.svg)](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.