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
|
@@ -23,14 +23,14 @@ import { decodePersistedToolResultContent } from '@maka/core/tool-result-record-
|
|
|
23
23
|
import { isEmittedAgentRunEventType } from '@maka/core/agent-run';
|
|
24
24
|
import { decodeModelCallAttempt, MODEL_CALL_ATTEMPT_EVENT_TYPE, } from '@maka/core/model-call-attempt';
|
|
25
25
|
import { TOOL_RECOVERY_DECISION_FACT_KIND } from '@maka/core/tool-recovery-fact';
|
|
26
|
-
import { buildHistoryCompactCheckpoint, matchHistoryCompactCheckpointPrefix, validateHistoryCompactCheckpointShape, } from './history-compact-checkpoint.js';
|
|
26
|
+
import { buildHistoryCompactCheckpoint, historyCompactSourceDigest, matchHistoryCompactCheckpointPrefix, validateHistoryCompactCheckpointShape, } from './history-compact-checkpoint.js';
|
|
27
27
|
import { findCheckpointSummaryDefect } from './history-compact-summary-validation.js';
|
|
28
28
|
import { isHistoryCompactContentEvent } from './history-compaction.js';
|
|
29
29
|
import { classifyTerminalRuntimeLedger, commitTerminalRunWithRuntimeFact, } from './terminal-run-commit.js';
|
|
30
30
|
import { buildToolOperationId } from './runtime-commit-sink.js';
|
|
31
31
|
import { isContinuationStartRuntimeEvent } from './runtime-event-read-model.js';
|
|
32
32
|
import { runtimeHandoffPause } from '@maka/core/runtime-handoff';
|
|
33
|
-
import { buildToolResultArchiveResourceRef, parseToolResultArchiveResourceRef, } from './tool-result-archive-resource.js';
|
|
33
|
+
import { buildToolResultArchiveResourceRef, parseToolResultArchiveResourceRef, parseToolResultEventAddress, } from './tool-result-archive-resource.js';
|
|
34
34
|
import { deserializeToolResultArchive, isArchivedToolResultPlaceholder, buildLedgerArchivedToolResultPlaceholder, } from './tool-result-archive.js';
|
|
35
35
|
import { rewriteDurableToolResultProjectionArtifactRefs } from './durable-tool-result-projection.js';
|
|
36
36
|
import { buildModelProjectionTransition, durableToolResultProjectionDigest, decodeModelProjectionTransition, MODEL_PROJECTION_TRANSITION_EVENT_TYPE, } from '@maka/core/model-projection-transition';
|
|
@@ -38,6 +38,7 @@ import { baseToolResultProjection, decodeLedgerTransition, reduceEffectiveModelP
|
|
|
38
38
|
import { archivedToolResultProjection } from './tool-result-archive-transition.js';
|
|
39
39
|
import { serializeToolResultProjectionV1 } from './tool-result-archive-encoding.js';
|
|
40
40
|
import { createHash } from 'node:crypto';
|
|
41
|
+
import { readToolResultPage, readableToolResult, resolveReadInput, READ_PAGE_MAX_CHARS, } from './read-page.js';
|
|
41
42
|
/** Walks every typed StorageRef site reached by conversation-copy rewriting. */
|
|
42
43
|
function collectConversationCopyStorageRefs(input) {
|
|
43
44
|
const refs = [];
|
|
@@ -354,6 +355,15 @@ export async function cloneConversationRuntimeLedger(input) {
|
|
|
354
355
|
throw new Error('Cyclic copied archive reference');
|
|
355
356
|
visiting.add(sourceId);
|
|
356
357
|
const target = clonedEventBySourceId.get(sourceId);
|
|
358
|
+
if (target?.content?.kind === 'function_response' && target.content.name === 'Read') {
|
|
359
|
+
target.content.result = rewriteReadPage(target.content.result, references, clonedEventBySourceId);
|
|
360
|
+
const projection = target.content.modelProjection;
|
|
361
|
+
if (projection?.kind === 'json')
|
|
362
|
+
target.content.modelProjection = {
|
|
363
|
+
...projection,
|
|
364
|
+
value: rewriteReadPage(projection.value, references, clonedEventBySourceId),
|
|
365
|
+
};
|
|
366
|
+
}
|
|
357
367
|
if (target?.content?.kind === 'function_response' && target.content.name === 'ArchiveRead') {
|
|
358
368
|
const resolveResult = (value) => rewriteArchiveReadResult(value, references, (ref) => {
|
|
359
369
|
const identity = parseToolResultArchiveResourceRef(ref);
|
|
@@ -377,8 +387,19 @@ export async function cloneConversationRuntimeLedger(input) {
|
|
|
377
387
|
for (const sourceId of clonedEventBySourceId.keys())
|
|
378
388
|
finishTarget(sourceId);
|
|
379
389
|
for (const event of clonedEventBySourceId.values()) {
|
|
390
|
+
if (event.content?.kind === 'function_call' && event.content.name === 'Read') {
|
|
391
|
+
const args = event.content.args;
|
|
392
|
+
if (args && typeof args === 'object' && 'path' in args && typeof args.path === 'string')
|
|
393
|
+
event.content = {
|
|
394
|
+
...event.content,
|
|
395
|
+
args: {
|
|
396
|
+
...args,
|
|
397
|
+
...rewriteReadInput(args, references, clonedEventBySourceId),
|
|
398
|
+
},
|
|
399
|
+
};
|
|
400
|
+
}
|
|
380
401
|
if (event.content?.kind === 'text')
|
|
381
|
-
event.content.text =
|
|
402
|
+
event.content.text = rewriteCopiedText(event.content.text, references, clonedEventBySourceId);
|
|
382
403
|
if (event.content?.kind === 'function_call' && event.content.name === 'ArchiveRead') {
|
|
383
404
|
const args = event.content.args;
|
|
384
405
|
if (args && typeof args === 'object' && 'ref' in args && typeof args.ref === 'string') {
|
|
@@ -412,18 +433,19 @@ export async function cloneConversationRuntimeLedger(input) {
|
|
|
412
433
|
terminalEvent,
|
|
413
434
|
};
|
|
414
435
|
});
|
|
415
|
-
const archiveReadCalls = new Set(flattenedPlans.flatMap((plan) => plan.events.flatMap((event) => event.content?.kind === 'function_response' &&
|
|
436
|
+
const archiveReadCalls = new Set(flattenedPlans.flatMap((plan) => plan.events.flatMap((event) => event.content?.kind === 'function_response' &&
|
|
437
|
+
(event.content.name === 'ArchiveRead' || event.content.name === 'Read')
|
|
416
438
|
? [`${event.turnId}:${event.content.id}`]
|
|
417
439
|
: [])));
|
|
418
440
|
const copiedMessages = input.copiedMessages.map((message) => {
|
|
419
441
|
const copied = rewriteConversationCopyMessage(message, references);
|
|
420
442
|
if (copied.type === 'user' || copied.type === 'assistant')
|
|
421
|
-
return { ...copied, text:
|
|
443
|
+
return { ...copied, text: rewriteCopiedText(copied.text, references, clonedEventBySourceId) };
|
|
422
444
|
if (copied.type === 'tool_result' &&
|
|
423
445
|
archiveReadCalls.has(`${copied.turnId}:${copied.toolUseId}`)) {
|
|
424
446
|
return {
|
|
425
447
|
...copied,
|
|
426
|
-
content: rewriteArchiveReadResult(copied.content, references),
|
|
448
|
+
content: rewriteReadPage(rewriteArchiveReadResult(copied.content, references), references, clonedEventBySourceId),
|
|
427
449
|
};
|
|
428
450
|
}
|
|
429
451
|
return copied;
|
|
@@ -479,8 +501,71 @@ export async function cloneConversationRuntimeLedger(input) {
|
|
|
479
501
|
function rewriteLedgerArchiveText(text, references) {
|
|
480
502
|
for (const [source, target] of references.ledgerArchives ?? [])
|
|
481
503
|
text = text.split(source).join(target.resourceRef);
|
|
504
|
+
for (const [source, target] of references.runtimeEventIds)
|
|
505
|
+
text = text
|
|
506
|
+
.split(`maka://runtime/tool-results/${encodeURIComponent(source)}`)
|
|
507
|
+
.join(`maka://runtime/tool-results/${encodeURIComponent(target)}`);
|
|
482
508
|
return text;
|
|
483
509
|
}
|
|
510
|
+
/** Text identifies generated addresses; the structured Read rewriter owns their semantics. */
|
|
511
|
+
function rewriteCopiedText(text, references, clonedEvents) {
|
|
512
|
+
return rewriteLedgerArchiveText(text, references).replace(/maka:\/\/read\/[A-Za-z0-9_-]+\?at=\d+&sha=[a-f0-9]{32}(?![A-Za-z0-9_?&#=%/-])/g, (path) => rewriteReadInput({ path }, references, clonedEvents).path);
|
|
513
|
+
}
|
|
514
|
+
function rewriteReadInput(input, references, clonedEvents) {
|
|
515
|
+
let original;
|
|
516
|
+
try {
|
|
517
|
+
original = resolveReadInput(input).path;
|
|
518
|
+
}
|
|
519
|
+
catch {
|
|
520
|
+
return input;
|
|
521
|
+
}
|
|
522
|
+
const prefix = 'maka://runtime/tool-results/';
|
|
523
|
+
const eventId = parseToolResultEventAddress(original);
|
|
524
|
+
if (original.startsWith(prefix) && !eventId)
|
|
525
|
+
return input;
|
|
526
|
+
const path = eventId
|
|
527
|
+
? `${prefix}${encodeURIComponent(references.runtimeEventIds.get(eventId) ?? eventId)}`
|
|
528
|
+
: rewriteLedgerArchiveText(references.mode === 'exact'
|
|
529
|
+
? rewriteAttachmentResourceRefs(original, references.artifactIds)
|
|
530
|
+
: original, references);
|
|
531
|
+
if (!input.path.startsWith('maka://read/'))
|
|
532
|
+
return { ...input, path };
|
|
533
|
+
const url = new URL(input.path);
|
|
534
|
+
if (eventId && path !== original) {
|
|
535
|
+
const copied = clonedEvents.get(eventId);
|
|
536
|
+
const projection = copied && baseToolResultProjection(copied);
|
|
537
|
+
const digest = projection &&
|
|
538
|
+
createHash('sha256')
|
|
539
|
+
.update(readableToolResult(serializeToolResultProjectionV1(projection)))
|
|
540
|
+
.digest('hex')
|
|
541
|
+
.slice(0, 32);
|
|
542
|
+
if (digest !== url.searchParams.get('sha'))
|
|
543
|
+
return { path };
|
|
544
|
+
}
|
|
545
|
+
url.pathname = `/${Buffer.from(path).toString('base64url')}`;
|
|
546
|
+
return { ...input, path: url.toString() };
|
|
547
|
+
}
|
|
548
|
+
function rewriteReadPage(value, references, clonedEvents) {
|
|
549
|
+
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
550
|
+
return value;
|
|
551
|
+
const page = value;
|
|
552
|
+
if (page.kind === 'json')
|
|
553
|
+
return { ...page, value: rewriteReadPage(page.value, references, clonedEvents) };
|
|
554
|
+
const next = page.next;
|
|
555
|
+
if (!next || typeof next !== 'object' || !('path' in next) || typeof next.path !== 'string')
|
|
556
|
+
return value;
|
|
557
|
+
const rewritten = rewriteReadInput(next, references, clonedEvents);
|
|
558
|
+
const reset = next.path.startsWith('maka://read/') && !rewritten.path.startsWith('maka://read/');
|
|
559
|
+
return {
|
|
560
|
+
...page,
|
|
561
|
+
next: rewritten,
|
|
562
|
+
...(reset
|
|
563
|
+
? {
|
|
564
|
+
continuationReset: 'The copied resource changed. Use next to read it from the beginning.',
|
|
565
|
+
}
|
|
566
|
+
: {}),
|
|
567
|
+
};
|
|
568
|
+
}
|
|
484
569
|
/** Only ArchiveRead's defined envelope is rewritten, never its opaque content/items. */
|
|
485
570
|
function rewriteArchiveReadResult(value, references, before) {
|
|
486
571
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
@@ -679,6 +764,11 @@ function cloneAgentRunEvent(event, ids, references, sourceCompactableEvents, clo
|
|
|
679
764
|
const match = matchHistoryCompactCheckpointPrefix(sourceCheckpoint, sourceCompactableEvents);
|
|
680
765
|
if (match.reason)
|
|
681
766
|
return null;
|
|
767
|
+
// Rebinding a digest must not make an already stale source summary valid.
|
|
768
|
+
const sourceEffective = reduceEffectiveModelProjections(match.coveredRuntimeEvents, [...clonedTransitions.keys()].map((record) => decodeModelProjectionTransition(record.data?.transition, record.sessionId))).events;
|
|
769
|
+
if (sourceCheckpoint.coverage.effectiveSourceDigest !==
|
|
770
|
+
historyCompactSourceDigest(sourceEffective))
|
|
771
|
+
return null;
|
|
682
772
|
// Copy is an admission seam for the sectioned summary contract: a marked
|
|
683
773
|
// checkpoint whose summary no longer satisfies the COMPLETE predicate —
|
|
684
774
|
// re-runnable here on structure and truncation (the size floor needs the
|
|
@@ -704,7 +794,8 @@ function cloneAgentRunEvent(event, ids, references, sourceCompactableEvents, clo
|
|
|
704
794
|
const checkpoint = buildHistoryCompactCheckpoint({
|
|
705
795
|
sessionId: references.targetSessionId,
|
|
706
796
|
coveredRuntimeEvents,
|
|
707
|
-
|
|
797
|
+
effectiveCoveredRuntimeEvents: reduceEffectiveModelProjections(coveredRuntimeEvents, [...clonedTransitions.values()].filter((transition) => transition !== null)).events,
|
|
798
|
+
summary: rewriteCopiedText(sourceCheckpoint.summary, references, clonedRuntimeEvents),
|
|
708
799
|
highWaterName: sourceCheckpoint.highWaterName,
|
|
709
800
|
highWaterSeq: sourceCheckpoint.highWaterSeq,
|
|
710
801
|
now: sourceCheckpoint.createdAt,
|
|
@@ -789,7 +880,11 @@ function cloneModelProjectionTransition(event, references, clonedRuntimeEvents,
|
|
|
789
880
|
}
|
|
790
881
|
: {}),
|
|
791
882
|
});
|
|
792
|
-
|
|
883
|
+
if (rewritten.page) {
|
|
884
|
+
delete rewritten.page;
|
|
885
|
+
rewritten.page = readToolResultPage(serialized, { path: rewritten.resourceRef }, READ_PAGE_MAX_CHARS - JSON.stringify(rewritten).length - 32);
|
|
886
|
+
}
|
|
887
|
+
references.ledgerArchives?.set(placeholder.resourceRef ?? buildToolResultArchiveResourceRef(placeholder), rewritten);
|
|
793
888
|
}
|
|
794
889
|
else {
|
|
795
890
|
rewritten = rewriteArchivedToolResult(placeholder, references);
|
|
@@ -803,7 +898,7 @@ function cloneModelProjectionTransition(event, references, clonedRuntimeEvents,
|
|
|
803
898
|
toolName: source.target.toolName,
|
|
804
899
|
},
|
|
805
900
|
sourceProjection,
|
|
806
|
-
replacement: archivedToolResultProjection(rewritten),
|
|
901
|
+
replacement: archivedToolResultProjection(rewritten, source.replacement),
|
|
807
902
|
// The applied chain is copied in fold order, so a predecessor is always
|
|
808
903
|
// rebuilt before its successor. An unmapped one means the chain broke, and
|
|
809
904
|
// rooting the successor instead would change what the fold decides.
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
// skipped the worker, so that undeclared rule became the only arbiter and made
|
|
28
28
|
// "full access" stricter than ask mode, which grants :slash_tmp outright (#2083).
|
|
29
29
|
import { Buffer } from 'node:buffer';
|
|
30
|
+
import { readPage } from './read-page.js';
|
|
30
31
|
import { lstat, realpath, stat } from 'node:fs/promises';
|
|
31
32
|
import { isAbsolute } from 'node:path';
|
|
32
33
|
import { ToolOutcomeUnknownError } from '@maka/core/events';
|
|
@@ -37,7 +38,7 @@ import { StableWriteFailure } from './file-stable-write.js';
|
|
|
37
38
|
import { applyUpdateToContent } from './apply-patch-file.js';
|
|
38
39
|
import { withFileWriteLock } from './file-write-lock.js';
|
|
39
40
|
import { isSupportedImagePath } from './image-file.js';
|
|
40
|
-
import { operationAccess } from './filesystem-worker/protocol.js';
|
|
41
|
+
import { FilesystemWorkerOperationSchema, operationAccess } from './filesystem-worker/protocol.js';
|
|
41
42
|
import { resolveCanonicalDirectoryEntryTarget } from './path-containment.js';
|
|
42
43
|
import { normalizeSandboxBoundaryPath } from './sandbox-boundary-path.js';
|
|
43
44
|
import { SandboxCommandError } from './sandbox/errors.js';
|
|
@@ -113,6 +114,8 @@ export function createBoundaryFilesystemExecutor(input) {
|
|
|
113
114
|
});
|
|
114
115
|
};
|
|
115
116
|
async function run(call, expectedIdentity) {
|
|
117
|
+
if (call.operation.kind === 'read')
|
|
118
|
+
FilesystemWorkerOperationSchema.parse({ ...call.operation, cwd: call.cwd });
|
|
116
119
|
const worker = workerFor(call.executionBoundary);
|
|
117
120
|
if (!worker) {
|
|
118
121
|
// The local backend consumes the same identity authority as the worker
|
|
@@ -266,13 +269,14 @@ function createWorkspaceFilesystemExecutor(workspace) {
|
|
|
266
269
|
const result = await workspace.readFile({
|
|
267
270
|
cwd,
|
|
268
271
|
path,
|
|
269
|
-
...(operation.offset !== undefined ? { offset: operation.offset } : {}),
|
|
270
|
-
...(operation.limit !== undefined ? { limit: operation.limit } : {}),
|
|
271
272
|
});
|
|
272
273
|
if ('bytes' in result) {
|
|
273
274
|
return { kind: 'read_image', bytes: result.bytes, mimeType: result.mimeType };
|
|
274
275
|
}
|
|
275
|
-
return {
|
|
276
|
+
return {
|
|
277
|
+
kind: 'read',
|
|
278
|
+
...readPage(result.content, operation, undefined, operation.continuation),
|
|
279
|
+
};
|
|
276
280
|
}
|
|
277
281
|
case 'write': {
|
|
278
282
|
const { path } = await workspace.resolveWritablePath({
|
|
@@ -534,7 +538,7 @@ function createWorkspaceFilesystemExecutor(workspace) {
|
|
|
534
538
|
label: 'Grep',
|
|
535
539
|
scope,
|
|
536
540
|
});
|
|
537
|
-
const
|
|
541
|
+
const result = await workspace.grepFiles({
|
|
538
542
|
cwd,
|
|
539
543
|
pattern: operation.pattern,
|
|
540
544
|
path,
|
|
@@ -544,7 +548,7 @@ function createWorkspaceFilesystemExecutor(workspace) {
|
|
|
544
548
|
timeoutMs: operation.timeoutMs,
|
|
545
549
|
...(abortSignal ? { abortSignal } : {}),
|
|
546
550
|
});
|
|
547
|
-
return { kind: 'grep',
|
|
551
|
+
return { kind: 'grep', ...result };
|
|
548
552
|
}
|
|
549
553
|
}
|
|
550
554
|
},
|
|
@@ -19,10 +19,11 @@
|
|
|
19
19
|
import { randomUUID } from 'node:crypto';
|
|
20
20
|
import { lstat, realpath } from 'node:fs/promises';
|
|
21
21
|
import { tmpdir } from 'node:os';
|
|
22
|
-
import { dirname } from 'node:path';
|
|
22
|
+
import { dirname, join } from 'node:path';
|
|
23
23
|
import { canReadPath, canWritePath } from '@maka/core/permission-profile';
|
|
24
24
|
import { compilePermissionProfile } from '@maka/core/permission-profile-compiler';
|
|
25
25
|
import { normalizeSandboxBoundaryPath } from '../sandbox-boundary-path.js';
|
|
26
|
+
import { MAX_CHILD_FD } from '../child-fd-input.js';
|
|
26
27
|
import { resolveCanonicalDirectoryEntryTarget } from '../path-containment.js';
|
|
27
28
|
import { pinExistingLinuxProfilePath } from '../sandbox/linux-profile-path.js';
|
|
28
29
|
import { classifyWindowsBrokerFailure } from '../sandbox/windows-broker-errors.js';
|
|
@@ -224,10 +225,40 @@ export class FilesystemWorkerClient {
|
|
|
224
225
|
if (Buffer.byteLength(requestJson, 'utf8') > FILESYSTEM_WORKER_MAX_REQUEST_BYTES) {
|
|
225
226
|
throw clientError('request_overflow', 'validation', requestId);
|
|
226
227
|
}
|
|
227
|
-
const launch = await this.input.getLaunchSpec();
|
|
228
|
+
const launch = await this.input.getLaunchSpec(operation);
|
|
228
229
|
if (!launch.ok)
|
|
229
230
|
throw clientError(launch.reason, 'launch', requestId, launch.message);
|
|
230
|
-
const
|
|
231
|
+
const searchMetadata = [];
|
|
232
|
+
if (operation.kind === 'grep' && target.targetType === 'directory') {
|
|
233
|
+
// Narrow the data scan to its target without dropping already-authorized
|
|
234
|
+
// ancestor ignore rules. Configuration files never grant their parent tree.
|
|
235
|
+
for (let parent = dirname(target.enforcementPath);; parent = dirname(parent)) {
|
|
236
|
+
for (const name of ['.gitignore', '.ignore', '.rgignore', '.git', '.git/info/exclude']) {
|
|
237
|
+
const path = join(parent, name);
|
|
238
|
+
if (!canReadPath(effectiveProfile, path, pathContext))
|
|
239
|
+
continue;
|
|
240
|
+
const canonical = await realpath(path).catch(() => undefined);
|
|
241
|
+
if (canonical && canReadPath(effectiveProfile, canonical, pathContext)) {
|
|
242
|
+
const metadata = await lstat(canonical).catch(() => undefined);
|
|
243
|
+
if (metadata?.isFile() || (name === '.git' && metadata?.isDirectory())) {
|
|
244
|
+
searchMetadata.push({
|
|
245
|
+
path,
|
|
246
|
+
canonicalPath: canonical,
|
|
247
|
+
targetType: metadata.isDirectory() ? 'directory' : 'file',
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (dirname(parent) === parent)
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
const firstMetadataFd = 5;
|
|
257
|
+
if (platform === 'linux' &&
|
|
258
|
+
searchMetadata.some(({ targetType }, index) => targetType === 'file' && firstMetadataFd + index > MAX_CHILD_FD)) {
|
|
259
|
+
throw clientError('request_overflow', 'validation', requestId, 'Too many ancestor ignore files for one Grep operation. Search from a higher-level directory.');
|
|
260
|
+
}
|
|
261
|
+
const workerProfile = deriveWorkerProfile(effectiveProfile, operationBoundary, searchMetadata.map(({ path, canonicalPath }) => platform === 'linux' ? path : canonicalPath));
|
|
231
262
|
const pinnedTarget = platform === 'linux' && !entryMode && target.targetType !== 'missing'
|
|
232
263
|
? (() => {
|
|
233
264
|
try {
|
|
@@ -270,7 +301,30 @@ export class FilesystemWorkerClient {
|
|
|
270
301
|
throw clientError('path_changed', 'validation', requestId, 'The approved filesystem target parent changed before sandbox launch.');
|
|
271
302
|
}
|
|
272
303
|
let transformed;
|
|
304
|
+
const pinnedMetadata = [];
|
|
305
|
+
const releasePinnedPaths = () => {
|
|
306
|
+
pinnedTarget?.releaseSource();
|
|
307
|
+
pinnedRuntimeWritableRoot?.releaseSource();
|
|
308
|
+
for (const pinned of pinnedMetadata)
|
|
309
|
+
pinned.releaseSource();
|
|
310
|
+
};
|
|
273
311
|
try {
|
|
312
|
+
if (platform === 'linux') {
|
|
313
|
+
for (const metadata of searchMetadata) {
|
|
314
|
+
const pinned = pinExistingLinuxProfilePath({
|
|
315
|
+
path: metadata.canonicalPath,
|
|
316
|
+
targetType: metadata.targetType,
|
|
317
|
+
access: 'read',
|
|
318
|
+
childFd: firstMetadataFd + pinnedMetadata.length,
|
|
319
|
+
});
|
|
320
|
+
if (!pinned) {
|
|
321
|
+
throw clientError('path_changed', 'validation', requestId);
|
|
322
|
+
}
|
|
323
|
+
// rg opens the ancestor's lexical name. Bind the verified canonical
|
|
324
|
+
// source there even when the original metadata entry was a symlink.
|
|
325
|
+
pinnedMetadata.push({ ...pinned, path: metadata.path });
|
|
326
|
+
}
|
|
327
|
+
}
|
|
274
328
|
transformed = this.input.sandboxManager.transform({
|
|
275
329
|
platform,
|
|
276
330
|
command: {
|
|
@@ -283,17 +337,18 @@ export class FilesystemWorkerClient {
|
|
|
283
337
|
...pathContext,
|
|
284
338
|
runtimeReadableRoots: launch.spec.runtimeReadableRoots,
|
|
285
339
|
executableRoots: launch.spec.executableRoots,
|
|
286
|
-
...(pinnedTarget
|
|
340
|
+
...(pinnedTarget || pinnedMetadata.length
|
|
287
341
|
? {
|
|
288
342
|
pinnedProfilePaths: [
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
343
|
+
...(pinnedTarget ? [pinnedTarget] : []),
|
|
344
|
+
...pinnedMetadata,
|
|
345
|
+
].map((pinned) => ({
|
|
346
|
+
path: pinned.path,
|
|
347
|
+
access: pinned.access,
|
|
348
|
+
fd: pinned.childFd,
|
|
349
|
+
sourceFd: pinned.sourceFd,
|
|
350
|
+
releaseSource: pinned.releaseSource,
|
|
351
|
+
})),
|
|
297
352
|
}
|
|
298
353
|
: {}),
|
|
299
354
|
...(pinnedRuntimeWritableRoot
|
|
@@ -313,13 +368,11 @@ export class FilesystemWorkerClient {
|
|
|
313
368
|
});
|
|
314
369
|
}
|
|
315
370
|
catch (error) {
|
|
316
|
-
|
|
317
|
-
pinnedRuntimeWritableRoot?.releaseSource();
|
|
371
|
+
releasePinnedPaths();
|
|
318
372
|
throw error;
|
|
319
373
|
}
|
|
320
374
|
if (!transformed.ok) {
|
|
321
|
-
|
|
322
|
-
pinnedRuntimeWritableRoot?.releaseSource();
|
|
375
|
+
releasePinnedPaths();
|
|
323
376
|
throw clientError(transformed.reason, 'transform', requestId, transformed.message, false, {
|
|
324
377
|
backend: transformed.sandboxType,
|
|
325
378
|
profileName: effectiveProfile.name ?? effectiveProfile.type,
|
|
@@ -348,8 +401,7 @@ export class FilesystemWorkerClient {
|
|
|
348
401
|
throw clientError(dispatched ? 'worker_io_incomplete' : 'spawn_failed', 'launch', requestId, undefined, false, {}, dispatched);
|
|
349
402
|
}
|
|
350
403
|
finally {
|
|
351
|
-
|
|
352
|
-
pinnedRuntimeWritableRoot?.releaseSource();
|
|
404
|
+
releasePinnedPaths();
|
|
353
405
|
}
|
|
354
406
|
if (processResult.timedOut) {
|
|
355
407
|
throw clientError('timeout', 'launch', requestId, undefined, false, {}, processResult.dispatched);
|
|
@@ -414,7 +466,7 @@ export function filesystemWorkerRuntimeWritableRoots(input) {
|
|
|
414
466
|
return input.writableAncestor ? [input.writableAncestor] : undefined;
|
|
415
467
|
return input.targetType === 'missing' ? [dirname(input.enforcementPath)] : undefined;
|
|
416
468
|
}
|
|
417
|
-
function deriveWorkerProfile(profile, operationBoundary) {
|
|
469
|
+
function deriveWorkerProfile(profile, operationBoundary, searchMetadata) {
|
|
418
470
|
if (profile.type !== 'managed' || profile.fileSystem.kind !== 'restricted')
|
|
419
471
|
return profile;
|
|
420
472
|
const target = operationBoundary.filesystem.entries[0];
|
|
@@ -430,6 +482,12 @@ function deriveWorkerProfile(profile, operationBoundary) {
|
|
|
430
482
|
access: target.access,
|
|
431
483
|
match: target.scope,
|
|
432
484
|
},
|
|
485
|
+
...searchMetadata.map((path) => ({
|
|
486
|
+
kind: 'path',
|
|
487
|
+
path,
|
|
488
|
+
access: 'read',
|
|
489
|
+
match: 'exact',
|
|
490
|
+
})),
|
|
433
491
|
],
|
|
434
492
|
},
|
|
435
493
|
network: { kind: 'restricted' },
|
|
@@ -18,12 +18,23 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { constants } from 'node:fs';
|
|
20
20
|
import { access, realpath } from 'node:fs/promises';
|
|
21
|
-
import {
|
|
21
|
+
import { dirname, isAbsolute, resolve } from 'node:path';
|
|
22
22
|
import { resolveFilesystemWorkerBundle, } from './resource-resolver.js';
|
|
23
23
|
import { resolveMacosExecutableDependencies, } from './macos-executable-dependencies.js';
|
|
24
|
+
import { currentRipgrepEnvironment, formatRipgrepEnvironmentArg, } from '../ripgrep-guidance.js';
|
|
25
|
+
import { defaultRipgrepCandidates, resolveRipgrepCandidates } from '../ripgrep-executable.js';
|
|
24
26
|
export function createFilesystemWorkerLaunchSpecProvider(input) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const platform = input.platform ?? process.platform;
|
|
28
|
+
let base;
|
|
29
|
+
return async (operation) => {
|
|
30
|
+
const resolved = await (base ??= resolveLaunchBase(input, platform));
|
|
31
|
+
if (!resolved.ok)
|
|
32
|
+
return resolved;
|
|
33
|
+
const grep = operation.kind === 'grep'
|
|
34
|
+
? await resolveWorkerRipgrep(input.rgCandidates ?? defaultRipgrepCandidates(input.hostEnv ?? process.env, platform), platform, input.inspectMacosExecutableDependencies ?? resolveMacosExecutableDependencies)
|
|
35
|
+
: undefined;
|
|
36
|
+
return { ok: true, spec: composeLaunchSpec(resolved.base, grep) };
|
|
37
|
+
};
|
|
27
38
|
}
|
|
28
39
|
export function buildFilesystemWorkerEnv(runtime, hostEnv = process.env, controlledTmpdir = '/tmp', platform = process.platform) {
|
|
29
40
|
const env = { TMPDIR: controlledTmpdir, OPENSSL_CONF: '/dev/null' };
|
|
@@ -47,7 +58,7 @@ export function buildFilesystemWorkerEnv(runtime, hostEnv = process.env, control
|
|
|
47
58
|
env.ELECTRON_RUN_AS_NODE = '1';
|
|
48
59
|
return env;
|
|
49
60
|
}
|
|
50
|
-
async function
|
|
61
|
+
async function resolveLaunchBase(input, platform) {
|
|
51
62
|
const bundle = await resolveFilesystemWorkerBundle(input.resourceLocation);
|
|
52
63
|
if (!bundle.ok) {
|
|
53
64
|
return {
|
|
@@ -64,7 +75,6 @@ async function resolveLaunchSpec(input) {
|
|
|
64
75
|
message: 'Filesystem worker runtime is unavailable.',
|
|
65
76
|
};
|
|
66
77
|
}
|
|
67
|
-
const platform = input.platform ?? process.platform;
|
|
68
78
|
// A packaged Windows executable lives directly inside the product-owned app
|
|
69
79
|
// directory. Granting its parent would widen a normal install from
|
|
70
80
|
// `...\Programs\Maka` to every application under `...\Programs` (or from
|
|
@@ -81,7 +91,6 @@ async function resolveLaunchSpec(input) {
|
|
|
81
91
|
};
|
|
82
92
|
}
|
|
83
93
|
const dependencyRoots = await resolveRuntimeDependencyRoots(program);
|
|
84
|
-
const grep = await resolveRipgrepExecutable(input.rgCandidates ?? defaultRipgrepCandidates(input.hostEnv ?? process.env, platform), platform, input.inspectMacosExecutableDependencies ?? resolveMacosExecutableDependencies);
|
|
85
94
|
const electronFrameworks = input.runtime === 'electron' && platform === 'darwin'
|
|
86
95
|
? await resolveReadableRoot(resolve(dirname(program), '..', 'Frameworks'))
|
|
87
96
|
: undefined;
|
|
@@ -92,52 +101,64 @@ async function resolveLaunchSpec(input) {
|
|
|
92
101
|
message: 'Electron framework roots are unavailable.',
|
|
93
102
|
};
|
|
94
103
|
}
|
|
104
|
+
const environment = currentRipgrepEnvironment(input.hostEnv ?? process.env);
|
|
95
105
|
return {
|
|
96
106
|
ok: true,
|
|
97
|
-
|
|
107
|
+
base: {
|
|
108
|
+
runtime: input.runtime,
|
|
109
|
+
platform,
|
|
98
110
|
program,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
// --no-stdio-init: Electron's run-as-node entry opens the NUL device to
|
|
105
|
-
// backfill missing standard handles before Node starts, and the
|
|
106
|
-
// AppContainer denies that device open, which aborts startup (FATAL
|
|
107
|
-
// node_main.cc "Unable to open nul device"). The broker always relays
|
|
108
|
-
// three valid standard handles into the child, so the backfill is
|
|
109
|
-
// unnecessary; the switch skips it and is consumed before Node's own
|
|
110
|
-
// option parsing.
|
|
111
|
-
args: [
|
|
112
|
-
...(input.runtime === 'electron' && platform === 'win32' ? ['--no-stdio-init'] : []),
|
|
113
|
-
...(platform === 'win32' ? ['--preserve-symlinks-main'] : []),
|
|
114
|
-
bundle.path,
|
|
115
|
-
...(grep ? ['--grep-executable', grep.executable] : []),
|
|
116
|
-
],
|
|
111
|
+
bundlePath: bundle.path,
|
|
112
|
+
runtimeRoot,
|
|
113
|
+
dependencyRoots,
|
|
114
|
+
...(electronFrameworks ? { electronFrameworks } : {}),
|
|
117
115
|
env: buildFilesystemWorkerEnv(input.runtime, input.hostEnv, input.tmpdir, platform),
|
|
118
|
-
|
|
119
|
-
bundle.path,
|
|
120
|
-
runtimeRoot,
|
|
121
|
-
...dependencyRoots,
|
|
122
|
-
...(grep?.runtimeReadableRoots ?? []),
|
|
123
|
-
]),
|
|
124
|
-
executableRoots: unique([
|
|
125
|
-
program,
|
|
126
|
-
runtimeRoot,
|
|
127
|
-
...(electronFrameworks ? [electronFrameworks] : []),
|
|
128
|
-
...dependencyRoots,
|
|
129
|
-
...(grep ? [grep.executable, ...grep.executableRoots] : []),
|
|
130
|
-
]),
|
|
116
|
+
...(environment ? { environment } : {}),
|
|
131
117
|
},
|
|
132
118
|
};
|
|
133
119
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
120
|
+
function composeLaunchSpec(base, grep) {
|
|
121
|
+
return {
|
|
122
|
+
program: base.program,
|
|
123
|
+
// --preserve-symlinks-main skips the module loader's realpath of the
|
|
124
|
+
// bundle path. Inside the Windows AppContainer that realpath would
|
|
125
|
+
// lstat every ancestor directory (up to the volume root), which the
|
|
126
|
+
// sandbox grants deliberately do not allow.
|
|
127
|
+
//
|
|
128
|
+
// --no-stdio-init: Electron's run-as-node entry opens the NUL device to
|
|
129
|
+
// backfill missing standard handles before Node starts, and the
|
|
130
|
+
// AppContainer denies that device open, which aborts startup (FATAL
|
|
131
|
+
// node_main.cc "Unable to open nul device"). The broker always relays
|
|
132
|
+
// three valid standard handles into the child, so the backfill is
|
|
133
|
+
// unnecessary; the switch skips it and is consumed before Node's own
|
|
134
|
+
// option parsing.
|
|
135
|
+
args: [
|
|
136
|
+
...(base.runtime === 'electron' && base.platform === 'win32' ? ['--no-stdio-init'] : []),
|
|
137
|
+
...(base.platform === 'win32' ? ['--preserve-symlinks-main'] : []),
|
|
138
|
+
base.bundlePath,
|
|
139
|
+
...(base.environment
|
|
140
|
+
? ['--ripgrep-environment', formatRipgrepEnvironmentArg(base.environment)]
|
|
141
|
+
: []),
|
|
142
|
+
...(grep ? ['--grep-executable', grep.executable] : []),
|
|
143
|
+
],
|
|
144
|
+
env: base.env,
|
|
145
|
+
runtimeReadableRoots: unique([
|
|
146
|
+
base.bundlePath,
|
|
147
|
+
base.runtimeRoot,
|
|
148
|
+
...base.dependencyRoots,
|
|
149
|
+
...(grep?.runtimeReadableRoots ?? []),
|
|
150
|
+
]),
|
|
151
|
+
executableRoots: unique([
|
|
152
|
+
base.program,
|
|
153
|
+
base.runtimeRoot,
|
|
154
|
+
...(base.electronFrameworks ? [base.electronFrameworks] : []),
|
|
155
|
+
...base.dependencyRoots,
|
|
156
|
+
...(grep ? [grep.executable, ...grep.executableRoots] : []),
|
|
157
|
+
]),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
async function resolveWorkerRipgrep(candidates, platform, inspectMacosExecutableDependencies) {
|
|
161
|
+
for await (const executable of resolveRipgrepCandidates(candidates)) {
|
|
141
162
|
if (platform !== 'darwin') {
|
|
142
163
|
return { executable, runtimeReadableRoots: [], executableRoots: [] };
|
|
143
164
|
}
|
|
@@ -171,16 +192,6 @@ async function resolveReadableRoot(candidate) {
|
|
|
171
192
|
return undefined;
|
|
172
193
|
}
|
|
173
194
|
}
|
|
174
|
-
function defaultRipgrepCandidates(env, platform = process.platform) {
|
|
175
|
-
const executableName = platform === 'win32' ? 'rg.exe' : 'rg';
|
|
176
|
-
return [
|
|
177
|
-
...(env.PATH ?? '')
|
|
178
|
-
.split(delimiter)
|
|
179
|
-
.filter(Boolean)
|
|
180
|
-
.map((directory) => join(directory, executableName)),
|
|
181
|
-
...(platform === 'win32' ? [] : ['/opt/homebrew/bin/rg', '/usr/local/bin/rg', '/usr/bin/rg']),
|
|
182
|
-
];
|
|
183
|
-
}
|
|
184
195
|
async function resolveRuntimeDependencyRoots(program) {
|
|
185
196
|
const candidates = program.startsWith('/opt/homebrew/')
|
|
186
197
|
? ['/opt/homebrew/opt', '/opt/homebrew/Cellar']
|