Spike: fs/upgrade/bench examples, agent resumes interrupted turns, world lock, short trap reasons

This commit is contained in:
2026-10-15 05:00:33 +01:00
parent 83bbbb33a8
commit 0be152dda9
13 changed files with 293 additions and 8 deletions
+7
View File
@@ -0,0 +1,7 @@
[package]
name = "notes"
version = "0.1.0"
edition = "2024"
[dependencies]
serde_json = "1"
+39
View File
@@ -0,0 +1,39 @@
//! Keeps a list of notes in /data/notes.json and publishes them as
//! /public/notes.txt. Version 2: adds `count` and no longer crashes.
use serde_json::{Value, json};
use std::io::{BufRead, Write};
const DATA: &str = "/data/notes.json";
fn save(notes: &[String]) {
std::fs::write(DATA, serde_json::to_string(notes).unwrap()).unwrap();
std::fs::write("/public/notes.txt", notes.join("\n") + "\n").unwrap();
}
fn main() {
let mut notes: Vec<String> = std::fs::read_to_string(DATA)
.ok()
.and_then(|s| serde_json::from_str(&s).ok())
.unwrap_or_default();
let mut out = std::io::stdout().lock();
for line in std::io::stdin().lock().lines() {
let Ok(line) = line else { break };
let Ok(msg) = serde_json::from_str::<Value>(&line) else { continue };
let body = &msg["body"];
let reply = match body["type"].as_str() {
Some("shutdown") => break,
Some("add") => {
notes.push(body["text"].as_str().unwrap_or_default().to_string());
save(&notes);
json!({"type": "added", "count": notes.len()})
}
Some("list") => json!({"type": "notes", "items": notes}),
Some("count") => json!({"type": "count", "count": notes.len(), "version": 2}),
// Version 2 fixes the crash.
Some("crash") => json!({"type": "not_crashing", "version": 2}),
_ => json!({"type": "error", "reason": "unknown message"}),
};
writeln!(out, "{}", json!({"to": msg["from"], "reply_to": msg["id"], "body": reply})).unwrap();
out.flush().unwrap();
}
}
+8
View File
@@ -0,0 +1,8 @@
{"send": {"type": "add", "text": "test note"}}
{"expect": {"type": "added"}}
{"send": {"type": "list"}}
{"expect": {"type": "notes"}}
{"send": {"type": "count"}}
{"expect": {"type": "count", "version": 2}}
{"send": {"type": "crash"}}
{"expect": {"type": "not_crashing"}}