✓
Passing This code compiles and runs correctly.
Code
// An agent, two sessions, one world: session A does a file-copy by hand,
// invents `backup`, and session B's vocabulary already contains it.
import std/io
import std/bridge
import std/runtime
import std/interpreter
tor read { path: string } -> string
proc read|zig {
const std = @import("std");
if (std.mem.indexOf(u8, path, "..") != null) return "<fenced>";
const p = std.fmt.allocPrint(std.heap.page_allocator, "tests/regression/400_RUNTIME_FEATURES/440_RESOURCE_BRIDGE/440_043_two_sessions_one_world/files/{s}", .{path}) catch unreachable;
return std.fs.cwd().readFileAlloc(std.heap.page_allocator, p, 1 << 20) catch "<unreadable>";
}
tor write { path: string, text: string } -> string
proc write|zig {
const std = @import("std");
if (std.mem.indexOf(u8, path, "..") != null) return "<fenced>";
const p = std.fmt.allocPrint(std.heap.page_allocator, "tests/regression/400_RUNTIME_FEATURES/440_RESOURCE_BRIDGE/440_043_two_sessions_one_world/files/{s}", .{path}) catch unreachable;
std.fs.cwd().writeFile(.{ .sub_path = p, .data = text }) catch return "<unwritable>";
return "wrote";
}
std/runtime:register(scope: "sandbox") {
read(1)
write(1)
}
tor turn { br: *std/bridge:Bridge, source: string }
turn = std/io:print.ln(" agent> {{ source:s }}")
|> std/bridge:run(br, source)
| result r |> std/interpreter:value.stringify(r.value): j |> std/io:print.ln(" world< {{ j:s }}")
| defined d |> std/io:print.ln(" world< defined {{ d:s }}")
| parse-error e |> std/io:print.ln(" world< parse: {{ e.message:s }}")
| event-denied ev |> std/io:print.ln(" world< denied: {{ ev:s }}")
| shape-error s |> std/io:print.ln(" world< shape: {{ s.branch:s }}")
| dispatch-error e |> std/io:print.ln(" world< dispatch: {{ e.message:s }}")
| validation-error _ |> std/io:print.ln(" world< validation")
| residue _ |> std/io:print.ln(" world< residue")
| exhausted _ |> std/io:print.ln(" world< exhausted")
| scope-not-found _ |> std/io:print.ln(" world< no scope")
| unhandled-branch _ |> std/io:print.ln(" world< unhandled")
[with]std/bridge:create(id: "a", scope: "sandbox", introspection: true, world: "tests/regression/400_RUNTIME_FEATURES/440_RESOURCE_BRIDGE/440_043_two_sessions_one_world/world"): a
|> turn(br: a, source: "read(path: \"hello.txt\") | ok t |> write(path: \"backup.txt\", text: t)")
|> turn(br: a, source: "tor backup { src: string, dst: string }\nbackup = read(path: src) | ok t |> write(path: dst, text: t)")
|> turn(br: a, source: "backup(src: \"hello.txt\", dst: \"again.txt\")")
|> std/bridge:close(br: a)
|> std/bridge:create(id: "b", scope: "sandbox", introspection: true, world: "tests/regression/400_RUNTIME_FEATURES/440_RESOURCE_BRIDGE/440_043_two_sessions_one_world/world"): b
|> turn(br: b, source: "vocabulary()")
|> turn(br: b, source: "backup(src: \"hello.txt\", dst: \"b-copy.txt\")")
|> turn(br: b, source: "format-disk()")
|> std/bridge:close(br: b)
Supporting Files
first line of the world
Actual
agent> read(path: "hello.txt") | ok t |> write(path: "backup.txt", text: t)
world< {"branch":"","value":"wrote"}
agent> tor backup { src: string, dst: string }
backup = read(path: src) | ok t |> write(path: dst, text: t)
world< defined backup
agent> backup(src: "hello.txt", dst: "again.txt")
world< {"branch":"","value":"wrote"}
agent> vocabulary()
world< {"branch":"","value":"read(path: string)\nwrite(path: string, text: string)\nvocabulary()\ngrammar()\nbind(name: string, value: Source)\nnote(text: Source) — speaks to the observer, not the user: reasoning, plans, and \"why I'm stuck\" go here\nbackup(src: string, dst: string)"}
agent> backup(src: "hello.txt", dst: "b-copy.txt")
world< {"branch":"","value":"wrote"}
agent> format-disk()
world< denied: format-disk
Expected output
agent> read(path: "hello.txt") | ok t |> write(path: "backup.txt", text: t)
world< {"branch":"","value":"wrote"}
agent> tor backup { src: string, dst: string }
backup = read(path: src) | ok t |> write(path: dst, text: t)
world< defined backup
agent> backup(src: "hello.txt", dst: "again.txt")
world< {"branch":"","value":"wrote"}
agent> vocabulary()
world< {"branch":"","value":"read(path: string)\nwrite(path: string, text: string)\nvocabulary()\ngrammar()\nbind(name: string, value: Source)\nnote(text: Source) — speaks to the observer, not the user: reasoning, plans, and \"why I'm stuck\" go here\nbackup(src: string, dst: string)"}
agent> backup(src: "hello.txt", dst: "b-copy.txt")
world< {"branch":"","value":"wrote"}
agent> format-disk()
world< denied: format-disk
Flows
flow ~register click a branch to expand · @labels scroll to their anchor
register (scope: "sandbox", source: read(1)
write(1))
subflow ~turn click a branch to expand · @labels scroll to their anchor
print.ln (expr: " agent> {{ source:s }}")
flow ~create click a branch to expand · @labels scroll to their anchor
create (id: "a", scope: "sandbox", introspection: true, world: "tests/regression/400_RUNTIME_FEATURES/440_RESOURCE_BRIDGE/440_043_two_sessions_one_world/world")
Test Configuration
MUST_RUN
Post-validation Script:
#!/bin/bash
# Pin the artifacts the transcript can't show: the defined verb persisted to
# the world, and every write landed the fixture's bytes. Then restore.
cd "$test_dir" 2>/dev/null || true
TD="${test_dir:-.}"
fail=0
grep -q 'backup = read(path: src)' "$TD/world/backup.k" || { echo "post: world/backup.k missing composite"; fail=1; }
for f in backup.txt again.txt b-copy.txt; do
grep -q 'first line of the world' "$TD/files/$f" || { echo "post: files/$f missing fixture bytes"; fail=1; }
done
rm -rf "$TD/world" "$TD/files/backup.txt" "$TD/files/again.txt" "$TD/files/b-copy.txt"
exit $fail