shennian 0.3.79 → 0.3.80
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{roomRuntimeAdapterForAgent as y}from"@shennian/wire";import h from"node:crypto";class u{deps;constructor(e){this.deps=e}async bind(e){const{machineId:i,machineToken:s}=this.deps.getMachineCredentials();if(!i||!s)throw new Error("Machine is not paired with Shennian.");const r=I(e.agentType),o=this.deps.hostProcessIdentity(),t=this.deps.registry.register({machineId:i,runtimeAdapter:r,sourceSessionKey:e.sourceSessionKey,nianSessionId:e.nianSessionId,hostProcessIdentity:o,capabilities:{canIdentifySession:!0,canBindAutomatically:!0,canOpenEmbeddedRoomPage:!1,canResumeIdleSession:!0,canActivateWhileHostOpen:!0}}),n=await this.deps.bindingClient.create({machineToken:s,bindingIntentId:e.assignmentIntentId,roomId:e.roomId,agentIdentityId:e.agentIdentityId,nianSessionId:e.nianSessionId,runtimeAdapter:r,sessionRegistryKey:t.registryKey,activationCapability:"managed",activationMode:"auto_follow"}),a=await this.resolveServerOwnedWorkspace({machineToken:s,roomId:n.binding.roomId,bindingId:n.binding.id,agentIdentityId:e.agentIdentityId});return this.deps.observations.observe({machineId:i,runtimeAdapter:r,sourceSessionKey:e.sourceSessionKey,hostContextHash:g(o),workspaceHash:g(a),workspacePath:a,lifecycleState:"active",eventName:"ManagedBind"}),
|
|
1
|
+
import{roomRuntimeAdapterForAgent as y}from"@shennian/wire";import h from"node:crypto";class u{deps;constructor(e){this.deps=e}async bind(e){const{machineId:i,machineToken:s}=this.deps.getMachineCredentials();if(!i||!s)throw new Error("Machine is not paired with Shennian.");const r=I(e.agentType),o=this.deps.hostProcessIdentity(),t=this.deps.registry.register({machineId:i,runtimeAdapter:r,sourceSessionKey:e.sourceSessionKey,nianSessionId:e.nianSessionId,hostProcessIdentity:o,capabilities:{canIdentifySession:!0,canBindAutomatically:!0,canOpenEmbeddedRoomPage:!1,canResumeIdleSession:!0,canActivateWhileHostOpen:!0}}),n=await this.deps.bindingClient.create({machineToken:s,bindingIntentId:e.assignmentIntentId,roomId:e.roomId,agentIdentityId:e.agentIdentityId,nianSessionId:e.nianSessionId,runtimeAdapter:r,sessionRegistryKey:t.registryKey,activationCapability:"managed",activationMode:"auto_follow"});this.deps.registry.setBinding({registryKey:t.registryKey,bindingId:n.binding.id,roomId:n.binding.roomId,agentIdentityId:n.binding.agentIdentityId,agentMembershipId:n.binding.agentMembershipId,status:n.binding.status,activationMode:n.binding.activationMode});const a=await this.resolveServerOwnedWorkspace({machineToken:s,roomId:n.binding.roomId,bindingId:n.binding.id,agentIdentityId:e.agentIdentityId});return this.deps.observations.observe({machineId:i,runtimeAdapter:r,sourceSessionKey:e.sourceSessionKey,hostContextHash:g(o),workspaceHash:g(a),workspacePath:a,lifecycleState:"active",eventName:"ManagedBind"}),n}async restart(e){const{machineId:i,machineToken:s}=this.deps.getMachineCredentials();if(!i||!s)throw new Error("Machine is not paired with Shennian.");const r=I(e.agentType),o=this.deps.hostProcessIdentity(),t=this.deps.registry.register({machineId:i,runtimeAdapter:r,sourceSessionKey:e.sourceSessionKey,nianSessionId:e.nianSessionId,hostProcessIdentity:o,capabilities:{canIdentifySession:!0,canBindAutomatically:!0,canOpenEmbeddedRoomPage:!1,canResumeIdleSession:!0,canActivateWhileHostOpen:!0}}),n=await this.deps.bindingClient.restart({machineToken:s,bindingId:e.bindingId,previousNianSessionId:e.previousNianSessionId,roomId:e.roomId,agentIdentityId:e.agentIdentityId,nianSessionId:e.nianSessionId,runtimeAdapter:r,sessionRegistryKey:t.registryKey});this.deps.registry.setBinding({registryKey:t.registryKey,bindingId:n.binding.id,roomId:n.binding.roomId,agentIdentityId:n.binding.agentIdentityId,agentMembershipId:n.binding.agentMembershipId,status:n.binding.status,activationMode:n.binding.activationMode}),this.deps.registry.advanceCursor({registryKey:t.registryKey,cursor:"delivered",sequence:n.resumeSequence}),this.deps.registry.advanceCursor({registryKey:t.registryKey,cursor:"activated",sequence:n.resumeSequence});for(const c of this.deps.registry.list())c.registryKey!==t.registryKey&&c.nianSessionId===e.previousNianSessionId&&c.binding?.bindingId===e.bindingId&&this.deps.registry.detachBinding(c.registryKey);const a=await this.resolveServerOwnedWorkspace({machineToken:s,roomId:n.binding.roomId,bindingId:n.binding.id,agentIdentityId:e.agentIdentityId});return this.deps.observations.observe({machineId:i,runtimeAdapter:r,sourceSessionKey:e.sourceSessionKey,hostContextHash:g(o),workspaceHash:g(a),workspacePath:a,lifecycleState:"active",eventName:"ManagedRestart"}),n}async resolveServerOwnedWorkspace(e){const i=await this.deps.bindingClient.status(e),s=i.managedWorkspacePath?.trim();if(i.agentIdentityId!==e.agentIdentityId||i.agent?.sessionMode!=="standard"||!s)throw new Error("managed_room_workspace_unavailable");return s}}function g(d){return h.createHash("sha256").update(d,"utf8").digest("hex")}function I(d){const e=y(d);if(e)return e;throw new Error(`Agent ${d} does not support managed Room binding.`)}export{u as TrustedManagedRoomBinder};
|
|
@@ -4,6 +4,7 @@ const GIT_DIRECTIVE_LINE_RE = /^\s*::git-[a-z-]+\{[^\n]*\}\s*$/gm;
|
|
|
4
4
|
const TOOL_PAYLOAD_PREFIX_RE = /^\s*\{\s*"v"\s*:\s*1\s*,\s*"type"\s*:\s*"(tool|tool_use|tool_result)"/;
|
|
5
5
|
const ENVIRONMENT_CONTEXT_RE = /^\s*<environment_context>\s*[^]*?<\/environment_context>\s*$/i;
|
|
6
6
|
const ENVIRONMENT_CONTEXT_REQUIRED_TAG_RE = /<(cwd|shell|current_date|timezone)>[^<]*<\/\1>/gi;
|
|
7
|
+
const CODEX_RECOMMENDED_PLUGINS_PREFIX_RE = /^\s*<recommended_plugins>[^]*?<\/recommended_plugins>\s*/i;
|
|
7
8
|
const CODEX_TURN_ABORTED_RE = /^\s*<turn_aborted>[^]*?<\/turn_aborted>\s*$/i;
|
|
8
9
|
const CODEX_INTERNAL_CONTEXT_RE = /^\s*<codex_internal_context\b[^>]*>[^]*?<\/codex_internal_context>\s*$/i;
|
|
9
10
|
const CODEX_PROJECT_INSTRUCTIONS_RE = /^\s*# AGENTS\.md instructions for [^\n]+\n+\s*<INSTRUCTIONS>\s*[^]*?<\/INSTRUCTIONS>\s*(?:<environment_context>[^]*?<\/environment_context>)?\s*$/i;
|
|
@@ -202,6 +203,15 @@ export function isCodexProjectInstructionsPayload(payload) {
|
|
|
202
203
|
return CODEX_PROJECT_INSTRUCTIONS_RE.test(payload);
|
|
203
204
|
}
|
|
204
205
|
export function isSystemControlPayload(payload) {
|
|
206
|
+
// Codex can inject the catalog alone or before environment/project metadata.
|
|
207
|
+
// Consume only a complete prefix and require the entire remainder to be control
|
|
208
|
+
// context, so discussions, code samples and appended user requests stay visible.
|
|
209
|
+
const plugins = payload.match(CODEX_RECOMMENDED_PLUGINS_PREFIX_RE);
|
|
210
|
+
if (plugins) {
|
|
211
|
+
const remainder = payload.slice(plugins[0].length).trim();
|
|
212
|
+
return !remainder || isSystemEnvironmentContextPayload(remainder) ||
|
|
213
|
+
isCodexProjectInstructionsPayload(remainder);
|
|
214
|
+
}
|
|
205
215
|
return (isSystemEnvironmentContextPayload(payload) ||
|
|
206
216
|
isCodexTurnAbortedPayload(payload) ||
|
|
207
217
|
CODEX_INTERNAL_CONTEXT_RE.test(payload) ||
|