@ornexus/neocortex 4.60.72 → 4.60.73
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/release-source.json +1 -1
- package/dist/sbom.cdx.json +24 -24
- package/install.ps1 +1 -1
- package/install.sh +1 -1
- package/package.json +2 -2
- package/packages/client/dist/adapters/adapter-registry.js +108 -1
- package/packages/client/dist/adapters/antigravity-adapter.js +77 -2
- package/packages/client/dist/adapters/claude-code-adapter.js +79 -3
- package/packages/client/dist/adapters/codex-adapter.js +80 -2
- package/packages/client/dist/adapters/cursor-adapter.js +115 -4
- package/packages/client/dist/adapters/gemini-adapter.js +71 -2
- package/packages/client/dist/adapters/grok-adapter.js +42 -2
- package/packages/client/dist/adapters/index.js +22 -1
- package/packages/client/dist/adapters/platform-detector.js +212 -1
- package/packages/client/dist/adapters/target-adapter.js +12 -0
- package/packages/client/dist/adapters/vscode-adapter.js +72 -2
- package/packages/client/dist/agent/refresh-stubs.js +417 -2
- package/packages/client/dist/agent/update-agent-yaml.js +102 -1
- package/packages/client/dist/agent/update-description.js +251 -1
- package/packages/client/dist/cache/crypto-utils.js +78 -1
- package/packages/client/dist/cache/encrypted-cache.js +108 -1
- package/packages/client/dist/cache/in-memory-asset-cache.js +73 -1
- package/packages/client/dist/cache/index.js +13 -1
- package/packages/client/dist/cache/protected-pi-boundary.js +44 -1
- package/packages/client/dist/checkpoint/checkpoint-client-reader.js +127 -2
- package/packages/client/dist/checkpoint/index.js +11 -1
- package/packages/client/dist/checkpoint/shared-checkpoint-types.js +32 -1
- package/packages/client/dist/cli.js +358 -5
- package/packages/client/dist/commands/activate.js +394 -8
- package/packages/client/dist/commands/architecture-answers.js +274 -7
- package/packages/client/dist/commands/architecture-memory-terminal.js +253 -4
- package/packages/client/dist/commands/architecture-non-ui-continuation.js +100 -1
- package/packages/client/dist/commands/architecture-root-binding.js +51 -1
- package/packages/client/dist/commands/cache-status.js +112 -2
- package/packages/client/dist/commands/config.js +88 -1
- package/packages/client/dist/commands/doctor.js +635 -2
- package/packages/client/dist/commands/invoke.js +7200 -143
- package/packages/client/dist/commands/legacy-epic-terminal.js +71 -1
- package/packages/client/dist/commands/legacy-story-branch.js +96 -1
- package/packages/client/dist/commands/legacy-story-pr.js +276 -1
- package/packages/client/dist/commands/mutation-qa-checkpoint.js +285 -5
- package/packages/client/dist/commands/mutation-qa-gate.js +54 -1
- package/packages/client/dist/commands/mutation-qa-git.js +41 -1
- package/packages/client/dist/commands/mutation-qa-policy.js +102 -1
- package/packages/client/dist/commands/mutation-qa-run.js +219 -3
- package/packages/client/dist/commands/mutation-qa-verdict.js +149 -1
- package/packages/client/dist/commands/mutation-qa.js +220 -1
- package/packages/client/dist/commands/native-agent.js +136 -2
- package/packages/client/dist/commands/planning-diagnosis.js +43 -1
- package/packages/client/dist/commands/planning-generation.js +53 -1
- package/packages/client/dist/commands/planning-memory.js +40 -1
- package/packages/client/dist/commands/planning-research.js +42 -1
- package/packages/client/dist/commands/private-session.js +75 -1
- package/packages/client/dist/commands/property-qa.js +139 -1
- package/packages/client/dist/commands/qa-control.js +16 -1
- package/packages/client/dist/commands/qa-scan-browser-launch.js +55 -1
- package/packages/client/dist/commands/qa-scan-browser-route.js +28 -1
- package/packages/client/dist/commands/qa-scan-capture.js +663 -5
- package/packages/client/dist/commands/qa-scan-discovery.js +376 -3
- package/packages/client/dist/commands/qa-scan-review.js +826 -5
- package/packages/client/dist/commands/qa-synthetic-backend-capture.js +266 -1
- package/packages/client/dist/commands/qa-synthetic-backend-review.js +297 -1
- package/packages/client/dist/commands/qa-synthetic-backend.js +340 -2
- package/packages/client/dist/commands/qa-synthetic-broker-port.js +85 -1
- package/packages/client/dist/commands/qa-synthetic-browser.js +39 -1
- package/packages/client/dist/commands/refactor-characterization.js +671 -21
- package/packages/client/dist/commands/refactor-commit.js +399 -13
- package/packages/client/dist/commands/refactor-control.js +142 -3
- package/packages/client/dist/commands/refactor-cpp-assertions.js +93 -3
- package/packages/client/dist/commands/refactor-review.js +283 -5
- package/packages/client/dist/commands/refactor-root.js +588 -7
- package/packages/client/dist/commands/refresh-memory.js +156 -3
- package/packages/client/dist/commands/shared-architecture-non-ui.js +24 -1
- package/packages/client/dist/commands/story-checkpoint.js +171 -1
- package/packages/client/dist/config/profile-directory.js +13 -1
- package/packages/client/dist/config/resolver-selection.js +278 -1
- package/packages/client/dist/config/secure-config.js +281 -12
- package/packages/client/dist/config.js +223 -2
- package/packages/client/dist/constants.js +25 -1
- package/packages/client/dist/context/context-collector.js +222 -2
- package/packages/client/dist/context/context-sanitizer.js +145 -1
- package/packages/client/dist/continuity/autonomous-governance.js +285 -1
- package/packages/client/dist/continuity/continuity-client-state-store.js +1587 -1
- package/packages/client/dist/continuity/invoke-hooks.js +129 -1
- package/packages/client/dist/continuity/migrations/001-initial-schema.js +12 -2
- package/packages/client/dist/continuity/migrations/002-processing-output-summary-indexes.js +12 -2
- package/packages/client/dist/continuity/migrations/003-headless-execution-attempts.js +12 -2
- package/packages/client/dist/continuity/migrations/004-outbox-delivery-state.js +12 -2
- package/packages/client/dist/continuity/migrations/005-bounded-headless-queue.js +12 -2
- package/packages/client/dist/continuity/migrations/006-native-agent-dispatches.js +10 -2
- package/packages/client/dist/continuity/native-agent-store.js +69 -1
- package/packages/client/dist/continuity/native-agent-types.js +90 -1
- package/packages/client/dist/continuity/outbox.js +117 -1
- package/packages/client/dist/continuity/runner-bootstrap-policy.js +172 -1
- package/packages/client/dist/continuity/sqlite-store.d.ts +22 -1
- package/packages/client/dist/continuity/sqlite-store.js +2612 -81
- package/packages/client/dist/effects/invoke-effect-gateways.js +62 -1
- package/packages/client/dist/errors/error-messages.js +228 -2
- package/packages/client/dist/errors/frontmatter-diagnostics.js +125 -1
- package/packages/client/dist/evidence/collector.js +347 -1
- package/packages/client/dist/evidence/index.js +1 -1
- package/packages/client/dist/evidence/types.js +2 -0
- package/packages/client/dist/fs/atomic-state-replace.js +152 -1
- package/packages/client/dist/generated/command-registry.generated.js +4076 -1
- package/packages/client/dist/generated/public-projections.generated.js +149 -1
- package/packages/client/dist/git/direct-yolo-c01-retry.js +138 -4
- package/packages/client/dist/git/direct-yolo-checkpoint.js +1234 -4
- package/packages/client/dist/git/epic-operational-state.d.ts +198 -0
- package/packages/client/dist/git/epic-operational-state.js +672 -0
- package/packages/client/dist/git/git-lifecycle-step-ids.js +14 -1
- package/packages/client/dist/git/git-lifecycle-store.d.ts +9 -1
- package/packages/client/dist/git/git-lifecycle-store.js +1981 -9
- package/packages/client/dist/git/legacy-story-branch-checkpoint.js +259 -9
- package/packages/client/dist/git/legacy-story-branch-setup.js +348 -4
- package/packages/client/dist/git/legacy-story-pr.js +3538 -70
- package/packages/client/dist/git/secure-filesystem-boundary.js +182 -5
- package/packages/client/dist/graph-retrieval/pre-command-hook.js +284 -1
- package/packages/client/dist/graph-retrieval/shared-graph-retrieval-contract.js +237 -1
- package/packages/client/dist/i18n/first-run.js +60 -2
- package/packages/client/dist/index.js +47 -1
- package/packages/client/dist/invocation/invoke-input.js +24 -1
- package/packages/client/dist/license/index.js +5 -1
- package/packages/client/dist/license/license-client.js +304 -1
- package/packages/client/dist/machine/fingerprint.js +163 -2
- package/packages/client/dist/machine/index.js +5 -1
- package/packages/client/dist/memory/project-memory-path-scope.js +62 -1
- package/packages/client/dist/memory/project-memory-writer.js +1007 -40
- package/packages/client/dist/memory/shared-project-memory-types.js +253 -2
- package/packages/client/dist/migrations/epic-lifecycle-backfill.d.ts +97 -0
- package/packages/client/dist/migrations/epic-lifecycle-backfill.js +1060 -0
- package/packages/client/dist/migrations/project-identity-capability.js +50 -1
- package/packages/client/dist/migrations/project-identity.js +493 -7
- package/packages/client/dist/migrations/state-json.d.ts +22 -0
- package/packages/client/dist/migrations/state-json.js +393 -4
- package/packages/client/dist/policy/architecture-policy.js +184 -2
- package/packages/client/dist/policy/index.js +7 -1
- package/packages/client/dist/policy/shared-policy-types.js +38 -0
- package/packages/client/dist/policy/subagent-approval-policy.js +55 -1
- package/packages/client/dist/private-execution/clean-baseline.js +279 -2
- package/packages/client/dist/private-execution/codex-executor.js +574 -4
- package/packages/client/dist/private-execution/codex-host-runtime.js +137 -1
- package/packages/client/dist/private-execution/codex-lifecycle-guard.js +97 -1
- package/packages/client/dist/private-execution/codex-scoped-permissions.js +128 -1
- package/packages/client/dist/private-execution/delivery.js +410 -13
- package/packages/client/dist/private-execution/diagnosis-root-review.js +294 -2
- package/packages/client/dist/private-execution/frozen-handoff.js +19 -6
- package/packages/client/dist/private-execution/implementation-validation.js +106 -2
- package/packages/client/dist/private-execution/isolated-admission.js +1432 -23
- package/packages/client/dist/private-execution/isolated-session.js +725 -5
- package/packages/client/dist/private-execution/isolated-workspace.js +122 -1
- package/packages/client/dist/private-execution/pact-consumer-runtime.js +409 -3
- package/packages/client/dist/private-execution/pact-test-source.js +258 -1
- package/packages/client/dist/private-execution/pact-toolchain.js +290 -3
- package/packages/client/dist/private-execution/pact-write-set.js +172 -1
- package/packages/client/dist/private-execution/planning-diagnosis-checkpoint.js +406 -5
- package/packages/client/dist/private-execution/planning-generation-checkpoint.js +462 -5
- package/packages/client/dist/private-execution/planning-memory-checkpoint.js +139 -3
- package/packages/client/dist/private-execution/planning-research-checkpoint.js +325 -4
- package/packages/client/dist/private-execution/private-report-store.js +42 -1
- package/packages/client/dist/private-execution/property-test-candidate.js +103 -1
- package/packages/client/dist/private-execution/property-test-choices.js +147 -3
- package/packages/client/dist/private-execution/property-test-plan.js +271 -7
- package/packages/client/dist/private-execution/property-test-review.js +258 -4
- package/packages/client/dist/private-execution/property-test-runtime.js +372 -9
- package/packages/client/dist/private-execution/property-test-source.js +139 -1
- package/packages/client/dist/private-execution/root-checkpoint.js +80 -1
- package/packages/client/dist/private-execution/root-memory-git-evidence.js +135 -3
- package/packages/client/dist/private-execution/root-memory-recovery.js +93 -1
- package/packages/client/dist/private-execution/root-memory-request.js +29 -1
- package/packages/client/dist/private-execution/root-memory-scope.js +178 -1
- package/packages/client/dist/private-execution/root-memory-writer.js +102 -1
- package/packages/client/dist/private-execution/session-lease.js +63 -1
- package/packages/client/dist/private-execution/shared-private-admission-types.js +50 -1
- package/packages/client/dist/private-execution/shared-project-validation.js +66 -1
- package/packages/client/dist/private-execution/shared-root-memory-types.js +61 -1
- package/packages/client/dist/private-execution/ux-source-validation.js +372 -1
- package/packages/client/dist/private-execution/ux-write-set.js +191 -2
- package/packages/client/dist/registry/registry-reconciliation.js +234 -1
- package/packages/client/dist/resilience/circuit-breaker.js +170 -1
- package/packages/client/dist/resilience/degradation-manager.js +164 -1
- package/packages/client/dist/resilience/freshness-indicator.js +100 -1
- package/packages/client/dist/resilience/index.js +8 -1
- package/packages/client/dist/resilience/recovery-detector.js +74 -1
- package/packages/client/dist/resolvers/asset-resolver.js +13 -0
- package/packages/client/dist/resolvers/local-resolver.js +255 -8
- package/packages/client/dist/resolvers/remote-resolver.js +233 -1
- package/packages/client/dist/runner/binary.js +404 -1
- package/packages/client/dist/runner/cli.js +1571 -17
- package/packages/client/dist/runner/headless/adapters.js +49 -1
- package/packages/client/dist/runner/headless/claude-code-adapter.js +79 -1
- package/packages/client/dist/runner/headless/continuous-story-workspace.js +1628 -11
- package/packages/client/dist/runner/headless/epic-git-reconciliation-inventory.js +69 -1
- package/packages/client/dist/runner/headless/epic-merge-candidate-qa.js +110 -2
- package/packages/client/dist/runner/headless/epic-terminal-git-cli-adapter.js +1236 -8
- package/packages/client/dist/runner/headless/epic-terminal-git-runner.js +318 -2
- package/packages/client/dist/runner/headless/fake-adapter.js +62 -1
- package/packages/client/dist/runner/headless/managed-profile.js +132 -1
- package/packages/client/dist/runner/headless/opencode-adapter.js +145 -2
- package/packages/client/dist/runner/headless/prepared-story-bundle.js +43 -1
- package/packages/client/dist/runner/headless/resolver.js +231 -1
- package/packages/client/dist/runner/headless/run-yolo.js +885 -1
- package/packages/client/dist/runner/headless/run-yoloop.js +2574 -2
- package/packages/client/dist/runner/headless/types.js +574 -2
- package/packages/client/dist/runner/local-console.js +396 -13
- package/packages/client/dist/runner/portal-sync-worker.js +1487 -1
- package/packages/client/dist/runner/project-identity.js +106 -1
- package/packages/client/dist/runner/scheduler.js +995 -7
- package/packages/client/dist/runner-cli.js +18 -2
- package/packages/client/dist/state/invocation-shape.js +13 -1
- package/packages/client/dist/state/project-state-snapshot.d.ts +8 -0
- package/packages/client/dist/state/project-state-snapshot.js +1731 -1
- package/packages/client/dist/state/state-json-repair.js +785 -3
- package/packages/client/dist/state/structural-dag-projection.js +118 -1
- package/packages/client/dist/telemetry/index.js +5 -1
- package/packages/client/dist/telemetry/offline-queue.js +131 -1
- package/packages/client/dist/tier/index.js +5 -1
- package/packages/client/dist/tier/tier-aware-client.js +405 -1
- package/packages/client/dist/types/index.js +38 -1
- package/packages/client/dist/version.js +27 -1
- package/packages/client/dist/yolo/change-evidence-collector.js +126 -1
- package/packages/client/dist/yolo/invoke-envelope-capability.js +62 -1
- package/packages/client/dist/yolo/spec-envelope-collector.js +184 -5
- package/packages/client/dist/yoloop/discovery-hook.js +300 -2
- package/packages/client/dist/yoloop/index.js +8 -1
- package/packages/client/dist/yoloop/invoke-hooks.js +669 -12
- package/packages/client/dist/yoloop/shared-discover-epics.js +1007 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.d.ts +65 -1
- package/packages/client/dist/yoloop/shared-yoloop-types.js +33 -1
- package/packages/client/dist/yoloop/target-normalization.js +180 -1
- package/packages/client/dist/yoloop/yoloop-client-state-store.d.ts +8 -0
- package/packages/client/dist/yoloop/yoloop-client-state-store.js +1920 -1
- package/packages/shared/dist/yolo/spec-envelope.js +3 -6
- package/targets-stubs/antigravity/gemini.md +1 -1
- package/targets-stubs/antigravity/skill/SKILL.md +1 -1
- package/targets-stubs/claude-code/neocortex-root.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex-root.md +2 -2
- package/targets-stubs/claude-code/neocortex.agent.yaml +1 -1
- package/targets-stubs/claude-code/neocortex.md +2 -2
- package/targets-stubs/codex/AGENTS.md +1 -1
- package/targets-stubs/cursor/agent.md +2 -2
- package/targets-stubs/gemini-cli/agent.md +2 -2
- package/targets-stubs/opencode/neocortex-root.md +1 -1
- package/targets-stubs/vscode/neocortex.agent.md +2 -2
|
@@ -1,13 +1,396 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @license FSL-1.1
|
|
3
|
+
* Copyright (c) 2026 OrNexus AI
|
|
4
|
+
*
|
|
5
|
+
* P197.03 -- local Plane B jobs console attach surface.
|
|
6
|
+
*
|
|
7
|
+
* Raw stdout/stderr and stdin are intentionally scoped to an operator-local IPC
|
|
8
|
+
* hop between the runner-owned child process and the foreground CLI. Nothing in
|
|
9
|
+
* this file persists raw output, PIDs, TTY names, file descriptors or socket paths
|
|
10
|
+
* to continuity storage or server-bound metadata.
|
|
11
|
+
*/
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
13
|
+
import { existsSync, mkdirSync, rmSync } from 'node:fs';
|
|
14
|
+
import { createConnection, createServer } from 'node:net';
|
|
15
|
+
import { tmpdir } from 'node:os';
|
|
16
|
+
import { dirname, join, resolve } from 'node:path';
|
|
17
|
+
import { createInterface } from 'node:readline';
|
|
18
|
+
export const LOCAL_JOBS_CONSOLE_REASON_CODES = Object.freeze({
|
|
19
|
+
OK: 'continuity-ok',
|
|
20
|
+
ATTACHED: 'jobs-console-attached',
|
|
21
|
+
NOT_ATTACHED: 'jobs-console-not-attached',
|
|
22
|
+
INVALID_SELECTOR: 'jobs-console-invalid-selector',
|
|
23
|
+
IPC_UNAVAILABLE: 'jobs-console-ipc-unavailable',
|
|
24
|
+
STDIN_CONFIRMATION_REQUIRED: 'jobs-console-stdin-confirmation-required',
|
|
25
|
+
STDIN_DISCARDED: 'jobs-console-stdin-discarded',
|
|
26
|
+
LOCAL_CONTROL_APPLIED: 'jobs-console-local-control-applied',
|
|
27
|
+
LOCAL_CONTROL_FAILED: 'jobs-console-local-control-failed',
|
|
28
|
+
});
|
|
29
|
+
const JOB_SELECTOR_PATTERN = /^@?(job-J\d{3,})$/i;
|
|
30
|
+
const SAFE_JOB_ID_PATTERN = /^job-J\d{3,}$/i;
|
|
31
|
+
const DEFAULT_CONSOLE_CONNECT_TIMEOUT_MS = 250;
|
|
32
|
+
export function isLocalJobsConsoleArgs(args) {
|
|
33
|
+
return parseLocalJobsConsoleArgs(args).kind !== 'not-console';
|
|
34
|
+
}
|
|
35
|
+
export function parseLocalJobsConsoleArgs(args) {
|
|
36
|
+
const tokens = args.trim().split(/\s+/).filter(Boolean);
|
|
37
|
+
if (tokens.length < 2)
|
|
38
|
+
return { kind: 'not-console' };
|
|
39
|
+
const command = tokens[0]?.replace(/^\*/, '').toLowerCase();
|
|
40
|
+
const operation = tokens[1]?.toLowerCase();
|
|
41
|
+
if (command !== 'jobs' || operation !== 'console')
|
|
42
|
+
return { kind: 'not-console' };
|
|
43
|
+
if (tokens.length !== 3)
|
|
44
|
+
return { kind: 'invalid', reasonCode: LOCAL_JOBS_CONSOLE_REASON_CODES.INVALID_SELECTOR };
|
|
45
|
+
const match = tokens[2]?.match(JOB_SELECTOR_PATTERN);
|
|
46
|
+
if (!match)
|
|
47
|
+
return { kind: 'invalid', reasonCode: LOCAL_JOBS_CONSOLE_REASON_CODES.INVALID_SELECTOR };
|
|
48
|
+
return { kind: 'valid', jobId: canonicalJobId(match[1]) };
|
|
49
|
+
}
|
|
50
|
+
export function localJobConsoleSocketPath(projectRoot, jobId) {
|
|
51
|
+
const root = resolve(projectRoot && projectRoot.trim().length > 0 ? projectRoot : process.cwd());
|
|
52
|
+
const rootHash = createHash('sha256').update(root).digest('hex').slice(0, 24);
|
|
53
|
+
const safeJobId = sanitizeSocketToken(canonicalJobId(jobId));
|
|
54
|
+
if (process.platform === 'win32')
|
|
55
|
+
return `\\\\.\\pipe\\neocortex-job-console-${rootHash}-${safeJobId}`;
|
|
56
|
+
return join(tmpdir(), 'neocortex-job-console', rootHash, `${safeJobId}.sock`);
|
|
57
|
+
}
|
|
58
|
+
export function createLocalJobConsoleServer(options) {
|
|
59
|
+
const jobId = canonicalJobId(options.jobId);
|
|
60
|
+
const socketPath = options.socketPath ?? localJobConsoleSocketPath(options.projectRoot, jobId);
|
|
61
|
+
const sockets = new Set();
|
|
62
|
+
let server;
|
|
63
|
+
let started = false;
|
|
64
|
+
const writeFrame = (socket, frame) => {
|
|
65
|
+
if (socket.destroyed)
|
|
66
|
+
return;
|
|
67
|
+
socket.write(`${JSON.stringify(frame)}\n`);
|
|
68
|
+
};
|
|
69
|
+
const broadcast = (frame) => {
|
|
70
|
+
for (const socket of sockets)
|
|
71
|
+
writeFrame(socket, frame);
|
|
72
|
+
};
|
|
73
|
+
const handleClientFrame = (socket, frame) => {
|
|
74
|
+
if (frame.type === 'close') {
|
|
75
|
+
socket.end();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (frame.type === 'stdin') {
|
|
79
|
+
const chunk = decodeBase64Frame(frame.data);
|
|
80
|
+
if (!chunk) {
|
|
81
|
+
writeFrame(socket, { type: 'stdin_ack', ok: false, reasonCode: LOCAL_JOBS_CONSOLE_REASON_CODES.IPC_UNAVAILABLE, publicSafe: true });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
options.writeStdin?.(chunk);
|
|
86
|
+
writeFrame(socket, { type: 'stdin_ack', ok: true, reasonCode: LOCAL_JOBS_CONSOLE_REASON_CODES.OK, publicSafe: true });
|
|
87
|
+
}
|
|
88
|
+
catch {
|
|
89
|
+
writeFrame(socket, { type: 'stdin_ack', ok: false, reasonCode: LOCAL_JOBS_CONSOLE_REASON_CODES.IPC_UNAVAILABLE, publicSafe: true });
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (frame.type === 'control') {
|
|
94
|
+
const signal = signalForControl(frame.action);
|
|
95
|
+
let ok = false;
|
|
96
|
+
try {
|
|
97
|
+
ok = Boolean(signal && options.signalProcess?.(signal));
|
|
98
|
+
}
|
|
99
|
+
catch {
|
|
100
|
+
ok = false;
|
|
101
|
+
}
|
|
102
|
+
writeFrame(socket, {
|
|
103
|
+
type: 'control_ack',
|
|
104
|
+
action: frame.action,
|
|
105
|
+
ok,
|
|
106
|
+
reasonCode: ok
|
|
107
|
+
? LOCAL_JOBS_CONSOLE_REASON_CODES.LOCAL_CONTROL_APPLIED
|
|
108
|
+
: LOCAL_JOBS_CONSOLE_REASON_CODES.LOCAL_CONTROL_FAILED,
|
|
109
|
+
publicSafe: true,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
jobId,
|
|
115
|
+
socketPath,
|
|
116
|
+
async start() {
|
|
117
|
+
if (started)
|
|
118
|
+
return { ok: true, reasonCode: LOCAL_JOBS_CONSOLE_REASON_CODES.OK, publicSafe: true };
|
|
119
|
+
if (!SAFE_JOB_ID_PATTERN.test(jobId)) {
|
|
120
|
+
return { ok: false, reasonCode: LOCAL_JOBS_CONSOLE_REASON_CODES.INVALID_SELECTOR, publicSafe: true };
|
|
121
|
+
}
|
|
122
|
+
try {
|
|
123
|
+
if (process.platform !== 'win32') {
|
|
124
|
+
mkdirSync(dirname(socketPath), { recursive: true, mode: 0o700 });
|
|
125
|
+
if (existsSync(socketPath))
|
|
126
|
+
rmSync(socketPath, { force: true });
|
|
127
|
+
}
|
|
128
|
+
server = createServer((socket) => {
|
|
129
|
+
sockets.add(socket);
|
|
130
|
+
socket.setEncoding('utf8');
|
|
131
|
+
writeFrame(socket, {
|
|
132
|
+
type: 'attached',
|
|
133
|
+
jobId,
|
|
134
|
+
...(options.attemptId ? { attemptId: options.attemptId } : {}),
|
|
135
|
+
...(options.executionId ? { executionId: options.executionId } : {}),
|
|
136
|
+
serverHeldStream: false,
|
|
137
|
+
publicSafe: true,
|
|
138
|
+
});
|
|
139
|
+
let buffer = '';
|
|
140
|
+
socket.on('data', (chunk) => {
|
|
141
|
+
buffer += chunk;
|
|
142
|
+
const lines = buffer.split('\n');
|
|
143
|
+
buffer = lines.pop() ?? '';
|
|
144
|
+
for (const line of lines) {
|
|
145
|
+
const parsed = parseClientFrame(line);
|
|
146
|
+
if (parsed)
|
|
147
|
+
handleClientFrame(socket, parsed);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
socket.on('close', () => sockets.delete(socket));
|
|
151
|
+
socket.on('error', () => sockets.delete(socket));
|
|
152
|
+
});
|
|
153
|
+
await new Promise((resolvePromise, rejectPromise) => {
|
|
154
|
+
server?.once('error', rejectPromise);
|
|
155
|
+
server?.listen(socketPath, () => resolvePromise());
|
|
156
|
+
});
|
|
157
|
+
started = true;
|
|
158
|
+
return { ok: true, reasonCode: LOCAL_JOBS_CONSOLE_REASON_CODES.OK, publicSafe: true };
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
return { ok: false, reasonCode: LOCAL_JOBS_CONSOLE_REASON_CODES.IPC_UNAVAILABLE, publicSafe: true };
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
broadcastStdout(chunk) {
|
|
165
|
+
broadcast(rawChunkFrame('stdout', chunk));
|
|
166
|
+
},
|
|
167
|
+
broadcastStderr(chunk) {
|
|
168
|
+
broadcast(rawChunkFrame('stderr', chunk));
|
|
169
|
+
},
|
|
170
|
+
close(exit = {}) {
|
|
171
|
+
broadcast({ type: 'exit', exitCode: exit.exitCode ?? null, signal: exit.signal ?? null, publicSafe: true });
|
|
172
|
+
for (const socket of sockets)
|
|
173
|
+
socket.end();
|
|
174
|
+
sockets.clear();
|
|
175
|
+
try {
|
|
176
|
+
server?.close();
|
|
177
|
+
}
|
|
178
|
+
catch {
|
|
179
|
+
// best effort cleanup only
|
|
180
|
+
}
|
|
181
|
+
if (process.platform !== 'win32') {
|
|
182
|
+
try {
|
|
183
|
+
rmSync(socketPath, { force: true });
|
|
184
|
+
}
|
|
185
|
+
catch { /* best effort */ }
|
|
186
|
+
}
|
|
187
|
+
started = false;
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
export async function runLocalJobsConsoleCommand(options) {
|
|
192
|
+
const stdout = options.stdout ?? process.stdout;
|
|
193
|
+
const stderr = options.stderr ?? process.stderr;
|
|
194
|
+
const input = options.stdin ?? process.stdin;
|
|
195
|
+
const parsed = parseLocalJobsConsoleArgs(options.args);
|
|
196
|
+
if (parsed.kind === 'not-console') {
|
|
197
|
+
return publicConsoleResult('invalid', 1, undefined, [LOCAL_JOBS_CONSOLE_REASON_CODES.INVALID_SELECTOR]);
|
|
198
|
+
}
|
|
199
|
+
if (parsed.kind === 'invalid') {
|
|
200
|
+
const result = publicConsoleResult('invalid', 1, undefined, [parsed.reasonCode]);
|
|
201
|
+
writeConsoleStatus(stdout, result, options.format);
|
|
202
|
+
return result;
|
|
203
|
+
}
|
|
204
|
+
const socketPath = localJobConsoleSocketPath(options.projectRoot, parsed.jobId);
|
|
205
|
+
const connectTimeoutMs = Math.max(10, Math.min(5_000, Math.floor(options.connectTimeoutMs ?? DEFAULT_CONSOLE_CONNECT_TIMEOUT_MS)));
|
|
206
|
+
return await new Promise((resolvePromise) => {
|
|
207
|
+
const socket = createConnection(socketPath);
|
|
208
|
+
let attached = false;
|
|
209
|
+
let settled = false;
|
|
210
|
+
let buffer = '';
|
|
211
|
+
let pendingStdin;
|
|
212
|
+
const reasonCodes = new Set();
|
|
213
|
+
let cleanupInput = () => { };
|
|
214
|
+
const timer = setTimeout(() => {
|
|
215
|
+
if (attached || settled)
|
|
216
|
+
return;
|
|
217
|
+
settled = true;
|
|
218
|
+
socket.destroy();
|
|
219
|
+
const result = publicConsoleResult('not-attached', 0, parsed.jobId, [LOCAL_JOBS_CONSOLE_REASON_CODES.NOT_ATTACHED]);
|
|
220
|
+
writeConsoleStatus(stdout, result, options.format);
|
|
221
|
+
resolvePromise(result);
|
|
222
|
+
}, connectTimeoutMs);
|
|
223
|
+
const finish = (status, exitCode = 0) => {
|
|
224
|
+
if (settled)
|
|
225
|
+
return;
|
|
226
|
+
settled = true;
|
|
227
|
+
clearTimeout(timer);
|
|
228
|
+
cleanupInput();
|
|
229
|
+
socket.end();
|
|
230
|
+
resolvePromise(publicConsoleResult(status, exitCode, parsed.jobId, Array.from(reasonCodes)));
|
|
231
|
+
};
|
|
232
|
+
const sendFrame = (frame) => {
|
|
233
|
+
if (!socket.destroyed)
|
|
234
|
+
socket.write(`${JSON.stringify(frame)}\n`);
|
|
235
|
+
};
|
|
236
|
+
const sendControl = (action) => {
|
|
237
|
+
sendFrame({ type: 'control', action });
|
|
238
|
+
};
|
|
239
|
+
const readline = createInterface({ input, terminal: false });
|
|
240
|
+
const onLine = (line) => {
|
|
241
|
+
if (!attached)
|
|
242
|
+
return;
|
|
243
|
+
const trimmed = line.trim();
|
|
244
|
+
if (pendingStdin !== undefined) {
|
|
245
|
+
if (trimmed === 'yes') {
|
|
246
|
+
sendFrame({ type: 'stdin', data: Buffer.from(`${pendingStdin}\n`, 'utf8').toString('base64'), encoding: 'base64' });
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
reasonCodes.add(LOCAL_JOBS_CONSOLE_REASON_CODES.STDIN_DISCARDED);
|
|
250
|
+
stdout.write('[jobs-console] stdin discarded; explicit confirmation was not provided.\n');
|
|
251
|
+
}
|
|
252
|
+
pendingStdin = undefined;
|
|
253
|
+
return;
|
|
254
|
+
}
|
|
255
|
+
if (trimmed === '/quit') {
|
|
256
|
+
sendFrame({ type: 'close' });
|
|
257
|
+
finish('attached', 0);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (trimmed === '/pause' || trimmed === '/resume' || trimmed === '/cancel') {
|
|
261
|
+
sendControl(trimmed.slice(1));
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
pendingStdin = line;
|
|
265
|
+
reasonCodes.add(LOCAL_JOBS_CONSOLE_REASON_CODES.STDIN_CONFIRMATION_REQUIRED);
|
|
266
|
+
stdout.write('[jobs-console] confirm stdin: type yes to send this line to the local process; anything else discards it.\n');
|
|
267
|
+
};
|
|
268
|
+
cleanupInput = () => {
|
|
269
|
+
readline.removeListener('line', onLine);
|
|
270
|
+
readline.close();
|
|
271
|
+
};
|
|
272
|
+
readline.on('line', onLine);
|
|
273
|
+
socket.on('connect', () => {
|
|
274
|
+
attached = true;
|
|
275
|
+
clearTimeout(timer);
|
|
276
|
+
reasonCodes.add(LOCAL_JOBS_CONSOLE_REASON_CODES.ATTACHED);
|
|
277
|
+
stdout.write(`[jobs-console] attached job=${parsed.jobId} serverHeldStream=false serverAccessToLocalhost=false controls=/pause,/resume,/cancel,/quit\n`);
|
|
278
|
+
});
|
|
279
|
+
socket.on('data', (chunk) => {
|
|
280
|
+
buffer += chunk.toString('utf8');
|
|
281
|
+
const lines = buffer.split('\n');
|
|
282
|
+
buffer = lines.pop() ?? '';
|
|
283
|
+
for (const line of lines) {
|
|
284
|
+
const frame = parseServerFrame(line);
|
|
285
|
+
if (!frame)
|
|
286
|
+
continue;
|
|
287
|
+
if (frame.type === 'stdout')
|
|
288
|
+
stdout.write(decodeBase64Frame(frame.data) ?? Buffer.alloc(0));
|
|
289
|
+
else if (frame.type === 'stderr')
|
|
290
|
+
stderr.write(decodeBase64Frame(frame.data) ?? Buffer.alloc(0));
|
|
291
|
+
else if (frame.type === 'control_ack') {
|
|
292
|
+
reasonCodes.add(frame.reasonCode);
|
|
293
|
+
stdout.write(`[jobs-console] control ${frame.action} ${frame.ok ? 'applied' : 'failed'} reason=${frame.reasonCode}\n`);
|
|
294
|
+
}
|
|
295
|
+
else if (frame.type === 'stdin_ack') {
|
|
296
|
+
reasonCodes.add(frame.reasonCode);
|
|
297
|
+
stdout.write(`[jobs-console] stdin ${frame.ok ? 'sent' : 'failed'} reason=${frame.reasonCode}\n`);
|
|
298
|
+
}
|
|
299
|
+
else if (frame.type === 'exit') {
|
|
300
|
+
finish('attached', 0);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
socket.on('error', () => {
|
|
305
|
+
if (attached || settled) {
|
|
306
|
+
reasonCodes.add(LOCAL_JOBS_CONSOLE_REASON_CODES.IPC_UNAVAILABLE);
|
|
307
|
+
finish('error', 1);
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
settled = true;
|
|
311
|
+
clearTimeout(timer);
|
|
312
|
+
cleanupInput();
|
|
313
|
+
const result = publicConsoleResult('not-attached', 0, parsed.jobId, [LOCAL_JOBS_CONSOLE_REASON_CODES.NOT_ATTACHED]);
|
|
314
|
+
writeConsoleStatus(stdout, result, options.format);
|
|
315
|
+
resolvePromise(result);
|
|
316
|
+
});
|
|
317
|
+
socket.on('close', () => {
|
|
318
|
+
if (!settled && attached)
|
|
319
|
+
finish('attached', 0);
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
function canonicalJobId(value) {
|
|
324
|
+
const raw = value.replace(/^@/, '');
|
|
325
|
+
const match = raw.match(/^job-J(\d{3,})$/i);
|
|
326
|
+
return match ? `job-J${match[1]}` : raw;
|
|
327
|
+
}
|
|
328
|
+
function sanitizeSocketToken(value) {
|
|
329
|
+
return value.replace(/[^A-Za-z0-9._-]+/g, '-').slice(0, 80) || 'job';
|
|
330
|
+
}
|
|
331
|
+
function rawChunkFrame(type, chunk) {
|
|
332
|
+
return { type, data: Buffer.from(chunk).toString('base64'), encoding: 'base64' };
|
|
333
|
+
}
|
|
334
|
+
function parseClientFrame(line) {
|
|
335
|
+
const frame = parseJsonRecord(line);
|
|
336
|
+
if (!frame)
|
|
337
|
+
return undefined;
|
|
338
|
+
if (frame.type === 'stdin' && typeof frame.data === 'string' && frame.encoding === 'base64')
|
|
339
|
+
return frame;
|
|
340
|
+
if (frame.type === 'control' && (frame.action === 'pause' || frame.action === 'resume' || frame.action === 'cancel'))
|
|
341
|
+
return frame;
|
|
342
|
+
if (frame.type === 'close')
|
|
343
|
+
return { type: 'close' };
|
|
344
|
+
return undefined;
|
|
345
|
+
}
|
|
346
|
+
function parseServerFrame(line) {
|
|
347
|
+
const frame = parseJsonRecord(line);
|
|
348
|
+
if (!frame || typeof frame.type !== 'string')
|
|
349
|
+
return undefined;
|
|
350
|
+
return frame;
|
|
351
|
+
}
|
|
352
|
+
function parseJsonRecord(line) {
|
|
353
|
+
if (!line.trim())
|
|
354
|
+
return undefined;
|
|
355
|
+
try {
|
|
356
|
+
const parsed = JSON.parse(line);
|
|
357
|
+
return typeof parsed === 'object' && parsed !== null && !Array.isArray(parsed) ? parsed : undefined;
|
|
358
|
+
}
|
|
359
|
+
catch {
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
function decodeBase64Frame(value) {
|
|
364
|
+
try {
|
|
365
|
+
return Buffer.from(value, 'base64');
|
|
366
|
+
}
|
|
367
|
+
catch {
|
|
368
|
+
return undefined;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
function signalForControl(action) {
|
|
372
|
+
if (action === 'pause')
|
|
373
|
+
return process.platform === 'win32' ? undefined : 'SIGSTOP';
|
|
374
|
+
if (action === 'resume')
|
|
375
|
+
return process.platform === 'win32' ? undefined : 'SIGCONT';
|
|
376
|
+
return 'SIGTERM';
|
|
377
|
+
}
|
|
378
|
+
function publicConsoleResult(status, exitCode, jobId, reasonCodes) {
|
|
379
|
+
return {
|
|
380
|
+
status,
|
|
381
|
+
exitCode,
|
|
382
|
+
...(jobId ? { jobId } : {}),
|
|
383
|
+
reasonCodes: reasonCodes.length > 0 ? Array.from(new Set(reasonCodes)) : [LOCAL_JOBS_CONSOLE_REASON_CODES.OK],
|
|
384
|
+
serverHeldStream: false,
|
|
385
|
+
serverAccessToLocalhost: false,
|
|
386
|
+
publicSafe: true,
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
function writeConsoleStatus(stdout, result, format = 'plain') {
|
|
390
|
+
if (format === 'json') {
|
|
391
|
+
stdout.write(`${JSON.stringify({ type: 'jobs_console_status', ...result })}\n`);
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
const job = result.jobId ? ` job=${result.jobId}` : '';
|
|
395
|
+
stdout.write(`[jobs-console] status=${result.status}${job} serverHeldStream=false serverAccessToLocalhost=false reasons=${result.reasonCodes.join(',')}\n`);
|
|
396
|
+
}
|