@phyzess/pappra 0.1.0-beta.13 → 0.1.0-beta.18
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/README.md +134 -15
- package/assets/integrations/skills/pappra/SKILL.md +28 -7
- package/assets/integrations/skills/pappra/references/collaboration.md +633 -0
- package/assets/integrations/skills/pappra/references/environment.md +360 -0
- package/assets/integrations/skills/pappra/references/hosts.md +20 -0
- package/assets/integrations/skills/pappra/references/operations.md +36 -5
- package/dist/adapters/pi/recovery-extension.d.ts +65 -0
- package/dist/adapters/pi/recovery-extension.js +238 -0
- package/dist/adapters/pi/session-transition-extension.d.ts +30 -0
- package/dist/adapters/pi/session-transition-extension.js +265 -0
- package/dist/app/automatic-handoff-events.d.ts +26 -0
- package/dist/app/automatic-handoff-events.js +134 -0
- package/dist/app/bounded-file.d.ts +2 -0
- package/dist/app/bounded-file.js +2 -0
- package/dist/app/capability-evidence/claude.d.ts +37 -0
- package/dist/app/capability-evidence/claude.js +206 -0
- package/dist/app/capability-evidence/codex.d.ts +35 -0
- package/dist/app/capability-evidence/codex.js +193 -0
- package/dist/app/capability-evidence/index.d.ts +33 -0
- package/dist/app/capability-evidence/index.js +117 -0
- package/dist/app/capability-evidence/pi.d.ts +73 -0
- package/dist/app/capability-evidence/pi.js +669 -0
- package/dist/app/capability-evidence/shared.d.ts +69 -0
- package/dist/app/capability-evidence/shared.js +195 -0
- package/dist/app/collab-auto-handoff.d.ts +55 -0
- package/dist/app/collab-auto-handoff.js +384 -0
- package/dist/app/collab-bindings.d.ts +57 -0
- package/dist/app/collab-bindings.js +1006 -0
- package/dist/app/collab-bootstrap-transport.d.ts +163 -0
- package/dist/app/collab-bootstrap-transport.js +769 -0
- package/dist/app/collab-bootstrap.d.ts +137 -0
- package/dist/app/collab-bootstrap.js +3455 -0
- package/dist/app/collab-handoff.d.ts +12 -0
- package/dist/app/collab-handoff.js +511 -0
- package/dist/app/collab-messages.d.ts +2 -0
- package/dist/app/collab-messages.js +2 -0
- package/dist/app/collab-notify.d.ts +156 -0
- package/dist/app/collab-notify.js +1208 -0
- package/dist/app/collab-preflight.d.ts +34 -0
- package/dist/app/collab-preflight.js +96 -0
- package/dist/app/collab-recovery-executor.d.ts +161 -0
- package/dist/app/collab-recovery-executor.js +1153 -0
- package/dist/app/collab-recovery-projection.d.ts +103 -0
- package/dist/app/collab-recovery-projection.js +659 -0
- package/dist/app/collab-recovery.d.ts +25 -0
- package/dist/app/collab-recovery.js +429 -0
- package/dist/app/collab-resources.d.ts +16 -0
- package/dist/app/collab-resources.js +278 -0
- package/dist/app/collab-role-events.d.ts +22 -0
- package/dist/app/collab-role-events.js +329 -0
- package/dist/app/collab-role-orchestration.d.ts +53 -0
- package/dist/app/collab-role-orchestration.js +601 -0
- package/dist/app/collab-role-plan.d.ts +81 -0
- package/dist/app/collab-role-plan.js +504 -0
- package/dist/app/collab-role-repair.d.ts +109 -0
- package/dist/app/collab-role-repair.js +821 -0
- package/dist/app/collab-rollover.d.ts +263 -0
- package/dist/app/collab-rollover.js +1112 -0
- package/dist/app/collab-route.d.ts +64 -0
- package/dist/app/collab-route.js +240 -0
- package/dist/app/collab-session-transition.d.ts +221 -0
- package/dist/app/collab-session-transition.js +3334 -0
- package/dist/app/collab-state.d.ts +7 -0
- package/dist/app/collab-state.js +162 -0
- package/dist/app/collab-task-store.d.ts +22 -0
- package/dist/app/collab-task-store.js +204 -0
- package/dist/app/collab-work-execution.d.ts +127 -0
- package/dist/app/collab-work-execution.js +1027 -0
- package/dist/app/collab-work-plan.d.ts +87 -0
- package/dist/app/collab-work-plan.js +437 -0
- package/dist/app/collaboration.d.ts +8 -2
- package/dist/app/collaboration.js +101 -12
- package/dist/app/doctor.js +108 -5
- package/dist/app/host-mcp.js +34 -8
- package/dist/app/host-probe.js +4 -4
- package/dist/app/init.d.ts +58 -4
- package/dist/app/init.js +768 -155
- package/dist/app/managed-pi-bootstrap-admission.d.ts +14 -0
- package/dist/app/managed-pi-bootstrap-admission.js +104 -0
- package/dist/app/managed-pi-bootstrap-refresh.d.ts +10 -0
- package/dist/app/managed-pi-bootstrap-refresh.js +78 -0
- package/dist/app/managed-pi-delivery.d.ts +8 -0
- package/dist/app/managed-pi-delivery.js +110 -0
- package/dist/app/managed-pi-handoff-receiver.d.ts +15 -0
- package/dist/app/managed-pi-handoff-receiver.js +263 -0
- package/dist/app/managed-pi-handoff-reference.d.ts +3 -0
- package/dist/app/managed-pi-handoff-reference.js +60 -0
- package/dist/app/managed-pi-herdr.d.ts +21 -0
- package/dist/app/managed-pi-herdr.js +185 -0
- package/dist/app/managed-pi-initial-admission.d.ts +28 -0
- package/dist/app/managed-pi-initial-admission.js +416 -0
- package/dist/app/managed-pi-initial-launch.d.ts +5 -0
- package/dist/app/managed-pi-initial-launch.js +61 -0
- package/dist/app/managed-pi-native-observation.d.ts +36 -0
- package/dist/app/managed-pi-native-observation.js +191 -0
- package/dist/app/managed-pi-readiness.d.ts +29 -0
- package/dist/app/managed-pi-readiness.js +288 -0
- package/dist/app/managed-pi-repair-stop.d.ts +21 -0
- package/dist/app/managed-pi-repair-stop.js +371 -0
- package/dist/app/managed-pi-resume-admission.d.ts +32 -0
- package/dist/app/managed-pi-resume-admission.js +618 -0
- package/dist/app/managed-pi-retirement.d.ts +28 -0
- package/dist/app/managed-pi-retirement.js +112 -0
- package/dist/app/managed-pi-sdk-control.d.ts +7 -0
- package/dist/app/managed-pi-sdk-control.js +169 -0
- package/dist/app/managed-pi-sdk-runtime.d.ts +3 -0
- package/dist/app/managed-pi-sdk-runtime.js +483 -0
- package/dist/app/managed-pi-source-admission.d.ts +14 -0
- package/dist/app/managed-pi-source-admission.js +323 -0
- package/dist/app/managed-pi-transition-host.d.ts +36 -0
- package/dist/app/managed-pi-transition-host.js +292 -0
- package/dist/app/managed-pi.d.ts +54 -0
- package/dist/app/managed-pi.js +248 -0
- package/dist/app/shell-readiness.d.ts +66 -0
- package/dist/app/shell-readiness.js +368 -0
- package/dist/app/task-pin.d.ts +2 -23
- package/dist/app/task-pin.js +2 -113
- package/dist/cli/commands/collaboration-binding.d.ts +13 -0
- package/dist/cli/commands/collaboration-binding.js +118 -0
- package/dist/cli/commands/collaboration-bootstrap.d.ts +10 -0
- package/dist/cli/commands/collaboration-bootstrap.js +84 -0
- package/dist/cli/commands/collaboration-capabilities.d.ts +13 -0
- package/dist/cli/commands/collaboration-capabilities.js +127 -0
- package/dist/cli/commands/collaboration-handoff.d.ts +13 -0
- package/dist/cli/commands/collaboration-handoff.js +102 -0
- package/dist/cli/commands/collaboration-message.d.ts +17 -0
- package/dist/cli/commands/collaboration-message.js +177 -0
- package/dist/cli/commands/collaboration-plan.d.ts +8 -0
- package/dist/cli/commands/collaboration-plan.js +108 -0
- package/dist/cli/commands/collaboration-preflight.d.ts +10 -0
- package/dist/cli/commands/collaboration-preflight.js +167 -0
- package/dist/cli/commands/collaboration-recovery-run.d.ts +46 -0
- package/dist/cli/commands/collaboration-recovery-run.js +224 -0
- package/dist/cli/commands/collaboration-recovery.d.ts +11 -0
- package/dist/cli/commands/collaboration-recovery.js +104 -0
- package/dist/cli/commands/collaboration-resources.d.ts +11 -0
- package/dist/cli/commands/collaboration-resources.js +96 -0
- package/dist/cli/commands/collaboration-role-plan.d.ts +9 -0
- package/dist/cli/commands/collaboration-role-plan.js +69 -0
- package/dist/cli/commands/collaboration-role-run.d.ts +11 -0
- package/dist/cli/commands/collaboration-role-run.js +128 -0
- package/dist/cli/commands/collaboration-rollover.d.ts +10 -0
- package/dist/cli/commands/collaboration-rollover.js +103 -0
- package/dist/cli/commands/collaboration-state.d.ts +10 -0
- package/dist/cli/commands/collaboration-state.js +96 -0
- package/dist/cli/commands/collaboration-transition.d.ts +10 -0
- package/dist/cli/commands/collaboration-transition.js +75 -0
- package/dist/cli/commands/collaboration-work-run.d.ts +34 -0
- package/dist/cli/commands/collaboration-work-run.js +178 -0
- package/dist/cli/commands/collaboration.d.ts +4 -0
- package/dist/cli/commands/collaboration.js +39 -4
- package/dist/cli/commands/continuity.js +2 -6
- package/dist/cli/commands/docs.d.ts +2 -0
- package/dist/cli/commands/docs.js +89 -15
- package/dist/cli/commands/host.d.ts +7 -1
- package/dist/cli/commands/host.js +122 -7
- package/dist/cli/commands/init.d.ts +20 -3
- package/dist/cli/commands/init.js +897 -232
- package/dist/cli/commands/mcp.d.ts +1 -0
- package/dist/cli/commands/mcp.js +11 -5
- package/dist/cli/commands/repair.d.ts +12 -0
- package/dist/cli/commands/repair.js +41 -0
- package/dist/cli/commands/runtime.d.ts +1 -1
- package/dist/cli/commands/runtime.js +139 -38
- package/dist/cli/commands/session.d.ts +7 -0
- package/dist/cli/commands/session.js +82 -0
- package/dist/cli/commands/task.js +19 -5
- package/dist/cli/run.js +866 -24
- package/dist/code/identity.d.ts +7 -0
- package/dist/code/identity.js +7 -3
- package/dist/code/registration.js +7 -0
- package/dist/code/service.d.ts +9 -0
- package/dist/code/service.js +16 -3
- package/dist/code/text.js +19 -7
- package/dist/collab/admission.d.ts +91 -66
- package/dist/collab/admission.js +21 -6
- package/dist/collab/canonical.d.ts +1 -1
- package/dist/collab/canonical.js +44 -3
- package/dist/collab/envelope.d.ts +2 -2
- package/dist/collab/envelope.js +12 -12
- package/dist/collab/first-work.d.ts +3 -0
- package/dist/collab/first-work.js +15 -0
- package/dist/collab/handoff.d.ts +16 -0
- package/dist/collab/handoff.js +39 -5
- package/dist/collab/index.d.ts +97 -1
- package/dist/collab/index.js +9 -1
- package/dist/collab/messages.js +126 -3
- package/dist/collab/persisted-messages.d.ts +123 -0
- package/dist/collab/persisted-messages.js +496 -0
- package/dist/collab/preflight.d.ts +1 -1
- package/dist/collab/resources.d.ts +13 -3
- package/dist/collab/resources.js +37 -6
- package/dist/collab/rollover.d.ts +311 -0
- package/dist/collab/rollover.js +1024 -0
- package/dist/collab/store.d.ts +1 -0
- package/dist/collab/store.js +1 -4
- package/dist/collab/types.d.ts +2 -354
- package/dist/collab/validation.d.ts +2 -10
- package/dist/collab/validation.js +2 -303
- package/dist/collab/work-plan.d.ts +105 -0
- package/dist/collab/work-plan.js +843 -0
- package/dist/continuity/context.d.ts +11 -2
- package/dist/continuity/context.js +100 -13
- package/dist/continuity/handoff-bundle.d.ts +296 -0
- package/dist/continuity/handoff-bundle.js +477 -0
- package/dist/continuity/index.d.ts +2 -0
- package/dist/continuity/index.js +1 -0
- package/dist/continuity/paths.js +10 -2
- package/dist/continuity/service.js +91 -15
- package/dist/continuity/task-pin.d.ts +24 -0
- package/dist/continuity/task-pin.js +590 -0
- package/dist/doctor.d.ts +1 -0
- package/dist/doctor.js +6 -0
- package/dist/experimental/index.d.ts +13 -0
- package/dist/experimental/index.js +25 -0
- package/dist/experimental/pi.d.ts +4 -0
- package/dist/experimental/pi.js +12 -0
- package/dist/hosts/claude/native.js +1 -1
- package/dist/hosts/codex/native.js +1 -1
- package/dist/hosts/codex/protocol.js +1 -1
- package/dist/hosts/integration/bootstrap-config.d.ts +58 -0
- package/dist/hosts/integration/bootstrap-config.js +254 -0
- package/dist/hosts/integration/bundle-export.d.ts +44 -0
- package/dist/hosts/integration/bundle-export.js +366 -3
- package/dist/hosts/integration/bundle.js +3 -0
- package/dist/hosts/integration/hook.js +36 -9
- package/dist/hosts/integration/pappra-bootstrap-extension.mjs +80 -0
- package/dist/hosts/integration/pappra-extension-runtime.mjs +59 -24631
- package/dist/hosts/integration/pappra-hook.mjs +61 -24749
- package/dist/hosts/integration/pappra-recovery-extension.mjs +259 -0
- package/dist/hosts/integration/pappra-session-transition-extension.mjs +276 -0
- package/dist/hosts/integration/pi-bootstrap-extension.d.ts +36 -0
- package/dist/hosts/integration/pi-bootstrap-extension.js +101 -0
- package/dist/hosts/integration/pi-bootstrap-guard.d.ts +125 -0
- package/dist/hosts/integration/pi-bootstrap-guard.js +438 -0
- package/dist/hosts/integration/pi-bootstrap-runtime.d.ts +63 -0
- package/dist/hosts/integration/pi-bootstrap-runtime.js +223 -0
- package/dist/hosts/integration/pi-native-events.d.ts +112 -0
- package/dist/hosts/integration/pi-native-events.js +348 -0
- package/dist/hosts/integration/pi-rollover-extension.d.ts +166 -0
- package/dist/hosts/integration/pi-rollover-extension.js +431 -0
- package/dist/hosts/integration/recovery-config.d.ts +48 -0
- package/dist/hosts/integration/recovery-config.js +117 -0
- package/dist/hosts/integration/service.d.ts +6 -1
- package/dist/hosts/integration/service.js +485 -35
- package/dist/hosts/integration/support.d.ts +7 -0
- package/dist/hosts/integration/support.js +9 -1
- package/dist/hosts/integration/templates.d.ts +3 -0
- package/dist/hosts/integration/templates.js +26 -3
- package/dist/hosts/pi/managed-host-identity.d.ts +2 -0
- package/dist/hosts/pi/managed-host-identity.js +40 -0
- package/dist/hosts/pi/managed-provider-diagnostics.d.ts +6 -0
- package/dist/hosts/pi/managed-provider-diagnostics.js +184 -0
- package/dist/hosts/pi/managed-sdk-session.d.ts +335 -0
- package/dist/hosts/pi/managed-sdk-session.js +1639 -0
- package/dist/hosts/pi/managed-session-extension.d.ts +20 -0
- package/dist/hosts/pi/managed-session-extension.js +84 -0
- package/dist/hosts/pi/managed-session.d.ts +177 -0
- package/dist/hosts/pi/managed-session.js +1557 -0
- package/dist/hosts/pi/protocol.js +1 -1
- package/dist/hosts/pi/query-result.js +1 -1
- package/dist/hosts/pi/resume-capability.d.ts +41 -0
- package/dist/hosts/pi/resume-capability.js +33 -0
- package/dist/hosts/pi/rpc.d.ts +182 -134
- package/dist/hosts/pi/rpc.js +230 -37
- package/dist/hosts/pilot.d.ts +97 -74
- package/dist/hosts/pilot.js +5 -1
- package/dist/hosts/version.d.ts +3 -0
- package/dist/hosts/version.js +18 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/infra/bounded-file.d.ts +19 -0
- package/dist/infra/bounded-file.js +66 -0
- package/dist/infra/fs.js +10 -2
- package/dist/infra/git.d.ts +29 -0
- package/dist/infra/git.js +45 -9
- package/dist/infra/json-property.d.ts +2 -0
- package/dist/infra/json-property.js +69 -0
- package/dist/infra/json.d.ts +4 -0
- package/dist/infra/json.js +24 -0
- package/dist/infra/owned-process-group.js +1 -1
- package/dist/infra/private-lock.d.ts +16 -0
- package/dist/infra/private-lock.js +148 -0
- package/dist/infra/private-state.d.ts +7 -0
- package/dist/infra/private-state.js +146 -0
- package/dist/infra/process-identity.d.ts +12 -0
- package/dist/infra/process-identity.js +142 -0
- package/dist/infra/validation.d.ts +5 -0
- package/dist/infra/validation.js +15 -0
- package/dist/init.d.ts +1 -0
- package/dist/init.js +6 -0
- package/dist/install/apply.d.ts +9 -1
- package/dist/install/apply.js +176 -12
- package/dist/install/dependencies.d.ts +38 -0
- package/dist/install/dependencies.js +282 -0
- package/dist/install/ownership.js +30 -1
- package/dist/install/references.d.ts +31 -0
- package/dist/install/references.js +208 -0
- package/dist/install/repair.d.ts +37 -0
- package/dist/install/repair.js +798 -0
- package/dist/install/reset-local.d.ts +16 -0
- package/dist/install/reset-local.js +304 -0
- package/dist/install/rollback.d.ts +3 -0
- package/dist/install/rollback.js +9 -3
- package/dist/install/runtime.d.ts +10 -6
- package/dist/install/runtime.js +299 -59
- package/dist/install/source-fingerprint.d.ts +2 -0
- package/dist/install/source-fingerprint.js +103 -0
- package/dist/knowledge/catalog.d.ts +1 -0
- package/dist/knowledge/catalog.js +143 -10
- package/dist/knowledge/journal.js +17 -7
- package/dist/knowledge/paths.js +2 -1
- package/dist/knowledge/refs.js +4 -0
- package/dist/knowledge/register-batch.d.ts +4 -0
- package/dist/knowledge/register-batch.js +225 -0
- package/dist/knowledge/relocate.d.ts +5 -0
- package/dist/knowledge/relocate.js +92 -0
- package/dist/knowledge/scan.js +103 -47
- package/dist/knowledge/service.d.ts +3 -0
- package/dist/knowledge/service.js +33 -1
- package/dist/knowledge/write.d.ts +4 -1
- package/dist/knowledge/write.js +1 -1
- package/dist/mcp/server.d.ts +4 -2
- package/dist/mcp/server.js +87 -136
- package/dist/schemas/collaboration-state-validation.d.ts +6 -0
- package/dist/schemas/collaboration-state-validation.js +342 -0
- package/dist/schemas/collaboration-state.d.ts +436 -0
- package/dist/schemas/collaboration-state.js +1 -0
- package/dist/schemas/collaboration.d.ts +335 -0
- package/dist/schemas/collaboration.js +272 -0
- package/dist/schemas/continuity.d.ts +8 -0
- package/dist/schemas/continuity.js +13 -3
- package/dist/schemas/doctor.d.ts +1 -0
- package/dist/schemas/doctor.js +1 -0
- package/dist/schemas/document.d.ts +61 -0
- package/dist/schemas/document.js +9 -0
- package/dist/schemas/errors.d.ts +1 -0
- package/dist/schemas/errors.js +1 -0
- package/dist/schemas/host.d.ts +24 -0
- package/dist/schemas/host.js +19 -0
- package/dist/schemas/install.d.ts +8 -2
- package/dist/schemas/install.js +11 -1
- package/dist/schemas/managed-pi-execution.d.ts +16 -0
- package/dist/schemas/managed-pi-execution.js +2 -0
- package/dist/schemas/outcome.d.ts +9 -5
- package/dist/workspace/config-file.js +1 -3
- package/dist/workspace/documents.js +12 -2
- package/dist/workspace/repositories.d.ts +7 -0
- package/dist/workspace/repositories.js +14 -5
- package/package.json +35 -35
- package/skills/pappra/SKILL.md +28 -7
- package/skills/pappra/references/collaboration.md +633 -0
- package/skills/pappra/references/environment.md +360 -0
- package/skills/pappra/references/hosts.md +20 -0
- package/skills/pappra/references/operations.md +36 -5
- package/dist/app/collab-from.d.ts +0 -35
- package/dist/app/collab-from.js +0 -84
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { continuityTaskPaths, writeContinuityBytes, } from '../continuity/paths.js';
|
|
4
|
+
import { readBoundedFile } from './bounded-file.js';
|
|
5
|
+
import { applySessionTransition, planSessionTransition, } from './collab-session-transition.js';
|
|
6
|
+
const MAX_TRANSCRIPT_BYTES = 64 * 1024 * 1024;
|
|
7
|
+
function transcript(file, sessionId, cwd) {
|
|
8
|
+
const before = fs.lstatSync(file);
|
|
9
|
+
const read = readBoundedFile(file, MAX_TRANSCRIPT_BYTES);
|
|
10
|
+
const after = fs.lstatSync(file);
|
|
11
|
+
if (!read.ok ||
|
|
12
|
+
before.dev !== after.dev ||
|
|
13
|
+
before.ino !== after.ino ||
|
|
14
|
+
before.size !== after.size ||
|
|
15
|
+
before.mtimeMs !== after.mtimeMs)
|
|
16
|
+
throw new Error('retirement_transcript_unstable');
|
|
17
|
+
let header;
|
|
18
|
+
try {
|
|
19
|
+
header = JSON.parse(read.text.split('\n', 1)[0]);
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
throw new Error('retirement_transcript_invalid');
|
|
23
|
+
}
|
|
24
|
+
if (header.type !== 'session' ||
|
|
25
|
+
header.id !== sessionId ||
|
|
26
|
+
header.cwd !== cwd)
|
|
27
|
+
throw new Error('retirement_transcript_identity_mismatch');
|
|
28
|
+
return read;
|
|
29
|
+
}
|
|
30
|
+
/** Native disposal and retention follow authoritative transfer + successor first work. */
|
|
31
|
+
export async function retireManagedPiSource(request, runtime, dependencies = {}) {
|
|
32
|
+
const observed = runtime.observe();
|
|
33
|
+
if (observed.native.sessionId !== request.intent.from.session_id ||
|
|
34
|
+
path.resolve(observed.cwd) !== path.resolve(request.intent.from.cwd ?? ''))
|
|
35
|
+
throw new Error('retirement_source_identity_mismatch');
|
|
36
|
+
// Check read-only first: retirement must never advance bootstrap or transfer.
|
|
37
|
+
const planned = await planSessionTransition(request, dependencies);
|
|
38
|
+
if (!planned.ok || planned.stage !== 'task_retired')
|
|
39
|
+
throw new Error('retirement_first_work_gate_unsatisfied');
|
|
40
|
+
const verified = await applySessionTransition(request, dependencies);
|
|
41
|
+
if (!verified.ok || verified.stage !== 'task_retired')
|
|
42
|
+
throw new Error('retirement_first_work_gate_unsatisfied');
|
|
43
|
+
const { root, continuity_task_id: taskId } = request.bundle;
|
|
44
|
+
const directory = path.join(continuityTaskPaths(root, taskId).taskDir, 'retired-sessions');
|
|
45
|
+
const archiveFile = path.join(directory, `${request.transition_id}.jsonl`);
|
|
46
|
+
const receiptFile = path.join(directory, `${request.transition_id}.receipt.json`);
|
|
47
|
+
const nativeFile = runtime.snapshot().session.sessionFile;
|
|
48
|
+
if (!nativeFile)
|
|
49
|
+
throw new Error('retirement_transcript_unavailable');
|
|
50
|
+
const prior = fs.lstatSync(receiptFile, { throwIfNoEntry: false });
|
|
51
|
+
if (prior) {
|
|
52
|
+
const read = readBoundedFile(receiptFile, 16 * 1024);
|
|
53
|
+
if (!read.ok)
|
|
54
|
+
throw new Error('retirement_receipt_unreadable');
|
|
55
|
+
const value = JSON.parse(read.text);
|
|
56
|
+
const archive = readBoundedFile(archiveFile, MAX_TRANSCRIPT_BYTES);
|
|
57
|
+
if (!runtime.isDisposed ||
|
|
58
|
+
value.schema !== 'pappra/managed-pi-retirement/1' ||
|
|
59
|
+
value.transition_id !== request.transition_id ||
|
|
60
|
+
value.source_session_id !== observed.native.sessionId ||
|
|
61
|
+
value.successor_session_id !== request.intent.to.session_id ||
|
|
62
|
+
value.status !== 'runtime_disposed_and_transcript_retained' ||
|
|
63
|
+
value.transcript?.source !== nativeFile ||
|
|
64
|
+
value.stop?.status !== 'runtime_disposed' ||
|
|
65
|
+
value.stop.process_exit !== 'not_owned' ||
|
|
66
|
+
value.transcript?.ref !==
|
|
67
|
+
path.relative(root, archiveFile).split(path.sep).join('/') ||
|
|
68
|
+
!archive.ok ||
|
|
69
|
+
archive.digest !== value.transcript.digest)
|
|
70
|
+
throw new Error('retirement_receipt_conflict');
|
|
71
|
+
transcript(archiveFile, observed.native.sessionId, observed.cwd);
|
|
72
|
+
return { receipt: value, receiptFile, duplicate: true };
|
|
73
|
+
}
|
|
74
|
+
transcript(nativeFile, observed.native.sessionId, observed.cwd);
|
|
75
|
+
const stopped = await runtime.stopOwnedRuntime();
|
|
76
|
+
if (stopped.status !== 'runtime_disposed' ||
|
|
77
|
+
stopped.sessionId !== observed.native.sessionId ||
|
|
78
|
+
stopped.process.exit !== 'not_owned' ||
|
|
79
|
+
!stopped.finalSnapshot.scopedQuiescent)
|
|
80
|
+
throw new Error('retirement_runtime_stop_unknown');
|
|
81
|
+
const bytes = transcript(nativeFile, observed.native.sessionId, observed.cwd);
|
|
82
|
+
const existing = fs.lstatSync(archiveFile, { throwIfNoEntry: false });
|
|
83
|
+
if (existing) {
|
|
84
|
+
const saved = readBoundedFile(archiveFile, MAX_TRANSCRIPT_BYTES);
|
|
85
|
+
if (!saved.ok || saved.digest !== bytes.digest)
|
|
86
|
+
throw new Error('retirement_archive_conflict');
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
const saved = await writeContinuityBytes(root, taskId, archiveFile, bytes.bytes, true);
|
|
90
|
+
if (!saved.ok)
|
|
91
|
+
throw new Error(saved.code);
|
|
92
|
+
}
|
|
93
|
+
const receipt = {
|
|
94
|
+
schema: 'pappra/managed-pi-retirement/1',
|
|
95
|
+
transition_id: request.transition_id,
|
|
96
|
+
source_session_id: observed.native.sessionId,
|
|
97
|
+
successor_session_id: request.intent.to.session_id,
|
|
98
|
+
status: 'runtime_disposed_and_transcript_retained',
|
|
99
|
+
stop: { status: 'runtime_disposed', process_exit: 'not_owned' },
|
|
100
|
+
transcript: {
|
|
101
|
+
source: nativeFile,
|
|
102
|
+
ref: path.relative(root, archiveFile).split(path.sep).join('/'),
|
|
103
|
+
digest: bytes.digest,
|
|
104
|
+
original: 'retained-in-place',
|
|
105
|
+
},
|
|
106
|
+
native_history: 'unchanged',
|
|
107
|
+
};
|
|
108
|
+
const saved = await writeContinuityBytes(root, taskId, receiptFile, Buffer.from(`${JSON.stringify(receipt, null, 2)}\n`), true);
|
|
109
|
+
if (!saved.ok)
|
|
110
|
+
throw new Error(saved.code);
|
|
111
|
+
return { receipt, receiptFile, duplicate: false };
|
|
112
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ManagedPiSdkSessionController } from '../hosts/pi/managed-sdk-session.js';
|
|
2
|
+
/** Private local endpoint for a runtime created by this process. Never adopts a PID. */
|
|
3
|
+
export declare function serveManagedPiSdkControl(controller: ManagedPiSdkSessionController, journalPath: string, requestedSocket?: string, automationStatus?: () => unknown, deliver?: (request: Readonly<Record<string, unknown>>) => Promise<Readonly<Record<string, unknown>>>): Promise<{
|
|
4
|
+
runId: string;
|
|
5
|
+
stopped: Promise<void>;
|
|
6
|
+
close(): void;
|
|
7
|
+
}>;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { randomBytes, timingSafeEqual } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import net from 'node:net';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
/** Private local endpoint for a runtime created by this process. Never adopts a PID. */
|
|
7
|
+
export async function serveManagedPiSdkControl(controller, journalPath, requestedSocket, automationStatus = () => null, deliver) {
|
|
8
|
+
const directory = path.dirname(journalPath);
|
|
9
|
+
const stat = fs.lstatSync(directory);
|
|
10
|
+
if (!stat.isDirectory() ||
|
|
11
|
+
stat.isSymbolicLink() ||
|
|
12
|
+
(stat.mode & 0o077) !== 0 ||
|
|
13
|
+
fs.realpathSync(directory) !== directory ||
|
|
14
|
+
(typeof process.getuid === 'function' && stat.uid !== process.getuid()))
|
|
15
|
+
throw new Error('sdk_control_directory_not_private');
|
|
16
|
+
const descriptorPath = `${journalPath}.control.json`;
|
|
17
|
+
if (fs.lstatSync(descriptorPath, { throwIfNoEntry: false }))
|
|
18
|
+
throw new Error('sdk_control_path_unavailable');
|
|
19
|
+
// macOS's per-user temp root and task paths can exceed sockaddr_un limits.
|
|
20
|
+
const socketDirectory = requestedSocket
|
|
21
|
+
? null
|
|
22
|
+
: fs.mkdtempSync(path.join(process.platform === 'darwin' ? '/private/tmp' : os.tmpdir(), 'pi-ctl-'));
|
|
23
|
+
const socketPath = requestedSocket ?? path.join(socketDirectory, 'c.sock');
|
|
24
|
+
if (!path.isAbsolute(socketPath) ||
|
|
25
|
+
Buffer.byteLength(socketPath) > 100 ||
|
|
26
|
+
fs.existsSync(socketPath) ||
|
|
27
|
+
fs.existsSync(descriptorPath))
|
|
28
|
+
throw new Error('sdk_control_path_unavailable');
|
|
29
|
+
const token = randomBytes(32).toString('hex');
|
|
30
|
+
const runId = randomBytes(16).toString('hex');
|
|
31
|
+
const peers = new Set();
|
|
32
|
+
let busy = false;
|
|
33
|
+
let resolveStopped;
|
|
34
|
+
const stopped = new Promise((resolve) => {
|
|
35
|
+
resolveStopped = resolve;
|
|
36
|
+
});
|
|
37
|
+
const server = net.createServer((socket) => {
|
|
38
|
+
peers.add(socket);
|
|
39
|
+
socket.once('close', () => peers.delete(socket));
|
|
40
|
+
socket.setTimeout(75_000, () => socket.destroy());
|
|
41
|
+
const chunks = [];
|
|
42
|
+
let requestBytes = 0;
|
|
43
|
+
let handled = false;
|
|
44
|
+
const send = (result) => socket.end(`${JSON.stringify(result)}\n`);
|
|
45
|
+
socket.on('data', (chunk) => {
|
|
46
|
+
if (handled)
|
|
47
|
+
return;
|
|
48
|
+
requestBytes += chunk.length;
|
|
49
|
+
if (requestBytes > 8192) {
|
|
50
|
+
handled = true;
|
|
51
|
+
send({ ok: false, reason: 'request_too_large' });
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
chunks.push(chunk);
|
|
55
|
+
if (!chunk.includes(0x0a))
|
|
56
|
+
return;
|
|
57
|
+
const data = Buffer.concat(chunks).toString('utf8');
|
|
58
|
+
const newline = data.indexOf('\n');
|
|
59
|
+
handled = true;
|
|
60
|
+
void (async () => {
|
|
61
|
+
try {
|
|
62
|
+
const request = JSON.parse(data.slice(0, newline));
|
|
63
|
+
const provided = Buffer.from(typeof request?.token === 'string' ? request.token : '');
|
|
64
|
+
const expected = Buffer.from(token);
|
|
65
|
+
if (provided.length !== expected.length ||
|
|
66
|
+
!timingSafeEqual(provided, expected)) {
|
|
67
|
+
send({ ok: false, reason: 'unauthorized' });
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (request.command === 'snapshot') {
|
|
71
|
+
send({
|
|
72
|
+
ok: true,
|
|
73
|
+
snapshot: controller.snapshot(),
|
|
74
|
+
automation: automationStatus(),
|
|
75
|
+
});
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (request.command === 'deliver') {
|
|
79
|
+
if (!deliver)
|
|
80
|
+
send({ ok: false, reason: 'delivery_not_configured' });
|
|
81
|
+
else
|
|
82
|
+
send(await deliver(request));
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (busy) {
|
|
86
|
+
send({ ok: false, reason: 'operation_in_progress' });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!['fence', 'stop'].includes(request.command)) {
|
|
90
|
+
send({ ok: false, reason: 'unsupported_command' });
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
busy = true;
|
|
94
|
+
try {
|
|
95
|
+
if (request.command === 'fence')
|
|
96
|
+
send({
|
|
97
|
+
ok: true,
|
|
98
|
+
snapshot: await controller.quiesce('authenticated_control_request'),
|
|
99
|
+
});
|
|
100
|
+
else {
|
|
101
|
+
const exit = await controller.stopOwnedRuntime();
|
|
102
|
+
send({ ok: true, exit });
|
|
103
|
+
// Resolve after the response has entered the socket, before CLI cleanup.
|
|
104
|
+
socket.once('close', resolveStopped);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
busy = false;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch {
|
|
112
|
+
send({ ok: false, reason: 'control_operation_failed' });
|
|
113
|
+
}
|
|
114
|
+
})();
|
|
115
|
+
});
|
|
116
|
+
socket.on('error', () => { });
|
|
117
|
+
});
|
|
118
|
+
await new Promise((resolve, reject) => {
|
|
119
|
+
server.once('error', reject);
|
|
120
|
+
server.listen(socketPath, () => {
|
|
121
|
+
server.off('error', reject);
|
|
122
|
+
resolve();
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
fs.chmodSync(socketPath, 0o600);
|
|
126
|
+
const socketIdentity = fs.lstatSync(socketPath);
|
|
127
|
+
try {
|
|
128
|
+
const fd = fs.openSync(descriptorPath, 'wx', 0o600);
|
|
129
|
+
try {
|
|
130
|
+
fs.writeFileSync(fd, `${JSON.stringify({
|
|
131
|
+
schema: 'harness-collab/pi-managed-control/1',
|
|
132
|
+
socketPath,
|
|
133
|
+
token,
|
|
134
|
+
runId,
|
|
135
|
+
sessionId: controller.observe().native.sessionId,
|
|
136
|
+
})}\n`);
|
|
137
|
+
fs.fsyncSync(fd);
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
fs.closeSync(fd);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
server.close();
|
|
145
|
+
throw error;
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
runId,
|
|
149
|
+
stopped,
|
|
150
|
+
close() {
|
|
151
|
+
for (const peer of peers)
|
|
152
|
+
peer.destroy();
|
|
153
|
+
server.close();
|
|
154
|
+
const current = fs.lstatSync(socketPath, { throwIfNoEntry: false });
|
|
155
|
+
if (current?.isSocket() &&
|
|
156
|
+
current.dev === socketIdentity.dev &&
|
|
157
|
+
current.ino === socketIdentity.ino)
|
|
158
|
+
fs.unlinkSync(socketPath);
|
|
159
|
+
if (socketDirectory) {
|
|
160
|
+
try {
|
|
161
|
+
fs.rmdirSync(socketDirectory);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
/* preserve unexpected contents */
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
};
|
|
169
|
+
}
|