@letta-ai/letta-code 0.34.67 → 0.34.69
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/mcp-client.js +2 -2
- package/dist/mcp-client.js.map +1 -1
- package/dist/mcp-oauth.js +2 -2
- package/dist/mcp-oauth.js.map +1 -1
- package/dist/types/agent/subagents/subagent-model.d.ts.map +1 -1
- package/dist/types/backend/api/usage-cost.d.ts.map +1 -1
- package/dist/types/cli/helpers/stream-terminal-eof-guard.d.ts +1 -0
- package/dist/types/cli/helpers/stream-terminal-eof-guard.d.ts.map +1 -1
- package/dist/types/tools/impl/bash.d.ts +2 -0
- package/dist/types/tools/impl/bash.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-payload.d.ts +4 -0
- package/dist/types/tools/impl/external-llm-trace-payload.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-proxy.d.ts +4 -1
- package/dist/types/tools/impl/external-llm-trace-proxy.d.ts.map +1 -1
- package/dist/types/tools/impl/external-llm-trace-session.d.ts.map +1 -1
- package/dist/types/tools/impl/process_manager.d.ts +1 -0
- package/dist/types/tools/impl/process_manager.d.ts.map +1 -1
- package/dist/types/tools/impl/shell-runner.d.ts +3 -0
- package/dist/types/tools/impl/shell-runner.d.ts.map +1 -1
- package/dist/types/tools/impl/task-create.d.ts +2 -2
- package/dist/types/tools/impl/task-create.d.ts.map +1 -1
- package/dist/types/tools/impl/task-get.d.ts +2 -2
- package/dist/types/tools/impl/task-get.d.ts.map +1 -1
- package/dist/types/tools/impl/task-list.d.ts +2 -6
- package/dist/types/tools/impl/task-list.d.ts.map +1 -1
- package/dist/types/tools/impl/task-update.d.ts +2 -2
- package/dist/types/tools/impl/task-update.d.ts.map +1 -1
- package/dist/types/tools/impl/tasks/store.d.ts +8 -0
- package/dist/types/tools/impl/tasks/store.d.ts.map +1 -1
- package/dist/types/tools/impl/watch-pr-cloud.d.ts.map +1 -1
- package/letta.js +494 -260
- package/npm-shrinkwrap.json +107 -103
- package/package.json +2 -2
- package/scripts/integration/headless-sigterm.py +245 -0
- package/scripts/source-file-size-baseline.json +1 -1
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"""Linux one-shot CLI regression. Run after bun run build with python3 <this file>."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
import shlex
|
|
6
|
+
import signal
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
import tempfile
|
|
10
|
+
import threading
|
|
11
|
+
import time
|
|
12
|
+
import unittest
|
|
13
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class Provider(BaseHTTPRequestHandler):
|
|
18
|
+
def log_message(self, *args):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
def do_GET(self):
|
|
22
|
+
self.send_response(200)
|
|
23
|
+
self.send_header("Content-Type", "application/json")
|
|
24
|
+
self.end_headers()
|
|
25
|
+
self.wfile.write(
|
|
26
|
+
b'{"object":"list","data":[{"id":"policy","object":"model","owned_by":"local"}]}'
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
def do_POST(self):
|
|
30
|
+
self.rfile.read(int(self.headers["Content-Length"]))
|
|
31
|
+
self.send_response(200)
|
|
32
|
+
self.send_header("Content-Type", "text/event-stream")
|
|
33
|
+
self.end_headers()
|
|
34
|
+
send_tool = self.server.command and not self.server.ready.is_set()
|
|
35
|
+
if send_tool:
|
|
36
|
+
call = {
|
|
37
|
+
"index": 0,
|
|
38
|
+
"id": "call_1",
|
|
39
|
+
"type": "function",
|
|
40
|
+
"function": {
|
|
41
|
+
"name": "Bash",
|
|
42
|
+
"arguments": json.dumps(self.server.command),
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
for delta, finish in [
|
|
46
|
+
({"role": "assistant", "tool_calls": [call]}, None),
|
|
47
|
+
({}, "tool_calls"),
|
|
48
|
+
]:
|
|
49
|
+
chunk = {
|
|
50
|
+
"id": "completion",
|
|
51
|
+
"model": "policy",
|
|
52
|
+
"created": 1,
|
|
53
|
+
"choices": [{"index": 0, "delta": delta, "finish_reason": finish}],
|
|
54
|
+
}
|
|
55
|
+
self.wfile.write(f"data: {json.dumps(chunk)}\n\n".encode())
|
|
56
|
+
self.wfile.write(b"data: [DONE]\n\n")
|
|
57
|
+
else:
|
|
58
|
+
self.wfile.write(b": connected\n\n")
|
|
59
|
+
self.wfile.flush()
|
|
60
|
+
self.server.ready.set()
|
|
61
|
+
if not send_tool:
|
|
62
|
+
self.server.release.wait(30)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def wait_for(predicate, description):
|
|
66
|
+
deadline = time.monotonic() + 15
|
|
67
|
+
while not predicate():
|
|
68
|
+
if time.monotonic() >= deadline:
|
|
69
|
+
raise AssertionError(f"timed out waiting for {description}")
|
|
70
|
+
time.sleep(0.02)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class Shutdown(unittest.TestCase):
|
|
74
|
+
def exercise(self, cli, scenario):
|
|
75
|
+
with (
|
|
76
|
+
tempfile.TemporaryDirectory() as tmp,
|
|
77
|
+
ThreadingHTTPServer(("127.0.0.1", 0), Provider) as server,
|
|
78
|
+
):
|
|
79
|
+
root = Path(tmp)
|
|
80
|
+
ready, cleaned = root / "pid", root / "cleaned"
|
|
81
|
+
child = root / "child.py"
|
|
82
|
+
child.write_text(
|
|
83
|
+
"import os, signal, time, sys\n"
|
|
84
|
+
"def clean(*_):\n"
|
|
85
|
+
" time.sleep(.7)\n"
|
|
86
|
+
f" open({str(cleaned)!r}, 'w').close()\n"
|
|
87
|
+
" sys.exit(0)\n"
|
|
88
|
+
f"signal.signal(signal.SIGTERM, {'clean' if scenario == 'grace' else 'signal.SIG_IGN'})\n"
|
|
89
|
+
f"open({str(ready)!r}, 'w').write(str(os.getpid()))\n"
|
|
90
|
+
"signal.pause()\n"
|
|
91
|
+
)
|
|
92
|
+
server.command = (
|
|
93
|
+
None
|
|
94
|
+
if scenario == "silent"
|
|
95
|
+
else {
|
|
96
|
+
"command": f"{shlex.quote(sys.executable)} {shlex.quote(str(child))} >/dev/null 2>&1 & wait",
|
|
97
|
+
"description": "Wait for child",
|
|
98
|
+
"timeout": 60000,
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
if scenario == "background":
|
|
102
|
+
server.command["run_in_background"] = True
|
|
103
|
+
server.ready, server.release = threading.Event(), threading.Event()
|
|
104
|
+
threading.Thread(target=server.serve_forever, daemon=True).start()
|
|
105
|
+
env = {
|
|
106
|
+
"PATH": os.environ["PATH"],
|
|
107
|
+
"HOME": tmp,
|
|
108
|
+
"LETTA_HOME": tmp,
|
|
109
|
+
"DO_NOT_TRACK": "1",
|
|
110
|
+
"LLAMA_CPP_BASE_URL": f"http://127.0.0.1:{server.server_port}/v1",
|
|
111
|
+
}
|
|
112
|
+
spec = root / "agent.json"
|
|
113
|
+
spec.write_text(
|
|
114
|
+
json.dumps(
|
|
115
|
+
{
|
|
116
|
+
"name": "shutdown-test",
|
|
117
|
+
"model": "llama-cpp/policy",
|
|
118
|
+
"system": "Run the command.",
|
|
119
|
+
"max_tokens": 512,
|
|
120
|
+
"context_window_limit": 32000,
|
|
121
|
+
}
|
|
122
|
+
)
|
|
123
|
+
)
|
|
124
|
+
agent = json.loads(
|
|
125
|
+
subprocess.check_output(
|
|
126
|
+
[
|
|
127
|
+
*cli,
|
|
128
|
+
"agents",
|
|
129
|
+
"create",
|
|
130
|
+
"--backend",
|
|
131
|
+
"local",
|
|
132
|
+
"--body",
|
|
133
|
+
str(spec),
|
|
134
|
+
],
|
|
135
|
+
env=env,
|
|
136
|
+
timeout=30,
|
|
137
|
+
)
|
|
138
|
+
)
|
|
139
|
+
read_fd, write_fd = os.pipe()
|
|
140
|
+
try:
|
|
141
|
+
with (
|
|
142
|
+
(root / "cli.log").open("w") as log,
|
|
143
|
+
subprocess.Popen(
|
|
144
|
+
[
|
|
145
|
+
*cli,
|
|
146
|
+
"--backend",
|
|
147
|
+
"local",
|
|
148
|
+
"--agent",
|
|
149
|
+
agent["id"],
|
|
150
|
+
"--output-format",
|
|
151
|
+
"stream-json",
|
|
152
|
+
"--yolo",
|
|
153
|
+
"-p",
|
|
154
|
+
"Run.",
|
|
155
|
+
],
|
|
156
|
+
env=env,
|
|
157
|
+
stdout=write_fd,
|
|
158
|
+
stderr=log,
|
|
159
|
+
) as proc,
|
|
160
|
+
):
|
|
161
|
+
try:
|
|
162
|
+
self.assertTrue(
|
|
163
|
+
server.ready.wait(20), "provider request never arrived"
|
|
164
|
+
)
|
|
165
|
+
if server.command:
|
|
166
|
+
wait_for(
|
|
167
|
+
lambda: ready.exists() and ready.stat().st_size,
|
|
168
|
+
"foreground child",
|
|
169
|
+
)
|
|
170
|
+
if scenario == "full":
|
|
171
|
+
os.set_blocking(write_fd, False)
|
|
172
|
+
for size in (4096, 1):
|
|
173
|
+
try:
|
|
174
|
+
while True:
|
|
175
|
+
os.write(write_fd, b"x" * size)
|
|
176
|
+
except BlockingIOError:
|
|
177
|
+
pass
|
|
178
|
+
interrupt = (
|
|
179
|
+
signal.SIGINT if scenario == "sigint" else signal.SIGTERM
|
|
180
|
+
)
|
|
181
|
+
proc.send_signal(interrupt)
|
|
182
|
+
self.assertEqual(proc.wait(timeout=7), 128 + interrupt)
|
|
183
|
+
if scenario == "grace":
|
|
184
|
+
self.assertTrue(
|
|
185
|
+
cleaned.exists(), "TERM cleanup was cut short"
|
|
186
|
+
)
|
|
187
|
+
if ready.exists():
|
|
188
|
+
stat = Path(f"/proc/{ready.read_text()}/stat")
|
|
189
|
+
try:
|
|
190
|
+
alive = stat.read_text().split()[2] != "Z"
|
|
191
|
+
except FileNotFoundError:
|
|
192
|
+
alive = False
|
|
193
|
+
self.assertEqual(
|
|
194
|
+
alive,
|
|
195
|
+
scenario == "background",
|
|
196
|
+
"unexpected descendant state after CLI exit",
|
|
197
|
+
)
|
|
198
|
+
if scenario != "full":
|
|
199
|
+
os.close(write_fd)
|
|
200
|
+
write_fd = -1
|
|
201
|
+
frames = [
|
|
202
|
+
json.loads(line)
|
|
203
|
+
for line in os.read(read_fd, 65536).splitlines()
|
|
204
|
+
]
|
|
205
|
+
self.assertEqual(
|
|
206
|
+
[
|
|
207
|
+
f.get("message")
|
|
208
|
+
for f in frames
|
|
209
|
+
if f.get("stop_reason") == "cancelled"
|
|
210
|
+
],
|
|
211
|
+
[f"Interrupted by {interrupt.name}"],
|
|
212
|
+
)
|
|
213
|
+
finally:
|
|
214
|
+
proc.kill()
|
|
215
|
+
if ready.exists() and ready.read_text():
|
|
216
|
+
try:
|
|
217
|
+
os.kill(int(ready.read_text()), signal.SIGKILL)
|
|
218
|
+
except ProcessLookupError:
|
|
219
|
+
pass
|
|
220
|
+
finally:
|
|
221
|
+
os.close(read_fd)
|
|
222
|
+
if write_fd >= 0:
|
|
223
|
+
os.close(write_fd)
|
|
224
|
+
server.release.set()
|
|
225
|
+
server.shutdown()
|
|
226
|
+
|
|
227
|
+
def test_shutdown(self):
|
|
228
|
+
for cli in (
|
|
229
|
+
["node", "letta.js"],
|
|
230
|
+
[
|
|
231
|
+
"bun",
|
|
232
|
+
"--loader=.md:text",
|
|
233
|
+
"--loader=.mdx:text",
|
|
234
|
+
"--loader=.txt:text",
|
|
235
|
+
"run",
|
|
236
|
+
"src/index.ts",
|
|
237
|
+
],
|
|
238
|
+
):
|
|
239
|
+
for scenario in ("silent", "full", "grace", "sigint", "background"):
|
|
240
|
+
with self.subTest(runtime=cli[0], scenario=scenario):
|
|
241
|
+
self.exercise(cli, scenario)
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
if __name__ == "__main__":
|
|
245
|
+
unittest.main()
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"src/cli/reflection-transcript.test.ts": 1084,
|
|
21
21
|
"src/cli/subcommands/mcp.ts": 1045,
|
|
22
22
|
"src/cli/subcommands/skills.ts": 1243,
|
|
23
|
-
"src/headless.ts":
|
|
23
|
+
"src/headless.ts": 4768,
|
|
24
24
|
"src/hooks/integration.test.ts": 1147,
|
|
25
25
|
"src/index.ts": 2543,
|
|
26
26
|
"src/mods/learning-harness.ts": 2434,
|