Skip to content
Draft
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
2 changes: 2 additions & 0 deletions src/core/tool_dispatch_adapter.ail
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export func tool_result_item_to_json(item: ToolResultItem) -> Json {
kv("bytes_written", jnum(_int_to_float(r.bytes_written))),
kv("sha256", js(r.sha256)),
kv("diff", js(r.diff)),
kv("typecheck", js(r.typecheck)),
kv("exit_code", jnum(0.0))
]),

Expand All @@ -101,6 +102,7 @@ export func tool_result_item_to_json(item: ToolResultItem) -> Json {
kv("applied_edits", jnum(_int_to_float(r.applied_edits))),
kv("dry_run", jb(r.dry_run)),
kv("match_strategy", js(r.match_strategy)),
kv("typecheck", js(r.typecheck)),
kv("exit_code", jnum(0.0))
]),

Expand Down
46 changes: 36 additions & 10 deletions src/core/tool_runtime.ail
Original file line number Diff line number Diff line change
Expand Up @@ -605,13 +605,17 @@ func run_write_file(id: string, path: string, content: string, workdir: string)
Err(msg) => ToolErrorResult({ id: id, tool: "WriteFile", message: "cannot create parent directory: ${msg}" }),
Ok(_) => match writeFileResult(resolved, content) {
Err(msg) => ToolErrorResult({ id: id, tool: "WriteFile", message: msg }),
Ok(_) => WriteFileResult({
id: id,
path: path,
bytes_written: length(content),
sha256: sha256Hex(content),
diff: build_write_file_diff(path, before, content, existed_before)
})
Ok(_) => {
let tc = ail_typecheck_after_edit(resolved, workdir);
WriteFileResult({
id: id,
path: path,
bytes_written: length(content),
sha256: sha256Hex(content),
diff: build_write_file_diff(path, before, content, existed_before),
typecheck: tc
})
}
}
}
}
Expand Down Expand Up @@ -791,12 +795,14 @@ func run_edit_file(
first_changed_line: changed_line,
applied_edits: applied.applied,
dry_run: true,
match_strategy: "exact"
match_strategy: "exact",
typecheck: ""
})
else
match atomic_write(resolved, after) {
Err(msg) => ToolErrorResult({ id: id, tool: "EditFile", message: msg }),
Ok(_) =>
Ok(_) => {
let tc = ail_typecheck_after_edit(resolved, workdir);
EditFileResult({
id: id,
path: path,
Expand All @@ -806,8 +812,10 @@ func run_edit_file(
first_changed_line: changed_line,
applied_edits: applied.applied,
dry_run: false,
match_strategy: "exact"
match_strategy: "exact",
typecheck: tc
})
}
}
}
}
Expand Down Expand Up @@ -870,6 +878,24 @@ func to_test_result(id: string, req: ProcessExecReq, out: ProcessOutput) -> Tool
})
}

-- Per-edit DP7 (M-MOTOKO-IMMEDIATE-TYPECHECK): after a .ail write/edit, type-check the
-- file IMMEDIATELY and return concise feedback in the tool result. The finalize-only dp7
-- gate is never reached on max_steps runs, so without this the model writes broken AILANG
-- (e.g. => match-arm drift) for the whole step budget with no feedback. Non-.ail files -> "".
func ail_typecheck_after_edit(resolved: string, workdir: string) -> string ! {Process} {
if not endsWith(resolved, ".ail") then ""
else match exec("bash", ["-c", "cd \"$1\" && ailang check \"$2\" 2>&1", "_chk", workdir, resolved]) {
Err(_) => "",
Ok(out) =>
if out.exitCode == 0 then "ailang check: OK - file type-checks."
else {
let raw = toString(out.stdout);
let snippet = if length(raw) > 1200 then substring(raw, 0, 1200) else raw;
"ailang check: FAILED - fix these errors before continuing:\n${snippet}"
}
}
}

func run_process_result(tool: string, id: string, req: ProcessExecReq) -> ToolResultItem ! {Process} {
-- M-MOTOKO-RPC-LOOP M10 follow-up: in v2 standalone mode (no
-- env-server delegation), wrap shell-tokened cmds in `bash -lc` so
Expand Down
6 changes: 4 additions & 2 deletions src/core/types.ail
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ export type ToolResultItem
path: string,
bytes_written: int,
sha256: string,
diff: string
diff: string,
typecheck: string
})
| EditFileResult({
id: string,
Expand All @@ -139,7 +140,8 @@ export type ToolResultItem
first_changed_line: int,
applied_edits: int,
dry_run: bool,
match_strategy: string
match_strategy: string,
typecheck: string
})
| BashExecResult({
id: string,
Expand Down
Loading