Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions specs/vps/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# specs/vps -- VPS protocol compatibility layer (Ladder front)

The law lives in `ladder_protocol_map.t27` (9 tests). Every decision the deployed adapter
makes -- model allowlist, request verdicts, supported vs strippable features, effective
max_tokens, stop vocabularies, role mapping (developer -> system), loopback-only bind --
is a function of that spec. The spec is the source of truth; nothing else decides.

Artifacts and deployment (verified 2026-11-11):

- `ladder_protocol_map.generated.mts` -- generated by `t27b ts` from the spec; the committed
copy is byte-identical to a fresh regeneration (checked in CI-style locally), so drift is a
failing diff.
- The executable chain on the VPS: agents -> 127.0.0.1:3132 (launchd SSH tunnel,
com.t27.vps-ladder-tunnel) -> VPS 127.0.0.1:3133 (`ladder-protocol-adapter.service`,
thin loader) -> 127.0.0.1:3131 (`dsh-ladder.service`) -> zai free rung.
- The thin loader (`protocol-adapter.mjs`, IO glue only: routing, JSON walk, SSE piping; zero
protocol decisions) is a deployment artifact kept on the VPS at
`/root/.t27os/bin/protocol-adapter.mjs`, sha256 a3946055b37817a6672b5a50a758d4f1bcca9d0761049a40121a6bbacc57742e .
It is intentionally NOT committed: it is foreign (non-t27) and under the foreign-line budget;
its sha256 here pins the reviewed bytes. To change protocol behavior, change the spec,
regenerate, redeploy -- never edit the loader.

Acceptance evidence (2026-11-11): opencode 2.2.5, claude 2.1.310, crush 0.92.0, codex 0.167.1
each completed a read->write task through the chain (files verified); law behaviors observed
live: 403 for an off-allowlist model, web_search tool stripped per law, developer role mapped.
Zero paid calls; local LM Studio not used by any agent.
305 changes: 305 additions & 0 deletions specs/vps/ladder_protocol_map.generated.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,305 @@
// Generated by t27b ts from module VpsLadderProtocolMap -- DO NOT EDIT; the decisions are specs/tri/t27b/ts_plan.t27
// phi^2 + 1/phi^2 = 3 | TRINITY

let t27_n: number = 0;
function t27_fail(m: string): never { throw new RangeError('t27: ' + m); }
function t27_chk(v: number, lo: number, hi: number): number { if (v < lo || v > hi) { t27_fail('integer overflow'); } return v; }
function t27_wrap(v: number, w: number, s: boolean): number { if (s) { return w === 32 ? v | 0 : (v << (32 - w)) >> (32 - w); } return w === 32 ? v >>> 0 : v & (2 ** w - 1); }
function t27_div(a: number, b: number): number { if (b === 0) { t27_fail('division by zero'); } return Math.trunc(a / b); }
function t27_rem(a: number, b: number): number { if (b === 0) { t27_fail('division by zero'); } return a % b; }
function t27_shl(a: number, b: number, w: number, s: boolean): number { if (b >= w) { t27_fail('shift amount too large'); } return t27_wrap(a << b, w, s); }
function t27_shr(a: number, b: number, w: number, s: boolean): number { if (b >= w) { t27_fail('shift amount too large'); } return s ? a >> b : a >>> b; }
function t27_check(c: boolean, test: string, line: number): void { if (!c) { throw new Error('t27: assert failed in ' + test + ' at line ' + String(line)); } }
function t27_assert(c: boolean, test: string, line: number): void { t27_n = t27_n + 1; t27_check(c, test, line); }
type t27_case = [string, () => number];

export const MODEL_WORD0: number = 762145895;
export const MODEL_WORD1: number = 758328885;
export const MODEL_WORD2: number = 1935764582;
export const MODEL_WORD3: number = 104;
export const MODEL_NAME_LEN: number = 13;
export const BIND_LOOPBACK_U32: number = 16777343;
export const MAX_TOKENS_DEFAULT: number = 2048;
export const MAX_TOKENS_CAP: number = 8192;
export const CHAT_STOP: number = 0;
export const CHAT_LENGTH: number = 1;
export const CHAT_TOOL_CALLS: number = 2;
export const ANTH_END_TURN: number = 0;
export const ANTH_MAX_TOKENS: number = 1;
export const ANTH_TOOL_USE: number = 2;
export const ANTH_UNSUPPORTED: number = 255;
export const RESP_COMPLETED: number = 1;
export const RESP_INCOMPLETE: number = 2;
export const RESP_UNSUPPORTED: number = 255;

export function word_matches(got: number, idx: number): boolean {
if ((idx === 0)) {
return (got === MODEL_WORD0);
}
if ((idx === 1)) {
return (got === MODEL_WORD1);
}
if ((idx === 2)) {
return (got === MODEL_WORD2);
}
if ((idx === 3)) {
return (got === MODEL_WORD3);
}
return false;
}

export function model_allowed(len: number, w0: number, w1: number, w2: number, w3: number): boolean {
if ((len !== MODEL_NAME_LEN)) {
return false;
}
return (((word_matches(w0, 0) && word_matches(w1, 1)) && word_matches(w2, 2)) && word_matches(w3, 3));
}

export function anth_req_verdict(has_model: boolean, max_tokens: number, name_ok: boolean): number {
if ((!has_model)) {
return 400;
}
if ((max_tokens === 0)) {
return 400;
}
if ((!name_ok)) {
return 403;
}
return 0;
}

export function resp_req_verdict(has_model: boolean, name_ok: boolean): number {
if ((!has_model)) {
return 400;
}
if ((!name_ok)) {
return 403;
}
return 0;
}

export function feature_supported(code: number): boolean {
if ((code === 0)) {
return true;
}
if ((code === 1)) {
return true;
}
if ((code === 2)) {
return true;
}
if ((code === 3)) {
return true;
}
if ((code === 4)) {
return true;
}
return false;
}

export function effective_max_tokens(requested: number): number {
if ((requested === 0)) {
return MAX_TOKENS_DEFAULT;
}
if ((requested > MAX_TOKENS_CAP)) {
return MAX_TOKENS_CAP;
}
return requested;
}

export function anth_stop_reason(chat_finish: number): number {
if ((chat_finish === CHAT_STOP)) {
return ANTH_END_TURN;
}
if ((chat_finish === CHAT_LENGTH)) {
return ANTH_MAX_TOKENS;
}
if ((chat_finish === CHAT_TOOL_CALLS)) {
return ANTH_TOOL_USE;
}
return ANTH_UNSUPPORTED;
}

export function resp_status(chat_finish: number): number {
if ((chat_finish === CHAT_STOP)) {
return RESP_COMPLETED;
}
if ((chat_finish === CHAT_LENGTH)) {
return RESP_INCOMPLETE;
}
if ((chat_finish === CHAT_TOOL_CALLS)) {
return RESP_COMPLETED;
}
return RESP_UNSUPPORTED;
}

export function loopback_only(ip_packed_le: number): boolean {
return (ip_packed_le === BIND_LOOPBACK_U32);
}

export function t27_test_the_allowlisted_model_passes_and_others_are_refused(): number {
t27_n = 0;
t27_assert(model_allowed(MODEL_NAME_LEN, MODEL_WORD0, MODEL_WORD1, MODEL_WORD2, MODEL_WORD3), 'the_allowlisted_model_passes_and_others_are_refused', 138);
t27_assert((!model_allowed(5, MODEL_WORD0, MODEL_WORD1, MODEL_WORD2, MODEL_WORD3)), 'the_allowlisted_model_passes_and_others_are_refused', 139);
t27_assert((!model_allowed(5, 1953526119, 0, 0, 0)), 'the_allowlisted_model_passes_and_others_are_refused', 141);
t27_assert((!model_allowed(12, MODEL_WORD0, MODEL_WORD1, MODEL_WORD2, MODEL_WORD3)), 'the_allowlisted_model_passes_and_others_are_refused', 143);
return t27_n;
}

export function t27_test_anthropic_request_verdicts(): number {
t27_n = 0;
t27_assert((anth_req_verdict(true, 100, true) === 0), 'anthropic_request_verdicts', 147);
t27_assert((anth_req_verdict(false, 100, true) === 400), 'anthropic_request_verdicts', 148);
t27_assert((anth_req_verdict(true, 0, true) === 400), 'anthropic_request_verdicts', 149);
t27_assert((anth_req_verdict(true, 100, false) === 403), 'anthropic_request_verdicts', 150);
return t27_n;
}

export function t27_test_responses_request_verdicts(): number {
t27_n = 0;
t27_assert((resp_req_verdict(true, true) === 0), 'responses_request_verdicts', 154);
t27_assert((resp_req_verdict(false, true) === 400), 'responses_request_verdicts', 155);
t27_assert((resp_req_verdict(true, false) === 403), 'responses_request_verdicts', 156);
return t27_n;
}

export function t27_test_supported_features_are_exactly_the_five(): number {
t27_n = 0;
t27_assert(feature_supported(0), 'supported_features_are_exactly_the_five', 160);
t27_assert(feature_supported(1), 'supported_features_are_exactly_the_five', 161);
t27_assert(feature_supported(2), 'supported_features_are_exactly_the_five', 162);
t27_assert(feature_supported(3), 'supported_features_are_exactly_the_five', 163);
t27_assert(feature_supported(4), 'supported_features_are_exactly_the_five', 164);
t27_assert((!feature_supported(10)), 'supported_features_are_exactly_the_five', 165);
t27_assert((!feature_supported(11)), 'supported_features_are_exactly_the_five', 166);
t27_assert((!feature_supported(12)), 'supported_features_are_exactly_the_five', 167);
t27_assert((!feature_supported(13)), 'supported_features_are_exactly_the_five', 168);
t27_assert((!feature_supported(200)), 'supported_features_are_exactly_the_five', 169);
return t27_n;
}

export function t27_test_effective_max_tokens_follows_the_law(): number {
t27_n = 0;
t27_assert((effective_max_tokens(0) === MAX_TOKENS_DEFAULT), 'effective_max_tokens_follows_the_law', 173);
t27_assert((effective_max_tokens(100) === 100), 'effective_max_tokens_follows_the_law', 174);
t27_assert((effective_max_tokens(100000) === MAX_TOKENS_CAP), 'effective_max_tokens_follows_the_law', 175);
return t27_n;
}

export function t27_test_stop_vocabularies_map_exactly(): number {
t27_n = 0;
t27_assert((anth_stop_reason(CHAT_STOP) === ANTH_END_TURN), 'stop_vocabularies_map_exactly', 179);
t27_assert((anth_stop_reason(CHAT_LENGTH) === ANTH_MAX_TOKENS), 'stop_vocabularies_map_exactly', 180);
t27_assert((anth_stop_reason(CHAT_TOOL_CALLS) === ANTH_TOOL_USE), 'stop_vocabularies_map_exactly', 181);
t27_assert((anth_stop_reason(9) === ANTH_UNSUPPORTED), 'stop_vocabularies_map_exactly', 182);
t27_assert((resp_status(CHAT_STOP) === RESP_COMPLETED), 'stop_vocabularies_map_exactly', 183);
t27_assert((resp_status(CHAT_LENGTH) === RESP_INCOMPLETE), 'stop_vocabularies_map_exactly', 184);
t27_assert((resp_status(CHAT_TOOL_CALLS) === RESP_COMPLETED), 'stop_vocabularies_map_exactly', 185);
t27_assert((resp_status(9) === RESP_UNSUPPORTED), 'stop_vocabularies_map_exactly', 186);
return t27_n;
}

export function feature_strippable(code: number): boolean {
if ((code === 10)) {
return true;
}
if ((code === 11)) {
return true;
}
if ((code === 12)) {
return true;
}
if ((code === 13)) {
return true;
}
return false;
}

export function t27_test_cloud_only_tools_are_stripped_not_served(): number {
t27_n = 0;
t27_assert(feature_strippable(10), 'cloud_only_tools_are_stripped_not_served', 202);
t27_assert(feature_strippable(11), 'cloud_only_tools_are_stripped_not_served', 203);
t27_assert(feature_strippable(12), 'cloud_only_tools_are_stripped_not_served', 204);
t27_assert(feature_strippable(13), 'cloud_only_tools_are_stripped_not_served', 205);
t27_assert((!feature_strippable(0)), 'cloud_only_tools_are_stripped_not_served', 206);
t27_assert((!feature_strippable(3)), 'cloud_only_tools_are_stripped_not_served', 207);
t27_assert((!feature_strippable(200)), 'cloud_only_tools_are_stripped_not_served', 208);
return t27_n;
}
export const CHAT_ROLE_SYSTEM: number = 0;
export const CHAT_ROLE_USER: number = 1;
export const CHAT_ROLE_ASSISTANT: number = 2;
export const CHAT_ROLE_TOOL: number = 3;

export function chat_role(client_role: number): number {
if ((client_role === 0)) {
return CHAT_ROLE_SYSTEM;
}
if ((client_role === 1)) {
return CHAT_ROLE_USER;
}
if ((client_role === 2)) {
return CHAT_ROLE_ASSISTANT;
}
if ((client_role === 3)) {
return CHAT_ROLE_TOOL;
}
if ((client_role === 4)) {
return CHAT_ROLE_SYSTEM;
}
return 255;
}

export function t27_test_developer_role_maps_to_system_and_unknowns_are_refused(): number {
t27_n = 0;
t27_assert((chat_role(0) === CHAT_ROLE_SYSTEM), 'developer_role_maps_to_system_and_unknowns_are_refused', 231);
t27_assert((chat_role(1) === CHAT_ROLE_USER), 'developer_role_maps_to_system_and_unknowns_are_refused', 232);
t27_assert((chat_role(2) === CHAT_ROLE_ASSISTANT), 'developer_role_maps_to_system_and_unknowns_are_refused', 233);
t27_assert((chat_role(3) === CHAT_ROLE_TOOL), 'developer_role_maps_to_system_and_unknowns_are_refused', 234);
t27_assert((chat_role(4) === CHAT_ROLE_SYSTEM), 'developer_role_maps_to_system_and_unknowns_are_refused', 235);
t27_assert((chat_role(9) === 255), 'developer_role_maps_to_system_and_unknowns_are_refused', 236);
return t27_n;
}

export function t27_test_the_adapter_binds_loopback_only(): number {
t27_n = 0;
t27_assert(loopback_only(BIND_LOOPBACK_U32), 'the_adapter_binds_loopback_only', 240);
t27_assert((!loopback_only(0)), 'the_adapter_binds_loopback_only', 241);
t27_assert((!loopback_only(16777344)), 'the_adapter_binds_loopback_only', 242);
return t27_n;
}

export const t27_tests: t27_case[] = [
['the_allowlisted_model_passes_and_others_are_refused', t27_test_the_allowlisted_model_passes_and_others_are_refused],
['anthropic_request_verdicts', t27_test_anthropic_request_verdicts],
['responses_request_verdicts', t27_test_responses_request_verdicts],
['supported_features_are_exactly_the_five', t27_test_supported_features_are_exactly_the_five],
['effective_max_tokens_follows_the_law', t27_test_effective_max_tokens_follows_the_law],
['stop_vocabularies_map_exactly', t27_test_stop_vocabularies_map_exactly],
['cloud_only_tools_are_stripped_not_served', t27_test_cloud_only_tools_are_stripped_not_served],
['developer_role_maps_to_system_and_unknowns_are_refused', t27_test_developer_role_maps_to_system_and_unknowns_are_refused],
['the_adapter_binds_loopback_only', t27_test_the_adapter_binds_loopback_only],
];

export const t27_invariants: t27_case[] = [
];

/// The assert table of `t27c test-report`, line for line.
export function t27_report(): string {
const lines: string[] = [' runtime asserts executed, per test (#6509; a pass with 0 is vacuous, T730):'];
let passed = 0;
let vacuous = 0;
for (const [name, run] of t27_tests) {
let n = -1;
try { n = run(); } catch (e) { n = -1; }
if (n < 0) { lines.push(' ' + '-'.padStart(6) + ' ' + name + ' (failed, not counted)'); continue; }
passed = passed + 1;
if (n === 0) { vacuous = vacuous + 1; lines.push(' ' + '0'.padStart(6) + ' ' + name + ' VACUOUS'); } else { lines.push(' ' + String(n).padStart(6) + ' ' + name); }
}
lines.push(' vacuous passes ' + String(vacuous) + ' of ' + String(passed) + ' (passed with 0 runtime asserts executed)');
return lines.join(String.fromCharCode(10));
}

/// Every test and invariant that throws, with what it threw; empty when all hold.
export function t27_failures(): string[] { const out: string[] = []; for (const [name, run] of t27_tests) { try { run(); } catch (e) { out.push('test ' + name + ': ' + String(e)); } } for (const [name, run] of t27_invariants) { try { run(); } catch (e) { out.push('invariant ' + name + ': ' + String(e)); } } return out; }

Loading
Loading