agent-test-kit 0.0.1__tar.gz → 0.0.2__tar.gz

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.
Files changed (22) hide show
  1. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/PKG-INFO +1 -1
  2. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/agent_test_kit.egg-info/PKG-INFO +1 -1
  3. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/claude_code.py +83 -7
  4. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/kept.py +13 -9
  5. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/pyproject.toml +1 -1
  6. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/LICENSE +0 -0
  7. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/README.md +0 -0
  8. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/agent_test_kit.egg-info/SOURCES.txt +0 -0
  9. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/agent_test_kit.egg-info/dependency_links.txt +0 -0
  10. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/agent_test_kit.egg-info/entry_points.txt +0 -0
  11. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/agent_test_kit.egg-info/top_level.txt +0 -0
  12. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/__init__.py +0 -0
  13. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/cli.py +0 -0
  14. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/events.py +0 -0
  15. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/label.html +0 -0
  16. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/labels.py +0 -0
  17. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/out.py +0 -0
  18. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/page.py +0 -0
  19. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/stages.py +0 -0
  20. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/tally.py +0 -0
  21. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/atkit/writer.py +0 -0
  22. {agent_test_kit-0.0.1 → agent_test_kit-0.0.2}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agent-test-kit
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: An agent test kit: test coding agents on the work they really did
5
5
  License-Expression: Apache-2.0
6
6
  Project-URL: Repository, https://github.com/shifting-labs/atkit
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: agent-test-kit
3
- Version: 0.0.1
3
+ Version: 0.0.2
4
4
  Summary: An agent test kit: test coding agents on the work they really did
5
5
  License-Expression: Apache-2.0
6
6
  Project-URL: Repository, https://github.com/shifting-labs/atkit
@@ -32,6 +32,29 @@ SETTING = re.compile(r"[A-Za-z_]\w*\+?=") # a variable being set
32
32
  # A whole word that is a program, with its folders or without. The whole word is looked at, because the end of one that
33
33
  # is not, such as a redirection, can be the name of a file.
34
34
  PROGRAM = re.compile(r"(?:[^\s<>|&;()`/]*/)*(\w[\w.+-]*)", re.ASCII)
35
+ AGENTS = frozenset({"Agent", "Task", "Workflow"}) # they start agents whose own calls are not in this log
36
+ # What a command line can run and still change no file of the work: programs that only read, and what git shows, records
37
+ # or sends.
38
+ # ponytail: the usual ones, and no thought for a git hook that edits files. A line with any other program may have
39
+ # written. Add one only when none of its options writes or runs another program, or refuse those options too.
40
+ READING = frozenset("[ cat cd cmp cut diff echo egrep fgrep grep head ls nl printf pwd rg stat tail test tr true type wc which".split())
41
+ GIT = frozenset("add blame cat-file commit describe diff grep log ls-files ls-tree merge-base push rev-list rev-parse shortlog show status".split())
42
+ # What writes a file or runs a program. Git also takes the start of a long option's name, and -O in a row of short ones.
43
+ WRITING = ("--output", "--exec", "--ext-diff", "--open-files-in-pager", "--receive-pack")
44
+ # The next piece of a command line: a word with its quotes, or what stands between two words. A mark inside quotes or
45
+ # after a backslash is a part of its word. In $'...' a backslash means something else, so that is no piece.
46
+ PIECE = re.compile(r"""[ \t]*(?:(?P<mark>[();<>|&\n]+)|(?P<word>(?:[^\s();<>|&'"\\$]|\$(?!')|\\[^\r\n]|'[^']*'|"(?:[^"\\]|\\.)*")+))""", re.DOTALL)
47
+ # A quoted or escaped part of a command line. Each is read from its start, so a quote inside one never opens another.
48
+ # The first kind is a text given as "$(cat <<'EOF' ... EOF)", as a commit's message often is. The shell reads nothing in
49
+ # it, up to the first line that is its end mark alone, and only the closing bracket may follow that line. It must be a
50
+ # word of its own and no option.
51
+ # ponytail: bash 3.2, which macOS still has, can end such a text at a ) inside it and run what follows a quote after
52
+ # that. Newer shells do not, so the text is read as they read it.
53
+ PART = re.compile(r"""(?<!\S)["]\$\(cat <<'(?P<end>\w+)'\n(?!-)(?:(?!(?P=end)\n)[^\n]*\n)*(?P=end)\n\s*\)"(?![^\s;&|])|\\.|'[^']*'|"(?:[^"\\]|\\.)*["]""", re.DOTALL)
54
+ # What the shell runs or works out, in quotes too, unless it is only a variable's value.
55
+ WORKED_OUT = re.compile(r"`|\$[(\[]|\$\{(?!\w+\})")
56
+ # A word that the shell can turn into an option, or into more than one word.
57
+ UNCLEAR = re.compile(r"\$|-.*\$|.*\{.*(?:,|\.\.)", re.DOTALL)
35
58
  SHOWN = 300 # how much of a message is shown back to the person who labels a result
36
59
  # The notice the harness sends when a command it ran in the background is over. The call's id and the status come first
37
60
  # and are the harness's own; the summary after them quotes words the agent wrote, so the exit code is read at its end.
@@ -63,6 +86,57 @@ def program(command):
63
86
  return "unnamed"
64
87
 
65
88
 
89
+ def changes_nothing(command):
90
+ """Whether a command line plainly changes no file of the work. It may have written wherever that is not plain: with
91
+ a program that is not listed, a command inside another, a function, a loop, a setting, or output to a file."""
92
+ command = PART.sub(lambda part: "text" if part["end"] else part[0], command).strip(" \t")
93
+ if WORKED_OUT.search(command):
94
+ return False
95
+ lines, line, at = [], [], 0
96
+ redirect = None # what stands before the word that says where a program reads or writes
97
+ while at < len(command):
98
+ piece = PIECE.match(command, at)
99
+ if not piece:
100
+ return False # a quote left open, or a character that one shell reads in another way than the next
101
+ mark, word, at = piece["mark"], piece["word"], piece.end()
102
+ if redirect:
103
+ # Nothing is kept of what goes to /dev/null, and 2>&1 only joins two outputs.
104
+ if not (word and redirect == "<" or word == "/dev/null" and redirect in (">", ">>", "&>", "&>>") or word in ("1", "2") and redirect == ">&"):
105
+ return False
106
+ redirect = None
107
+ elif word:
108
+ # A comment can hold a quote, which would hide the line after it.
109
+ if word.startswith("#") or not line and word not in READING | {"git", "sed"}:
110
+ return False
111
+ line += shlex.split(word)
112
+ elif set(mark) & set("()<>"):
113
+ redirect = mark
114
+ else:
115
+ lines.append(line)
116
+ line = []
117
+ lines = [one for one in [*lines, line] if one]
118
+ return bool(lines) and not redirect and all(map(harmless, lines))
119
+
120
+
121
+ def harmless(words):
122
+ """Whether one listed command changes no file: none of its options writes one or runs another program."""
123
+ name, *rest = words
124
+ if name == "sed": # only to print lines by their numbers
125
+ return len(rest) > 1 and rest[0] == "-n" and bool(re.fullmatch(r"[\d$,;p]+", rest[1])) and not any(one.startswith("-") or UNCLEAR.match(one) for one in rest[2:])
126
+ if name == "printf": # -v sets a variable, such as the one that says where programs are
127
+ return not rest or not (rest[0].startswith("-v") or UNCLEAR.match(rest[0]))
128
+ if name not in ("git", "rg"):
129
+ return True
130
+ if any(map(UNCLEAR.match, rest)):
131
+ return False
132
+ options = [one.split("=")[0] for one in rest]
133
+ if name == "rg":
134
+ return not {"--pre", "--hostname-bin"} & set(options)
135
+ while rest and rest[0] in ("--no-pager", "-P", "-C"):
136
+ rest = rest[2 if rest[0] == "-C" else 1:]
137
+ return bool(rest) and rest[0] in GIT and not any(re.match("-[^-]*O", one) or len(one) > 2 and any(writing.startswith(one) for writing in WRITING) for one in options)
138
+
139
+
66
140
  def edited(outcome):
67
141
  """The lines an edit added and removed, as two sets of fingerprints, from what the log says of the edit. A file
68
142
  that was created has no patch: all of its lines were added."""
@@ -222,7 +296,7 @@ def session(task, paths):
222
296
  for block in blocks:
223
297
  if block.get("type") != "tool_result" or block.get("tool_use_id") not in calls:
224
298
  continue
225
- tool, committing, target, background = calls.pop(block["tool_use_id"])
299
+ tool, committing, target, background, unchanged = calls.pop(block["tool_use_id"])
226
300
  failed = bool(block.get("is_error"))
227
301
  if not failed and (background or outcome.get("backgroundTaskId")):
228
302
  # The command went to the background, by the agent's wish or after waiting too long. This line only
@@ -241,7 +315,7 @@ def session(task, paths):
241
315
  # Fingerprints only: enough to tell whether a line is still there, and not enough to read it.
242
316
  lines = {"files": [target], **({"added": {target: sorted(added)}} if added else {}), **({"removed": {target: sorted(removed)}} if removed else {})}
243
317
  yield event("call_end", at, id=block["tool_use_id"], failed=failed,
244
- wrote=True if changed else False if tool in READERS else None, **({"exit": 1} if nothing else {}), **lines)
318
+ wrote=True if changed else False if unchanged else None, **({"exit": 1} if nothing else {}), **lines)
245
319
  if opening(entry) is not None:
246
320
  person = by_person(entry)
247
321
  if person:
@@ -263,13 +337,15 @@ def session(task, paths):
263
337
  inputs = block["input"] if isinstance(block.get("input"), dict) else {}
264
338
  command = str(inputs.get("command") or "")
265
339
  if block.get("name") == "Bash":
266
- name = program(command)
267
- calls[block["id"]] = ("Bash", name == "git" and " commit" in command, None, bool(inputs.get("run_in_background")))
268
- yield event("call_start", at, id=block["id"], type="command", name=name, check=bool(CHECK.search(command)))
340
+ name, harmless_line = program(command), changes_nothing(command)
341
+ calls[block["id"]] = ("Bash", name == "git" and " commit" in command, None, bool(inputs.get("run_in_background")), harmless_line)
342
+ # Such a line can name a test tool, as a search or a commit's message does, and runs no test.
343
+ yield event("call_start", at, id=block["id"], type="command", name=name, check=bool(CHECK.search(command)) and not harmless_line)
269
344
  else:
270
345
  # The path a writing tool was given stays in the events on this machine; no report copies it.
271
- calls[block["id"]] = (block.get("name"), False, inputs.get("file_path") if isinstance(inputs.get("file_path"), str) else None, False)
272
- yield event("call_start", at, id=block["id"], type="tool", name=str(block.get("name")).split("__")[-1])
346
+ name = block.get("name")
347
+ calls[block["id"]] = (name, False, inputs.get("file_path") if isinstance(inputs.get("file_path"), str) else None, False, name in READERS)
348
+ yield event("call_start", at, id=block["id"], type="subagent" if name in AGENTS else "tool", name=str(name).split("__")[-1])
273
349
  usage = message.get("usage")
274
350
  if isinstance(usage, dict) and message.get("id") not in counted: # one message can span several lines
275
351
  counted.add(message.get("id"))
@@ -91,22 +91,27 @@ def is_check(start):
91
91
 
92
92
 
93
93
  def check(events, result, counts=None):
94
- """Checked at the end: did a build or a test pass after the last call that could write?
94
+ """Checked at the end: did a build or a test pass after the last call that could write? Where a call that may have
95
+ written comes after the last check, nobody knows whether the check saw the work as it was left.
95
96
  `events` are those of the result's task. `counts` says of a file whether it is part of the work: a call that names
96
97
  its files and wrote none of the work, only a note beside it, is not the last write."""
97
98
  earlier = [event for event in events if event["at"] <= result["at"]]
98
99
  ends = {event["id"]: event for event in earlier if event["kind"] == "call_end"}
99
100
  calls = [(start, ends[start["id"]]) for start in earlier if start["kind"] == "call_start" and start["id"] in ends]
100
101
  # A test run writes caches of its own, so only the other calls say when the work was last written.
101
- work = [end for start, end in calls if not is_check(start)]
102
- if work and all(end.get("wrote") is None for end in work):
102
+ work = [(start, end) for start, end in calls if not is_check(start)]
103
+ if work and all(end.get("wrote") is None for _, end in work):
103
104
  return "not known" # no call says whether it wrote, so the last write cannot be placed
104
- writes = [end["at"] for end in work if end.get("wrote") and (counts is None or not end.get("files") or any(map(counts, end["files"])))]
105
+ writes = [end["at"] for _, end in work if end.get("wrote") and (counts is None or not end.get("files") or any(map(counts, end["files"])))]
106
+ # Where nothing says whether a call wrote, a command or a subagent may have. A tool did not: the ones that write say so.
107
+ unsure = [end["at"] for start, end in work if end.get("wrote") is None and start.get("type") != "tool"]
105
108
  checks = [(start, end) for start, end in calls if is_check(start) and (not writes or start["at"] >= max(writes))]
106
109
  if not checks:
107
110
  return "none ran"
108
- last = max(checks, key=lambda call: call[1]["at"])[1]
109
- return "failed" if last.get("failed") else "passed"
111
+ start, end = max(checks, key=lambda call: call[1]["at"])
112
+ if any(at > start["at"] for at in unsure):
113
+ return "not known"
114
+ return "failed" if end.get("failed") else "passed"
110
115
 
111
116
 
112
117
  def follow_up(events, result):
@@ -348,11 +353,10 @@ def results(events, repo=None, main=None):
348
353
  seen.add(task)
349
354
  own, before = list(group), None
350
355
  for result in own:
351
- if result["kind"] != "result":
356
+ # A report that the work is not ready ends nothing: the work goes on, and is a part of what is ready later.
357
+ if result["kind"] != "result" or not result.get("ready"):
352
358
  continue
353
359
  since, before = before, result["at"]
354
- if not result.get("ready"):
355
- continue
356
360
  folder = result.get("repo") or repo # a result may name the folder it was asked in
357
361
  commit = result.get("commit")
358
362
  files, lines = written(own, since, result["at"]), lines_of(own, since, result["at"])
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "agent-test-kit"
3
- version = "0.0.1"
3
+ version = "0.0.2"
4
4
  description = "An agent test kit: test coding agents on the work they really did"
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
File without changes
File without changes
File without changes