@atlaswork/atlascode 0.1.125 → 0.1.127
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/atlasweb-carrier.json +6 -0
- package/dist/cli.js +530 -18
- package/dist/web-session-runtime/atlascode/web/entry.d.ts +2 -0
- package/dist/web-session-runtime/atlascode/web/executionOutlet.d.ts +60 -0
- package/dist/web-session-runtime/atlascode/web/runtimeEntry.d.ts +16 -0
- package/dist/web-session-runtime/index.d.ts +1 -1
- package/dist/web-session-runtime/kernel/execution/executionOutlet.d.ts +60 -0
- package/dist/web-session-runtime/kernel/protocol/webExecutionV0.d.ts +542 -0
- package/dist/web-session-runtime/kernel/state/injection.d.ts +28 -0
- package/dist/web-session-runtime/kernel/state/ports.d.ts +67 -0
- package/dist/web-session-runtime-execution/atlascode/web/contract.d.ts +10 -0
- package/dist/web-session-runtime-execution/atlascode/web/cursorLedger.d.ts +63 -0
- package/dist/web-session-runtime-execution/atlascode/web/entry.d.ts +26 -0
- package/dist/web-session-runtime-execution/atlascode/web/errors.d.ts +16 -0
- package/dist/web-session-runtime-execution/atlascode/web/follow.d.ts +82 -0
- package/dist/web-session-runtime-execution/atlascode/web/limits.d.ts +63 -0
- package/dist/web-session-runtime-execution/atlascode/web/projection.d.ts +69 -0
- package/dist/web-session-runtime-execution/atlascode/web/readonlyRuntime.d.ts +156 -0
- package/dist/web-session-runtime-execution/atlascode/web/runtimeDefault.d.ts +26 -0
- package/dist/web-session-runtime-execution/atlascode/web/sessionStoreAdapter.d.ts +70 -0
- package/dist/web-session-runtime-execution/engine/session/env.d.ts +32 -0
- package/dist/web-session-runtime-execution/engine/session/firstPrompt.d.ts +21 -0
- package/dist/web-session-runtime-execution/engine/session/json.d.ts +27 -0
- package/dist/web-session-runtime-execution/engine/session/load.d.ts +88 -0
- package/dist/web-session-runtime-execution/engine/session/paths.d.ts +25 -0
- package/dist/web-session-runtime-execution/engine/session/predicates.d.ts +55 -0
- package/dist/web-session-runtime-execution/engine/session/readonly.d.ts +29 -0
- package/dist/web-session-runtime-execution/engine/session/scanner.d.ts +26 -0
- package/dist/web-session-runtime-execution/engine/session/search.d.ts +44 -0
- package/dist/web-session-runtime-execution/engine/session/types.d.ts +379 -0
- package/dist/web-session-runtime-execution/index.d.ts +1 -0
- package/dist/web-session-runtime-execution/index.js +8681 -0
- package/dist/web-session-runtime-execution/kernel/execution/executionComposition.d.ts +18 -0
- package/dist/web-session-runtime-execution/kernel/execution/executionKernel.d.ts +77 -0
- package/dist/web-session-runtime-execution/kernel/execution/executionOutlet.d.ts +60 -0
- package/dist/web-session-runtime-execution/kernel/protocol/webExecutionV0.d.ts +547 -0
- package/dist/web-session-runtime-execution/kernel/protocol/webSessionV0.d.ts +727 -0
- package/dist/web-session-runtime-execution/kernel/state/injection.d.ts +28 -0
- package/dist/web-session-runtime-execution/kernel/state/ports.d.ts +67 -0
- package/dist/web-session-runtime-execution/shared/ProductDefinition.d.ts +47 -0
- package/dist/web-session-runtime-execution/shared/agentRoleTemplates.d.ts +44 -0
- package/dist/web-session-runtime-execution/shared/agentSwarmsEnabled.d.ts +5 -0
- package/dist/web-session-runtime-execution/shared/boundedImageRead.d.ts +31 -0
- package/dist/web-session-runtime-execution/shared/circular-buffer.d.ts +42 -0
- package/dist/web-session-runtime-execution/shared/configDir.d.ts +57 -0
- package/dist/web-session-runtime-execution/shared/constants.d.ts +19 -0
- package/dist/web-session-runtime-execution/shared/debug.d.ts +32 -0
- package/dist/web-session-runtime-execution/shared/env.d.ts +38 -0
- package/dist/web-session-runtime-execution/shared/errors.d.ts +56 -0
- package/dist/web-session-runtime-execution/shared/feature.d.ts +25 -0
- package/dist/web-session-runtime-execution/shared/format.d.ts +11 -0
- package/dist/web-session-runtime-execution/shared/fs-operations.d.ts +116 -0
- package/dist/web-session-runtime-execution/shared/hash.d.ts +13 -0
- package/dist/web-session-runtime-execution/shared/identity.d.ts +23 -0
- package/dist/web-session-runtime-execution/shared/index.d.ts +46 -0
- package/dist/web-session-runtime-execution/shared/lazySchema.d.ts +12 -0
- package/dist/web-session-runtime-execution/shared/log.d.ts +1 -0
- package/dist/web-session-runtime-execution/shared/path.d.ts +22 -0
- package/dist/web-session-runtime-execution/shared/pdfPageImages.d.ts +19 -0
- package/dist/web-session-runtime-execution/shared/pdfReference.d.ts +70 -0
- package/dist/web-session-runtime-execution/shared/permissionDeadline.d.ts +24 -0
- package/dist/web-session-runtime-execution/shared/platform.d.ts +8 -0
- package/dist/web-session-runtime-execution/shared/stringUtils.d.ts +110 -0
- package/dist/web-session-runtime-execution/shared/swarmSchemaFilter.d.ts +23 -0
- package/dist/web-session-runtime-execution/shared/teamFileSchema.d.ts +151 -0
- package/dist/web-session-runtime-execution/shared/teamInboxSchema.d.ts +112 -0
- package/dist/web-session-runtime-execution/shared/teammateContext.d.ts +89 -0
- package/dist/web-session-runtime-execution/shared/tempDir.d.ts +1 -0
- package/dist/web-session-runtime-execution/shared/textEncoding.d.ts +41 -0
- package/dist/web-session-runtime-execution/shared/tokenEstimation.d.ts +36 -0
- package/dist/web-session-runtime-execution/shared/types-session.d.ts +266 -0
- package/dist/web-session-runtime-execution/shared/types.d.ts +190 -0
- package/dist/web-session-runtime-execution/shared/unc.d.ts +5 -0
- package/dist/web-session-runtime-execution/shared/windowsPaths.d.ts +24 -0
- package/package.json +10 -3
package/dist/cli.js
CHANGED
|
@@ -6050,6 +6050,9 @@ function _ensureDefaultMemoizer() {
|
|
|
6050
6050
|
function string2(params) {
|
|
6051
6051
|
return _string(ZodString, params);
|
|
6052
6052
|
}
|
|
6053
|
+
function uuid2(params) {
|
|
6054
|
+
return _uuid(ZodUUID, params);
|
|
6055
|
+
}
|
|
6053
6056
|
function url(params) {
|
|
6054
6057
|
return _url(ZodURL, params);
|
|
6055
6058
|
}
|
|
@@ -29405,23 +29408,69 @@ function sortLogs(logs) {
|
|
|
29405
29408
|
});
|
|
29406
29409
|
}
|
|
29407
29410
|
|
|
29411
|
+
// src/kernel/state/injection.ts
|
|
29412
|
+
function armKernelInjectionGuard() {
|
|
29413
|
+
_armed = true;
|
|
29414
|
+
}
|
|
29415
|
+
function claimKernelInjectionSlot(slot) {
|
|
29416
|
+
if (!_armed)
|
|
29417
|
+
return;
|
|
29418
|
+
if (_consumed[slot]) {
|
|
29419
|
+
throw new Error(`set-once 守卫:${slot} 二次注入 = 硬错(B0 合同 §7;产品模式静默覆盖语义不可达)`);
|
|
29420
|
+
}
|
|
29421
|
+
_consumed[slot] = true;
|
|
29422
|
+
}
|
|
29423
|
+
function isKernelInjectionArmed() {
|
|
29424
|
+
return _armed;
|
|
29425
|
+
}
|
|
29426
|
+
function setKernelBootstrapState(port) {
|
|
29427
|
+
claimKernelInjectionSlot("bootstrapState");
|
|
29428
|
+
_statePort = port;
|
|
29429
|
+
}
|
|
29430
|
+
function setKernelBootstrapNoopSeam(seam) {
|
|
29431
|
+
claimKernelInjectionSlot("noopSeam");
|
|
29432
|
+
_noopSeam = seam;
|
|
29433
|
+
}
|
|
29434
|
+
function getKernelBootstrapNoopSeam() {
|
|
29435
|
+
return _noopSeam ?? DEFAULT_NOOP_SEAM;
|
|
29436
|
+
}
|
|
29437
|
+
var _statePort = null, _noopSeam = null, _armed = false, _consumed, DEFAULT_NOOP_SEAM;
|
|
29438
|
+
var init_injection = __esm(() => {
|
|
29439
|
+
_consumed = {
|
|
29440
|
+
bootstrapState: false,
|
|
29441
|
+
noopSeam: false,
|
|
29442
|
+
sessionEnv: false
|
|
29443
|
+
};
|
|
29444
|
+
DEFAULT_NOOP_SEAM = {
|
|
29445
|
+
addSlowOperation() {},
|
|
29446
|
+
waitForScrollIdle() {},
|
|
29447
|
+
setLastAPIRequest() {},
|
|
29448
|
+
setLastAPIRequestMessages() {}
|
|
29449
|
+
};
|
|
29450
|
+
});
|
|
29451
|
+
|
|
29408
29452
|
// src/engine/session/env.ts
|
|
29409
29453
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
29410
29454
|
import { homedir as homedir3 } from "os";
|
|
29411
29455
|
import { join as join4 } from "path";
|
|
29412
29456
|
function setSessionEnv(partial) {
|
|
29457
|
+
claimKernelInjectionSlot("sessionEnv");
|
|
29413
29458
|
_env = { ..._env, ...partial };
|
|
29414
29459
|
}
|
|
29415
29460
|
function getSessionEnv() {
|
|
29416
29461
|
return _env;
|
|
29417
29462
|
}
|
|
29418
29463
|
function resetSessionEnv() {
|
|
29464
|
+
if (isKernelInjectionArmed()) {
|
|
29465
|
+
throw new Error("set-once 守卫:armed 态 resetSessionEnv = 硬错(单向不可逆;注入→reset 解除→再注入 = 静默顶替绕行向量)");
|
|
29466
|
+
}
|
|
29419
29467
|
_sessionId = undefined;
|
|
29420
29468
|
_originalCwd = undefined;
|
|
29421
29469
|
_env = defaultEnv;
|
|
29422
29470
|
}
|
|
29423
29471
|
var _sessionId, _originalCwd, _cleanupHandlers, defaultEnv, _env;
|
|
29424
29472
|
var init_env = __esm(() => {
|
|
29473
|
+
init_injection();
|
|
29425
29474
|
_cleanupHandlers = [];
|
|
29426
29475
|
defaultEnv = {
|
|
29427
29476
|
getSessionId: () => _sessionId ??= randomUUID3(),
|
|
@@ -95720,24 +95769,481 @@ var init_cli = __esm(() => {
|
|
|
95720
95769
|
init_hooksWiring();
|
|
95721
95770
|
});
|
|
95722
95771
|
|
|
95723
|
-
// src/kernel/
|
|
95724
|
-
|
|
95725
|
-
|
|
95726
|
-
|
|
95727
|
-
|
|
95728
|
-
|
|
95772
|
+
// src/kernel/protocol/webExecutionV0.ts
|
|
95773
|
+
var EXECUTION_SCHEMA_VERSION = 0, EXECUTION_PROTOCOL_VERSION = "v0", ExecutionOpaqueIdSchema, ExecutionCursorSchema, ExecutionBindSchema, EnvelopeFields, EventEnvelopeFields, CapabilityProbeCommandSchema, TurnSubmitCommandSchema, TargetTurnPayload, TurnCancelCommandSchema, QueueRemoveCommandSchema, ApprovalDecideCommandSchema, FollowResumeCommandSchema, WebExecutionCommandSchema, WebExecutionErrorSchema, EXECUTION_CAPABILITY_DISABLED_CODE = "capabilityDisabled", TurnAcceptedEventSchema, TurnStartedEventSchema, TurnDeltaEventSchema, TurnCompletedEventSchema, TurnFailedEventSchema, TurnCancelledEventSchema, ApprovalRequestedEventSchema, ApprovalSettledEventSchema, QueueUpdatedEventSchema, ErrorEventSchema, WebExecutionEventSchema;
|
|
95774
|
+
var init_webExecutionV0 = __esm(() => {
|
|
95775
|
+
init_v4();
|
|
95776
|
+
ExecutionOpaqueIdSchema = string2().min(1).max(128);
|
|
95777
|
+
ExecutionCursorSchema = string2().min(1).max(512);
|
|
95778
|
+
ExecutionBindSchema = strictObject({
|
|
95779
|
+
workspaceId: ExecutionOpaqueIdSchema,
|
|
95780
|
+
sessionId: ExecutionOpaqueIdSchema,
|
|
95781
|
+
turnId: ExecutionOpaqueIdSchema.optional()
|
|
95782
|
+
});
|
|
95783
|
+
EnvelopeFields = {
|
|
95784
|
+
v: literal(EXECUTION_SCHEMA_VERSION),
|
|
95785
|
+
id: uuid2(),
|
|
95786
|
+
ts: number2(),
|
|
95787
|
+
bind: ExecutionBindSchema
|
|
95788
|
+
};
|
|
95789
|
+
EventEnvelopeFields = {
|
|
95790
|
+
...EnvelopeFields,
|
|
95791
|
+
cursor: ExecutionCursorSchema
|
|
95792
|
+
};
|
|
95793
|
+
CapabilityProbeCommandSchema = strictObject({
|
|
95794
|
+
...EnvelopeFields,
|
|
95795
|
+
type: literal("capability.probe"),
|
|
95796
|
+
payload: strictObject({})
|
|
95797
|
+
});
|
|
95798
|
+
TurnSubmitCommandSchema = strictObject({
|
|
95799
|
+
...EnvelopeFields,
|
|
95800
|
+
type: literal("turn.submit"),
|
|
95801
|
+
payload: strictObject({
|
|
95802
|
+
submitId: uuid2(),
|
|
95803
|
+
text: string2().min(1)
|
|
95804
|
+
})
|
|
95805
|
+
});
|
|
95806
|
+
TargetTurnPayload = { targetTurnId: ExecutionOpaqueIdSchema };
|
|
95807
|
+
TurnCancelCommandSchema = strictObject({
|
|
95808
|
+
...EnvelopeFields,
|
|
95809
|
+
type: literal("turn.cancel"),
|
|
95810
|
+
payload: strictObject(TargetTurnPayload)
|
|
95811
|
+
});
|
|
95812
|
+
QueueRemoveCommandSchema = strictObject({
|
|
95813
|
+
...EnvelopeFields,
|
|
95814
|
+
type: literal("queue.remove"),
|
|
95815
|
+
payload: strictObject(TargetTurnPayload)
|
|
95816
|
+
});
|
|
95817
|
+
ApprovalDecideCommandSchema = strictObject({
|
|
95818
|
+
...EnvelopeFields,
|
|
95819
|
+
bind: ExecutionBindSchema.required({ turnId: true }),
|
|
95820
|
+
type: literal("approval.decide"),
|
|
95821
|
+
payload: strictObject({
|
|
95822
|
+
approvalId: ExecutionOpaqueIdSchema,
|
|
95823
|
+
decision: _enum(["approved", "denied"])
|
|
95824
|
+
})
|
|
95825
|
+
});
|
|
95826
|
+
FollowResumeCommandSchema = strictObject({
|
|
95827
|
+
...EnvelopeFields,
|
|
95828
|
+
type: literal("follow.resume"),
|
|
95829
|
+
payload: strictObject({
|
|
95830
|
+
cursor: ExecutionCursorSchema.optional()
|
|
95831
|
+
})
|
|
95832
|
+
});
|
|
95833
|
+
WebExecutionCommandSchema = discriminatedUnion("type", [
|
|
95834
|
+
CapabilityProbeCommandSchema,
|
|
95835
|
+
TurnSubmitCommandSchema,
|
|
95836
|
+
TurnCancelCommandSchema,
|
|
95837
|
+
QueueRemoveCommandSchema,
|
|
95838
|
+
ApprovalDecideCommandSchema,
|
|
95839
|
+
FollowResumeCommandSchema
|
|
95840
|
+
]);
|
|
95841
|
+
WebExecutionErrorSchema = strictObject({
|
|
95842
|
+
code: string2().min(1).max(128),
|
|
95843
|
+
message: string2().max(1024),
|
|
95844
|
+
retryable: boolean2()
|
|
95845
|
+
});
|
|
95846
|
+
TurnAcceptedEventSchema = strictObject({
|
|
95847
|
+
...EventEnvelopeFields,
|
|
95848
|
+
type: literal("turn.accepted"),
|
|
95849
|
+
payload: strictObject({ submitId: uuid2() })
|
|
95850
|
+
});
|
|
95851
|
+
TurnStartedEventSchema = strictObject({
|
|
95852
|
+
...EventEnvelopeFields,
|
|
95853
|
+
type: literal("turn.started"),
|
|
95854
|
+
payload: strictObject({})
|
|
95855
|
+
});
|
|
95856
|
+
TurnDeltaEventSchema = strictObject({
|
|
95857
|
+
...EventEnvelopeFields,
|
|
95858
|
+
type: literal("turn.delta"),
|
|
95859
|
+
payload: strictObject({ text: string2() })
|
|
95860
|
+
});
|
|
95861
|
+
TurnCompletedEventSchema = strictObject({
|
|
95862
|
+
...EventEnvelopeFields,
|
|
95863
|
+
type: literal("turn.completed"),
|
|
95864
|
+
payload: strictObject({})
|
|
95865
|
+
});
|
|
95866
|
+
TurnFailedEventSchema = strictObject({
|
|
95867
|
+
...EventEnvelopeFields,
|
|
95868
|
+
type: literal("turn.failed"),
|
|
95869
|
+
payload: strictObject({ message: string2().max(1024) })
|
|
95870
|
+
});
|
|
95871
|
+
TurnCancelledEventSchema = strictObject({
|
|
95872
|
+
...EventEnvelopeFields,
|
|
95873
|
+
type: literal("turn.cancelled"),
|
|
95874
|
+
payload: strictObject({})
|
|
95875
|
+
});
|
|
95876
|
+
ApprovalRequestedEventSchema = strictObject({
|
|
95877
|
+
...EventEnvelopeFields,
|
|
95878
|
+
type: literal("approval.requested"),
|
|
95879
|
+
payload: strictObject({ approvalId: ExecutionOpaqueIdSchema })
|
|
95880
|
+
});
|
|
95881
|
+
ApprovalSettledEventSchema = strictObject({
|
|
95882
|
+
...EventEnvelopeFields,
|
|
95883
|
+
type: literal("approval.settled"),
|
|
95884
|
+
payload: strictObject({
|
|
95885
|
+
approvalId: ExecutionOpaqueIdSchema,
|
|
95886
|
+
decision: _enum(["approved", "denied", "expired", "voidedByCancel"]),
|
|
95887
|
+
actorId: ExecutionOpaqueIdSchema,
|
|
95888
|
+
timestamp: number2()
|
|
95889
|
+
})
|
|
95890
|
+
});
|
|
95891
|
+
QueueUpdatedEventSchema = strictObject({
|
|
95892
|
+
...EventEnvelopeFields,
|
|
95893
|
+
type: literal("queue.updated"),
|
|
95894
|
+
payload: strictObject({ depth: number2().int().min(0) })
|
|
95895
|
+
});
|
|
95896
|
+
ErrorEventSchema = strictObject({
|
|
95897
|
+
...EventEnvelopeFields,
|
|
95898
|
+
type: literal("error"),
|
|
95899
|
+
payload: strictObject({ error: WebExecutionErrorSchema })
|
|
95900
|
+
});
|
|
95901
|
+
WebExecutionEventSchema = discriminatedUnion("type", [
|
|
95902
|
+
TurnAcceptedEventSchema,
|
|
95903
|
+
TurnStartedEventSchema,
|
|
95904
|
+
TurnDeltaEventSchema,
|
|
95905
|
+
TurnCompletedEventSchema,
|
|
95906
|
+
TurnFailedEventSchema,
|
|
95907
|
+
TurnCancelledEventSchema,
|
|
95908
|
+
ApprovalRequestedEventSchema,
|
|
95909
|
+
ApprovalSettledEventSchema,
|
|
95910
|
+
QueueUpdatedEventSchema,
|
|
95911
|
+
ErrorEventSchema
|
|
95912
|
+
]);
|
|
95913
|
+
});
|
|
95914
|
+
|
|
95915
|
+
// src/kernel/execution/executionOutlet.ts
|
|
95916
|
+
function createExecutionOutlet(options) {
|
|
95917
|
+
const isEnabled = options.isExecutionEnabled ?? (() => false);
|
|
95918
|
+
return {
|
|
95919
|
+
probe: () => ({
|
|
95920
|
+
type: "capability.probe",
|
|
95921
|
+
enabled: isEnabled(),
|
|
95922
|
+
protocolVersion: EXECUTION_PROTOCOL_VERSION
|
|
95923
|
+
}),
|
|
95924
|
+
handle: async (command) => {
|
|
95925
|
+
if (command.type === "capability.probe") {
|
|
95926
|
+
return {
|
|
95927
|
+
type: "capability.probe",
|
|
95928
|
+
enabled: isEnabled(),
|
|
95929
|
+
protocolVersion: EXECUTION_PROTOCOL_VERSION
|
|
95930
|
+
};
|
|
95931
|
+
}
|
|
95932
|
+
if (!isEnabled()) {
|
|
95933
|
+
return capabilityDisabledError(command.type);
|
|
95934
|
+
}
|
|
95935
|
+
if (command.type === "follow.resume") {
|
|
95936
|
+
const replay = options.resumeExecution?.({ workspaceId: command.bind.workspaceId, sessionId: command.bind.sessionId }, command.payload.cursor);
|
|
95937
|
+
if (!replay || replay.kind === "expired") {
|
|
95938
|
+
return { code: "cursorExpired", message: "游标过期/溢出丢弃:按基线替换恢复(合同 §6)", retryable: false };
|
|
95939
|
+
}
|
|
95940
|
+
return replay;
|
|
95941
|
+
}
|
|
95942
|
+
return options.dispatchCommand(command);
|
|
95943
|
+
},
|
|
95944
|
+
followResume: (bind, cursor) => {
|
|
95945
|
+
if (!isEnabled() || !options.resumeExecution) {
|
|
95946
|
+
return capabilityDisabledError("follow.resume");
|
|
95947
|
+
}
|
|
95948
|
+
return options.resumeExecution(bind, cursor);
|
|
95949
|
+
}
|
|
95950
|
+
};
|
|
95951
|
+
}
|
|
95952
|
+
var capabilityDisabledError = (type) => ({
|
|
95953
|
+
code: EXECUTION_CAPABILITY_DISABLED_CODE,
|
|
95954
|
+
message: `执行能力未开启(默认 fail-closed):${type} 被拒且内核零痕迹(B0 合同 §2/E1)`,
|
|
95955
|
+
retryable: false
|
|
95956
|
+
});
|
|
95957
|
+
var init_executionOutlet = __esm(() => {
|
|
95958
|
+
init_webExecutionV0();
|
|
95959
|
+
});
|
|
95960
|
+
|
|
95961
|
+
// src/kernel/execution/executionKernel.ts
|
|
95962
|
+
function createExecutionKernel(options) {
|
|
95963
|
+
const now = options.now ?? (() => Date.now());
|
|
95964
|
+
const actorId = options.actorId ?? (() => "kernel");
|
|
95965
|
+
const queueDepth = options.queueDepth ?? EXECUTION_QUEUE_DEPTH;
|
|
95966
|
+
const approvalTimeoutMs = options.approvalTimeoutMs ?? EXECUTION_APPROVAL_TIMEOUT_MS;
|
|
95967
|
+
const maxTextBytes = options.maxTextBytes ?? EXECUTION_MAX_TEXT_BYTES;
|
|
95968
|
+
const followBufferLimit = options.followBufferLimit ?? EXECUTION_FOLLOW_BUFFER_LIMIT;
|
|
95969
|
+
const maxDeltaBytes = EXECUTION_MAX_DELTA_BYTES;
|
|
95970
|
+
const streams = new Map;
|
|
95971
|
+
const approvals = new Map;
|
|
95972
|
+
const subscribers = new Set;
|
|
95973
|
+
const turnStates = new Map;
|
|
95974
|
+
let turnCounter = 0;
|
|
95975
|
+
let approvalCounter = 0;
|
|
95976
|
+
const streamOf = (ws, s) => {
|
|
95977
|
+
const key = streamKey(ws, s);
|
|
95978
|
+
let st = streams.get(key);
|
|
95979
|
+
if (!st) {
|
|
95980
|
+
st = {
|
|
95981
|
+
cursor: 0,
|
|
95982
|
+
buffer: [],
|
|
95983
|
+
overflowed: false,
|
|
95984
|
+
queue: [],
|
|
95985
|
+
running: undefined,
|
|
95986
|
+
turns: new Map,
|
|
95987
|
+
idempotency: new Map
|
|
95988
|
+
};
|
|
95989
|
+
streams.set(key, st);
|
|
95990
|
+
}
|
|
95991
|
+
return st;
|
|
95992
|
+
};
|
|
95993
|
+
const err = (code, message, retryable = false) => ({
|
|
95994
|
+
code,
|
|
95995
|
+
message,
|
|
95996
|
+
retryable
|
|
95997
|
+
});
|
|
95998
|
+
const emit = (st, bind, type, payload) => {
|
|
95999
|
+
st.cursor += 1;
|
|
96000
|
+
if (st.buffer.length >= followBufferLimit) {
|
|
96001
|
+
st.overflowed = true;
|
|
96002
|
+
st.buffer.shift();
|
|
96003
|
+
}
|
|
96004
|
+
const event = {
|
|
96005
|
+
v: 0,
|
|
96006
|
+
id: crypto.randomUUID(),
|
|
96007
|
+
ts: now(),
|
|
96008
|
+
type,
|
|
96009
|
+
bind,
|
|
96010
|
+
cursor: String(st.cursor).padStart(16, "0"),
|
|
96011
|
+
payload
|
|
96012
|
+
};
|
|
96013
|
+
st.buffer.push(event);
|
|
96014
|
+
for (const cb of subscribers)
|
|
96015
|
+
cb(event);
|
|
96016
|
+
return event;
|
|
96017
|
+
};
|
|
96018
|
+
const settleApproval = (a, decision) => {
|
|
96019
|
+
if (a.settled)
|
|
96020
|
+
return;
|
|
96021
|
+
a.settled = true;
|
|
96022
|
+
if (a.timer)
|
|
96023
|
+
clearTimeout(a.timer);
|
|
96024
|
+
approvals.delete(a.approvalId);
|
|
96025
|
+
const st = streamOf(a.workspaceId, a.sessionId);
|
|
96026
|
+
const event = emit(st, { workspaceId: a.workspaceId, sessionId: a.sessionId, turnId: a.turnId }, "approval.settled", { approvalId: a.approvalId, decision, actorId: actorId(), timestamp: now() });
|
|
96027
|
+
a.resolve(decision);
|
|
96028
|
+
return event;
|
|
96029
|
+
};
|
|
96030
|
+
const settleTurn = (st, turn, terminal, failedMessage) => {
|
|
96031
|
+
if (turn.state === "completed" || turn.state === "failed" || turn.state === "cancelled") {
|
|
96032
|
+
return;
|
|
96033
|
+
}
|
|
96034
|
+
turn.state = terminal;
|
|
96035
|
+
turnStates.set(turn.turnId, terminal);
|
|
96036
|
+
if (terminal === "cancelled") {
|
|
96037
|
+
for (const a of [...approvals.values()]) {
|
|
96038
|
+
if (a.turnId === turn.turnId && !a.settled)
|
|
96039
|
+
settleApproval(a, "voidedByCancel");
|
|
96040
|
+
}
|
|
96041
|
+
}
|
|
96042
|
+
st.running = st.running?.turnId === turn.turnId ? undefined : st.running;
|
|
96043
|
+
const event = emit(st, { workspaceId: streamWs(st), sessionId: streamSess(st), turnId: turn.turnId }, `turn.${terminal}`, terminal === "failed" ? { message: failedMessage ?? "turn failed" } : {});
|
|
96044
|
+
pump(streamWs(st), streamSess(st));
|
|
96045
|
+
return event;
|
|
96046
|
+
};
|
|
96047
|
+
const wsByStream = new Map;
|
|
96048
|
+
const sessByStream = new Map;
|
|
96049
|
+
const streamWs = (st) => wsByStream.get(st) ?? "";
|
|
96050
|
+
const streamSess = (st) => sessByStream.get(st) ?? "";
|
|
96051
|
+
const origStreamOf = streamOf;
|
|
96052
|
+
const streamOfTracked = (ws, s) => {
|
|
96053
|
+
const st = origStreamOf(ws, s);
|
|
96054
|
+
if (!wsByStream.has(st)) {
|
|
96055
|
+
wsByStream.set(st, ws);
|
|
96056
|
+
sessByStream.set(st, s);
|
|
96057
|
+
}
|
|
96058
|
+
return st;
|
|
96059
|
+
};
|
|
96060
|
+
const pump = (ws, s) => {
|
|
96061
|
+
const st = streamOfTracked(ws, s);
|
|
96062
|
+
if (st.running || st.queue.length === 0)
|
|
96063
|
+
return;
|
|
96064
|
+
const turn = st.queue.shift();
|
|
96065
|
+
turn.state = "running";
|
|
96066
|
+
turnStates.set(turn.turnId, "running");
|
|
96067
|
+
turn.controller = new AbortController;
|
|
96068
|
+
st.running = turn;
|
|
96069
|
+
emit(st, { workspaceId: ws, sessionId: s, turnId: turn.turnId }, "turn.started", {});
|
|
96070
|
+
(async () => {
|
|
96071
|
+
let outcome;
|
|
96072
|
+
try {
|
|
96073
|
+
outcome = await options.runTurn({
|
|
96074
|
+
bind: { workspaceId: ws, sessionId: s, turnId: turn.turnId },
|
|
96075
|
+
text: turn.text,
|
|
96076
|
+
signal: turn.controller.signal,
|
|
96077
|
+
emitDelta: (text) => {
|
|
96078
|
+
if (turn.state !== "running" || turn.controller?.signal.aborted)
|
|
96079
|
+
return;
|
|
96080
|
+
if (Buffer.byteLength(text, "utf8") > maxDeltaBytes) {
|
|
96081
|
+
settleTurn(st, turn, "failed", `turn.delta 超 ${maxDeltaBytes} 字节上限(合同 §8)`);
|
|
96082
|
+
return;
|
|
96083
|
+
}
|
|
96084
|
+
emit(st, { workspaceId: ws, sessionId: s, turnId: turn.turnId }, "turn.delta", { text });
|
|
96085
|
+
},
|
|
96086
|
+
requestApproval: () => {
|
|
96087
|
+
const approvalId = `appr-${++approvalCounter}`;
|
|
96088
|
+
return new Promise((resolve) => {
|
|
96089
|
+
const approval = {
|
|
96090
|
+
approvalId,
|
|
96091
|
+
turnId: turn.turnId,
|
|
96092
|
+
workspaceId: ws,
|
|
96093
|
+
sessionId: s,
|
|
96094
|
+
requestedAt: now(),
|
|
96095
|
+
settled: false,
|
|
96096
|
+
timer: undefined,
|
|
96097
|
+
resolve
|
|
96098
|
+
};
|
|
96099
|
+
approvals.set(approvalId, approval);
|
|
96100
|
+
emit(st, { workspaceId: ws, sessionId: s, turnId: turn.turnId }, "approval.requested", { approvalId });
|
|
96101
|
+
approval.timer = setTimeout(() => {
|
|
96102
|
+
settleApproval(approval, "expired");
|
|
96103
|
+
}, approvalTimeoutMs);
|
|
96104
|
+
approval.timer.unref?.();
|
|
96105
|
+
});
|
|
96106
|
+
}
|
|
96107
|
+
});
|
|
96108
|
+
} catch (e) {
|
|
96109
|
+
outcome = "failed";
|
|
96110
|
+
settleTurn(st, turn, "failed", e instanceof Error ? e.message : String(e));
|
|
96111
|
+
return;
|
|
96112
|
+
}
|
|
96113
|
+
if (outcome === "failed") {
|
|
96114
|
+
settleTurn(st, turn, "failed");
|
|
96115
|
+
} else {
|
|
96116
|
+
settleTurn(st, turn, outcome);
|
|
96117
|
+
}
|
|
96118
|
+
})();
|
|
96119
|
+
};
|
|
96120
|
+
const handleCommand = async (command) => {
|
|
96121
|
+
const ws = command.bind.workspaceId;
|
|
96122
|
+
const s = command.bind.sessionId;
|
|
96123
|
+
if (ws.includes("\x00") || s.includes("\x00")) {
|
|
96124
|
+
return err("invalidBind", "workspaceId/sessionId 不得含 NUL 分隔符(流键碰撞面)");
|
|
96125
|
+
}
|
|
96126
|
+
if (command.type === "turn.submit") {
|
|
96127
|
+
const st = streamOfTracked(ws, s);
|
|
96128
|
+
const recorded = st.idempotency.get(command.payload.submitId);
|
|
96129
|
+
if (recorded)
|
|
96130
|
+
return recorded;
|
|
96131
|
+
if (Buffer.byteLength(command.payload.text, "utf8") > maxTextBytes) {
|
|
96132
|
+
const rejection = err("resourceLimit", `turn.submit 超过 ${maxTextBytes} 字节上限(合同 §8)`);
|
|
96133
|
+
st.idempotency.set(command.payload.submitId, rejection);
|
|
96134
|
+
return rejection;
|
|
96135
|
+
}
|
|
96136
|
+
if (st.queue.length + (st.running ? 1 : 0) >= queueDepth) {
|
|
96137
|
+
const rejection = err("queueFull", `会话队列已满(深度 ${queueDepth},合同 §8)`, true);
|
|
96138
|
+
st.idempotency.set(command.payload.submitId, rejection);
|
|
96139
|
+
return rejection;
|
|
96140
|
+
}
|
|
96141
|
+
const turn = {
|
|
96142
|
+
turnId: `turn-${++turnCounter}`,
|
|
96143
|
+
submitId: command.payload.submitId,
|
|
96144
|
+
text: command.payload.text,
|
|
96145
|
+
state: "queued"
|
|
96146
|
+
};
|
|
96147
|
+
st.turns.set(turn.turnId, turn);
|
|
96148
|
+
turnStates.set(turn.turnId, "queued");
|
|
96149
|
+
st.queue.push(turn);
|
|
96150
|
+
const accepted = emit(st, { workspaceId: ws, sessionId: s, turnId: turn.turnId }, "turn.accepted", { submitId: command.payload.submitId });
|
|
96151
|
+
st.idempotency.set(command.payload.submitId, accepted);
|
|
96152
|
+
pump(ws, s);
|
|
96153
|
+
return accepted;
|
|
96154
|
+
}
|
|
96155
|
+
if (command.type === "turn.cancel" || command.type === "queue.remove") {
|
|
96156
|
+
const st = streamOfTracked(ws, s);
|
|
96157
|
+
const turn = st.turns.get(command.payload.targetTurnId);
|
|
96158
|
+
if (!turn)
|
|
96159
|
+
return err("notFound", `目标回合不存在:${command.payload.targetTurnId}`);
|
|
96160
|
+
if (turn.state === "queued") {
|
|
96161
|
+
st.queue = st.queue.filter((t) => t.turnId !== turn.turnId);
|
|
96162
|
+
turn.state = "cancelled";
|
|
96163
|
+
turnStates.set(turn.turnId, "cancelled");
|
|
96164
|
+
return emit(st, { workspaceId: ws, sessionId: s, turnId: turn.turnId }, "turn.cancelled", {});
|
|
96165
|
+
}
|
|
96166
|
+
if (turn.state === "running") {
|
|
96167
|
+
turn.controller?.abort();
|
|
96168
|
+
turn.state = "cancelled";
|
|
96169
|
+
turnStates.set(turn.turnId, "cancelled");
|
|
96170
|
+
const event = emit(st, { workspaceId: ws, sessionId: s, turnId: turn.turnId }, "turn.cancelled", {});
|
|
96171
|
+
for (const a of [...approvals.values()]) {
|
|
96172
|
+
if (a.turnId === turn.turnId && !a.settled)
|
|
96173
|
+
settleApproval(a, "voidedByCancel");
|
|
96174
|
+
}
|
|
96175
|
+
st.running = st.running?.turnId === turn.turnId ? undefined : st.running;
|
|
96176
|
+
pump(ws, s);
|
|
96177
|
+
return event;
|
|
96178
|
+
}
|
|
96179
|
+
return err("alreadySettled", `回合已终态(${turn.state}),边界错误不改状态(合同 §4)`);
|
|
96180
|
+
}
|
|
96181
|
+
if (command.type === "approval.decide") {
|
|
96182
|
+
const a = approvals.get(command.payload.approvalId);
|
|
96183
|
+
if (!a)
|
|
96184
|
+
return err("notFound", `待批操作不存在或已结算:${command.payload.approvalId}`);
|
|
96185
|
+
if (command.bind.turnId !== a.turnId || command.bind.workspaceId !== a.workspaceId || command.bind.sessionId !== a.sessionId) {
|
|
96186
|
+
return err("approvalBindMismatch", `decide bind 三元组与审批归属不一致(合同 §5)`);
|
|
96187
|
+
}
|
|
96188
|
+
if (a.settled || now() - a.requestedAt >= approvalTimeoutMs) {
|
|
96189
|
+
if (!a.settled)
|
|
96190
|
+
settleApproval(a, "expired");
|
|
96191
|
+
return err("alreadySettled", "待批操作已结算(过期/已决),边界错误(合同 §5)");
|
|
96192
|
+
}
|
|
96193
|
+
return settleApproval(a, command.payload.decision);
|
|
96194
|
+
}
|
|
96195
|
+
return err("notImplemented", "follow.resume 于 S4 切片落地(合同 §6)");
|
|
96196
|
+
};
|
|
96197
|
+
return {
|
|
96198
|
+
handleCommand,
|
|
96199
|
+
replaySince: (workspaceId, sessionId, cursor) => {
|
|
96200
|
+
const st = streams.get(streamKey(workspaceId, sessionId));
|
|
96201
|
+
const headCursor = String(st?.cursor ?? 0).padStart(16, "0");
|
|
96202
|
+
if (!st || !cursor)
|
|
96203
|
+
return { kind: "baseline", events: [], headCursor };
|
|
96204
|
+
if (st.overflowed)
|
|
96205
|
+
return { kind: "expired", events: [], headCursor };
|
|
96206
|
+
const idx = st.buffer.findIndex((e) => e.cursor === cursor);
|
|
96207
|
+
if (idx < 0)
|
|
96208
|
+
return { kind: "expired", events: [], headCursor };
|
|
96209
|
+
return { kind: "delta", events: st.buffer.slice(idx + 1), headCursor };
|
|
96210
|
+
},
|
|
96211
|
+
onEvent: (cb) => {
|
|
96212
|
+
subscribers.add(cb);
|
|
96213
|
+
return () => subscribers.delete(cb);
|
|
96214
|
+
},
|
|
96215
|
+
turnStates,
|
|
96216
|
+
bufferState: (workspaceId, sessionId) => {
|
|
96217
|
+
const st = streams.get(streamKey(workspaceId, sessionId));
|
|
96218
|
+
return st ? { overflowed: st.overflowed, kept: st.buffer.length } : { overflowed: false, kept: 0 };
|
|
96219
|
+
}
|
|
96220
|
+
};
|
|
95729
96221
|
}
|
|
95730
|
-
|
|
95731
|
-
|
|
96222
|
+
var EXECUTION_QUEUE_DEPTH = 16, EXECUTION_APPROVAL_TIMEOUT_MS = 300000, EXECUTION_MAX_TEXT_BYTES, EXECUTION_FOLLOW_BUFFER_LIMIT = 1e4, EXECUTION_MAX_DELTA_BYTES, streamKey = (ws, s) => `${ws}\x00${s}`;
|
|
96223
|
+
var init_executionKernel = __esm(() => {
|
|
96224
|
+
EXECUTION_MAX_TEXT_BYTES = 2 * 1024 * 1024;
|
|
96225
|
+
EXECUTION_MAX_DELTA_BYTES = 256 * 1024;
|
|
96226
|
+
});
|
|
96227
|
+
|
|
96228
|
+
// src/kernel/execution/executionComposition.ts
|
|
96229
|
+
function createExecutionComposition(options = {}) {
|
|
96230
|
+
const kernel = createExecutionKernel({
|
|
96231
|
+
runTurn: options.runTurn ?? (async () => {
|
|
96232
|
+
throw new Error("执行能力 runTurn 真体未接线(B0 执行出口波 S4 落地细化附注:引擎深缝候后续切片;能力开关 fail-closed off 时不可达)");
|
|
96233
|
+
}),
|
|
96234
|
+
actorId: options.actorId ?? (() => "atlas-local-ambient"),
|
|
96235
|
+
...options.now !== undefined ? { now: options.now } : {}
|
|
96236
|
+
});
|
|
96237
|
+
const outlet = createExecutionOutlet({
|
|
96238
|
+
isExecutionEnabled: () => process.env.ATLAS_WEB_EXECUTION_ENABLED === "1",
|
|
96239
|
+
dispatchCommand: (command) => kernel.handleCommand(command),
|
|
96240
|
+
resumeExecution: (bind, cursor) => kernel.replaySince(bind.workspaceId, bind.sessionId, cursor)
|
|
96241
|
+
});
|
|
96242
|
+
return { kernel, outlet };
|
|
95732
96243
|
}
|
|
95733
|
-
var
|
|
95734
|
-
|
|
95735
|
-
|
|
95736
|
-
addSlowOperation() {},
|
|
95737
|
-
waitForScrollIdle() {},
|
|
95738
|
-
setLastAPIRequest() {},
|
|
95739
|
-
setLastAPIRequestMessages() {}
|
|
95740
|
-
};
|
|
96244
|
+
var init_executionComposition = __esm(() => {
|
|
96245
|
+
init_executionOutlet();
|
|
96246
|
+
init_executionKernel();
|
|
95741
96247
|
});
|
|
95742
96248
|
|
|
95743
96249
|
// src/kernel/utils/configDir.ts
|
|
@@ -442038,10 +442544,12 @@ function createCoreDependencies2(backendConfig) {
|
|
|
442038
442544
|
executor: new ShellExecutor,
|
|
442039
442545
|
ascendExecutor: new AscendExecutor2(ascendConfig),
|
|
442040
442546
|
ascendConfig,
|
|
442041
|
-
ascendFreshnessPort: new DefaultAscendFreshnessPort
|
|
442547
|
+
ascendFreshnessPort: new DefaultAscendFreshnessPort,
|
|
442548
|
+
execution: createExecutionComposition()
|
|
442042
442549
|
};
|
|
442043
442550
|
}
|
|
442044
442551
|
function getCoreDependencies2() {
|
|
442552
|
+
armKernelInjectionGuard();
|
|
442045
442553
|
return _coreDeps ??= createCoreDependencies2();
|
|
442046
442554
|
}
|
|
442047
442555
|
var _coreDeps;
|
|
@@ -442059,6 +442567,7 @@ var init_factory = __esm(() => {
|
|
|
442059
442567
|
init_AscendExecutor();
|
|
442060
442568
|
init_contextHostWiring();
|
|
442061
442569
|
init_AscendFreshnessPort();
|
|
442570
|
+
init_executionComposition();
|
|
442062
442571
|
init_settings_adapter();
|
|
442063
442572
|
init_settings3();
|
|
442064
442573
|
init_constants5();
|
|
@@ -502326,6 +502835,7 @@ init_modelprovider2();
|
|
|
502326
502835
|
init_shared();
|
|
502327
502836
|
init_memory();
|
|
502328
502837
|
init_injection();
|
|
502838
|
+
init_executionComposition();
|
|
502329
502839
|
init_bootstrapStatePort();
|
|
502330
502840
|
init_executor();
|
|
502331
502841
|
init_permissions3();
|
|
@@ -502700,11 +503210,13 @@ function createCoreDependencies() {
|
|
|
502700
503210
|
sandboxManager,
|
|
502701
503211
|
modelProvider: getModelProvider(),
|
|
502702
503212
|
memoryStore: new FileSystemMemoryStore,
|
|
502703
|
-
appState
|
|
503213
|
+
appState,
|
|
503214
|
+
execution: createExecutionComposition()
|
|
502704
503215
|
};
|
|
502705
503216
|
}
|
|
502706
503217
|
var _core;
|
|
502707
503218
|
function getCoreDependencies() {
|
|
503219
|
+
armKernelInjectionGuard();
|
|
502708
503220
|
return _core ??= createCoreDependencies();
|
|
502709
503221
|
}
|
|
502710
503222
|
|
|
@@ -17,3 +17,5 @@ export type { FollowHandle } from './follow.js';
|
|
|
17
17
|
export type { SessionStoreAdapter, SessionStoreScopes, SessionFileEntry, TranscriptStat, TranscriptTail, } from './sessionStoreAdapter.js';
|
|
18
18
|
export type { NeutralProjection, NeutralProjectionMessage, NeutralBlock, ProjectionSourceMessage, ProjectionEngineDeps, ProjectionLoad, } from './projection.js';
|
|
19
19
|
export { WebSessionError, type WebSessionErrorCode } from './errors.js';
|
|
20
|
+
export { createExecutionOutlet, type ExecutionOutlet, type ExecutionOutletOptions, type ExecutionDispatchResult, type WebExecutionProbeResult, } from '../../kernel/execution/executionOutlet.js';
|
|
21
|
+
export { EXECUTION_SCHEMA_VERSION, EXECUTION_PROTOCOL_VERSION, EXECUTION_CAPABILITY_DISABLED_CODE, WebExecutionCommandSchema, WebExecutionEventSchema, WebExecutionErrorSchema, ExecutionBindSchema, type ExecutionBind, type ExecutionReplay, type WebExecutionCommand, type WebExecutionEvent, type WebExecutionError, } from '../../kernel/protocol/webExecutionV0.js';
|