forked from WHC/Hermit
Initial CST-Agent: portable Linux/Termux/Windows coding agent.
Vendored sashidown, OpenAI-compatible env (OPENAI_*), and bootstrap scripts. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
CC ?= gcc
|
||||
CFLAGS ?= -std=c11 -Wall -Wextra -O2
|
||||
|
||||
.PHONY: all clean test
|
||||
|
||||
all: calc
|
||||
|
||||
calc: calc.c
|
||||
$(CC) $(CFLAGS) -o $@ $<
|
||||
|
||||
test: calc
|
||||
./tests/smoke.sh
|
||||
|
||||
clean:
|
||||
rm -f calc
|
||||
@@ -0,0 +1,19 @@
|
||||
# mini_calc
|
||||
|
||||
Tiny integer calculator CLI for CST-Agent e2e demos.
|
||||
|
||||
## Ops
|
||||
|
||||
`add` `sub` `mul` `div` — all four work (see `make test`).
|
||||
|
||||
```bash
|
||||
./calc add 2 3 # → 5
|
||||
./calc div 8 2 # → 4
|
||||
```
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
make
|
||||
make test
|
||||
```
|
||||
@@ -0,0 +1,11 @@
|
||||
# 任务:修好 mini_calc
|
||||
|
||||
你在一个很小的 C 项目里。请完成下列事项后结束(不要无关重构):
|
||||
|
||||
1. 阅读 `README.md`、`calc.c`、`tests/smoke.sh`。
|
||||
2. 修复 `add` 的 off-by-one bug(应为 `a+b`,不是 `a+b+1`)。
|
||||
3. 实现真正的整数除法 `div_ints`(`a/b`,调用方已保证 `b!=0`)。
|
||||
4. 运行 `make test`,确保全部用例通过。
|
||||
5. 用简短中文说明你改了什么。
|
||||
|
||||
可用工具:`read_file`、`run_shell`、`write_file` / `apply_patch`。工作区根目录就是本项目。
|
||||
@@ -0,0 +1,58 @@
|
||||
/* mini_calc — intentionally broken fixture for CST-Agent e2e / paper case study.
|
||||
*
|
||||
* Bugs (for the agent to fix):
|
||||
* 1) add(): off-by-one — returns a+b+1
|
||||
* 2) div(): missing — only stub returns 0
|
||||
* README claims all four ops work (false until fixed).
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int add(int a, int b) {
|
||||
/* BUG: off-by-one */
|
||||
return a + b + 1;
|
||||
}
|
||||
|
||||
int sub(int a, int b) { return a - b; }
|
||||
|
||||
int mul(int a, int b) { return a * b; }
|
||||
|
||||
int div_ints(int a, int b) {
|
||||
/* BUG: not implemented */
|
||||
(void)a;
|
||||
(void)b;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usage(const char *argv0) {
|
||||
fprintf(stderr, "Usage: %s <add|sub|mul|div> <a> <b>\n", argv0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 4) {
|
||||
usage(argv[0]);
|
||||
return 2;
|
||||
}
|
||||
int a = atoi(argv[2]);
|
||||
int b = atoi(argv[3]);
|
||||
int r = 0;
|
||||
if (strcmp(argv[1], "add") == 0)
|
||||
r = add(a, b);
|
||||
else if (strcmp(argv[1], "sub") == 0)
|
||||
r = sub(a, b);
|
||||
else if (strcmp(argv[1], "mul") == 0)
|
||||
r = mul(a, b);
|
||||
else if (strcmp(argv[1], "div") == 0) {
|
||||
if (b == 0) {
|
||||
fprintf(stderr, "div by zero\n");
|
||||
return 3;
|
||||
}
|
||||
r = div_ints(a, b);
|
||||
} else {
|
||||
usage(argv[0]);
|
||||
return 2;
|
||||
}
|
||||
printf("%d\n", r);
|
||||
return 0;
|
||||
}
|
||||
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/usr/bin/env bash
|
||||
# Smoke tests for mini_calc. Exit 0 only when add/sub/mul/div are correct.
|
||||
set -euo pipefail
|
||||
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
CALC="$ROOT/calc"
|
||||
fail=0
|
||||
|
||||
expect() {
|
||||
local op=$1 a=$2 b=$3 want=$4
|
||||
local got
|
||||
got="$("$CALC" "$op" "$a" "$b")"
|
||||
if [[ "$got" != "$want" ]]; then
|
||||
echo "FAIL: $op $a $b → got '$got' want '$want'"
|
||||
fail=1
|
||||
else
|
||||
echo "ok: $op $a $b → $got"
|
||||
fi
|
||||
}
|
||||
|
||||
expect add 2 3 5
|
||||
expect sub 9 4 5
|
||||
expect mul 3 4 12
|
||||
expect div 8 2 4
|
||||
|
||||
if [[ "$fail" -ne 0 ]]; then
|
||||
echo "smoke: FAILED"
|
||||
exit 1
|
||||
fi
|
||||
echo "smoke: PASSED"
|
||||
exit 0
|
||||
Reference in New Issue
Block a user