aws-case-drafter 0.1.0__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 (61) hide show
  1. aws_case_drafter-0.1.0/.gitignore +34 -0
  2. aws_case_drafter-0.1.0/.kiro/backlog.md +96 -0
  3. aws_case_drafter-0.1.0/.kiro/hooks/auto-build-whl.kiro.hook +14 -0
  4. aws_case_drafter-0.1.0/.kiro/hooks/auto-git-commit.kiro.hook +13 -0
  5. aws_case_drafter-0.1.0/.kiro/settings/mcp.json +15 -0
  6. aws_case_drafter-0.1.0/.kiro/specs/mvp-mcp-tools/.config.kiro +1 -0
  7. aws_case_drafter-0.1.0/.kiro/specs/mvp-mcp-tools/design.md +961 -0
  8. aws_case_drafter-0.1.0/.kiro/specs/mvp-mcp-tools/requirements.md +281 -0
  9. aws_case_drafter-0.1.0/.kiro/specs/mvp-mcp-tools/tasks.md +331 -0
  10. aws_case_drafter-0.1.0/.kiro/steering/project-context.md +315 -0
  11. aws_case_drafter-0.1.0/PKG-INFO +16 -0
  12. aws_case_drafter-0.1.0/README.md +3 -0
  13. aws_case_drafter-0.1.0/demo/fixture-lambda/function.zip +0 -0
  14. aws_case_drafter-0.1.0/demo/fixture-lambda/index.js +23 -0
  15. aws_case_drafter-0.1.0/demo/index.html +707 -0
  16. aws_case_drafter-0.1.0/demo/scenario-B-test.md +113 -0
  17. aws_case_drafter-0.1.0/pyproject.toml +26 -0
  18. aws_case_drafter-0.1.0/restore-casedrafter-index.sh +33 -0
  19. aws_case_drafter-0.1.0/src/case_drafter/__init__.py +3 -0
  20. aws_case_drafter-0.1.0/src/case_drafter/attachments.py +124 -0
  21. aws_case_drafter-0.1.0/src/case_drafter/dedup.py +151 -0
  22. aws_case_drafter-0.1.0/src/case_drafter/log_offload.py +118 -0
  23. aws_case_drafter-0.1.0/src/case_drafter/logs.py +268 -0
  24. aws_case_drafter-0.1.0/src/case_drafter/redaction.py +131 -0
  25. aws_case_drafter-0.1.0/src/case_drafter/server.py +159 -0
  26. aws_case_drafter-0.1.0/src/case_drafter/templates/__init__.py +30 -0
  27. aws_case_drafter-0.1.0/src/case_drafter/templates/_common.py +40 -0
  28. aws_case_drafter-0.1.0/src/case_drafter/templates/apigw.py +174 -0
  29. aws_case_drafter-0.1.0/src/case_drafter/templates/general.py +69 -0
  30. aws_case_drafter-0.1.0/src/case_drafter/templates/lambda.py +169 -0
  31. aws_case_drafter-0.1.0/src/case_drafter/templates/resource.py +199 -0
  32. aws_case_drafter-0.1.0/src/case_drafter/tools/__init__.py +23 -0
  33. aws_case_drafter-0.1.0/src/case_drafter/tools/_shared.py +36 -0
  34. aws_case_drafter-0.1.0/src/case_drafter/tools/draft_case.py +367 -0
  35. aws_case_drafter-0.1.0/src/case_drafter/tools/fetch_apigw.py +500 -0
  36. aws_case_drafter-0.1.0/src/case_drafter/tools/fetch_lambda.py +401 -0
  37. aws_case_drafter-0.1.0/src/case_drafter/tools/submit_case.py +498 -0
  38. aws_case_drafter-0.1.0/src/case_drafter/validation.py +154 -0
  39. aws_case_drafter-0.1.0/tests/__init__.py +0 -0
  40. aws_case_drafter-0.1.0/tests/conftest.py +132 -0
  41. aws_case_drafter-0.1.0/tests/test_apigw_template.py +160 -0
  42. aws_case_drafter-0.1.0/tests/test_attachment_reference.py +82 -0
  43. aws_case_drafter-0.1.0/tests/test_attachments.py +106 -0
  44. aws_case_drafter-0.1.0/tests/test_case_lock.py +84 -0
  45. aws_case_drafter-0.1.0/tests/test_dedup.py +49 -0
  46. aws_case_drafter-0.1.0/tests/test_draft_gating.py +587 -0
  47. aws_case_drafter-0.1.0/tests/test_fetch_apigw.py +531 -0
  48. aws_case_drafter-0.1.0/tests/test_fetch_lambda_filter.py +131 -0
  49. aws_case_drafter-0.1.0/tests/test_general_template.py +47 -0
  50. aws_case_drafter-0.1.0/tests/test_lambda_template.py +140 -0
  51. aws_case_drafter-0.1.0/tests/test_log_offload.py +110 -0
  52. aws_case_drafter-0.1.0/tests/test_logs.py +319 -0
  53. aws_case_drafter-0.1.0/tests/test_redaction_props.py +223 -0
  54. aws_case_drafter-0.1.0/tests/test_resource_template.py +167 -0
  55. aws_case_drafter-0.1.0/tests/test_server.py +252 -0
  56. aws_case_drafter-0.1.0/tests/test_skeleton.py +57 -0
  57. aws_case_drafter-0.1.0/tests/test_submit_case.py +623 -0
  58. aws_case_drafter-0.1.0/tests/test_validation.py +161 -0
  59. aws_case_drafter-0.1.0/tests/test_validation_props.py +78 -0
  60. aws_case_drafter-0.1.0/try_it.py +210 -0
  61. aws_case_drafter-0.1.0/uv.lock +828 -0
@@ -0,0 +1,34 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ *.egg-info/
7
+ *.egg
8
+ dist/
9
+ build/
10
+
11
+ # Virtual environments
12
+ .venv/
13
+ venv/
14
+ ENV/
15
+
16
+ # Testing
17
+ .hypothesis/
18
+ .pytest_cache/
19
+ .coverage
20
+ htmlcov/
21
+
22
+ # IDE
23
+ .idea/
24
+ .vscode/
25
+ *.swp
26
+ *.swo
27
+
28
+ # OS
29
+ .DS_Store
30
+ Thumbs.db
31
+
32
+ # Environment variables
33
+ .env
34
+ .env.local
@@ -0,0 +1,96 @@
1
+ # Backlog(候选改进池)
2
+
3
+ 仓库级的未来改进候选池,跨 spec、未排期。条目要正式开工时,把它「毕业」成 `.kiro/specs/<feature>/` 下的独立 spec,再从这里移除或标记。
4
+
5
+ > 注:这里只记「想做什么 + 为什么 + 大致路径」,不是实现计划。MVP 范围内的已排期任务在各自 spec 的 `tasks.md`。
6
+
7
+ ---
8
+
9
+ ## Lambda 日志查询灵活化(非报错类问题)
10
+
11
+ - 问题:`fetch_lambda_context` 当前是「错误日志专用」——`fetch_lambda.py` 写死了一个错误关键字
12
+ filter pattern(`ERROR/Exception/Failed/timeout/Runtime.`),`logs.py` 又围绕「匹配到的错误行
13
+ → 按 RequestId 补全 START/END/REPORT 生命周期」组织。对**不报错的问题**抓不到相关日志:
14
+ - 不报错但行为异常(结果不对、走错分支、该触发没触发)
15
+ - 性能/冷启动(只想看 REPORT 行的 Duration/Init Duration,没有 ERROR 关键字)
16
+ - 特定业务标识(订单号/下游服务名如 DynamoDB,想按它捞)
17
+ - 特定时间点(事故发生在过去某个具体时刻,而非「最近 N 小时」)
18
+ - 思路:把日志查询的部分控制权交给模型,但**不暴露 CloudWatch 原生 filter 语法**(大小写敏感、
19
+ `?"..."` OR 语法,弱模型必写错),改成几个直观可选参数,服务端翻译成正确 pattern。
20
+ - 建议参数(全部可选、向后兼容,不填即现状):
21
+ - `keyword: str | None = None` —— 简单关键字,非空时围绕它构建匹配(服务端处理大小写变体),
22
+ 取代默认错误过滤。
23
+ - `latest_stream_only: bool = False` —— True 时跳过错误过滤,直接拉**最新 log stream 的全部日志**
24
+ (「不报错、想看函数到底在干嘛」的场景)。
25
+ - `end_time: str | None = None`(ISO8601)—— 时间窗变成 `[end_time - window, end_time]`,
26
+ 处理过去某时刻的事故;不填默认 now(即现状)。优先级:可后置,先上前两个也够用。
27
+ - 优先级:`latest_stream_only` > `keyword` > 默认错误过滤。
28
+ - 注意点:
29
+ - 关键字/最新流模式**不能套用 RequestId 生命周期补全**(那是为错误行设计的),走「原样返回」
30
+ 路径(类似现有 `with_context=False`)。
31
+ - `latest_stream_only` 需先 `describe_log_streams` 拿最新 stream,再 `get_log_events`,
32
+ 和现有 `filter_log_events` 路径不同,需在 `logs.py` 加新查询函数。
33
+ - redaction、50k 截断、`hints.instructions`(「不要分析总结日志」)原样保留。
34
+ - 影响:`fetch_lambda.py`、`logs.py`、`validation.py`(新参数校验)+ 测试。medium effort。
35
+
36
+ ---
37
+
38
+ ## Lazy credential re-check(凭证模式自愈)
39
+
40
+ - 问题:`credential_mode` 在启动时决定一次后冻结。启动时的瞬时失败(如慢 AssumeRole profile
41
+ 超时)会把 server 永久降级为 credentialless 直到重启,即便 AWS 已恢复。
42
+ - 修复:credentialless 模式下,若工具调用未显式带 `aws_profile`,在调用时尝试解析一次凭证;
43
+ 成功则升级为 credential 模式并缓存 session。
44
+ - 影响:`AppContext` 和 `fetch_lambda` 的 session 获取;medium effort。
45
+ - 现状缓解:已把 `_CREDENTIAL_TIMEOUT_SECONDS` 放宽到 15s。
46
+
47
+ ---
48
+
49
+ ## 超大文本内容转附件上传(日志 / 目录 / 配置)
50
+
51
+ - 目标:当要附加的信息过大(用户想贴大量日志/目录/多文件,或 fetch 工具抓到大段日志)时,
52
+ 自动检测并把内容打包压缩成附件上传,避免塞爆工单正文、也省去客户手动操作。
53
+ - 选这个角度(而非截图)的原因:这类内容是**工具本就持有的文本**,不存在截图那种「用户粘进
54
+ 聊天框的字节进不了 MCP 工具调用」的死结,实现路径直接、可控。截图方案因字节传递难题暂搁置。
55
+ - 检测机制(核心):
56
+ - 设阈值(如正文超过 N KB / 日志行数超过 M / 多个文件),触发「转附件」决策。
57
+ - 正文里保留**关键摘要 + 代表性片段**(含 RequestId、INIT、REPORT、首末错误行),完整内容
58
+ 进附件,符合现有「日志要有上下文」原则,避免正文被淹没。
59
+ - 压缩:多文件/目录 → zip;单个大日志 → gzip 或直接 .txt(视 5MB 限制)。
60
+ - API path:`add_attachments_to_set` → `attachmentSetId` → `create_case(attachmentSetId=...)`
61
+ 或 `add_communication_to_case(attachmentSetId=...)`。
62
+ - Support API 限制:单集最多 3 个附件、单个 ≤5MB、attachment set 创建后 1 小时过期;需 Business+
63
+ Support Plan。aws-cn 同样支持(端点仍为 `support.cn-north-1`)。超 5MB 需切分/进一步压缩;
64
+ 超 3 个需合并打包。
65
+ - 安全:附件内容同样要过现有 `redaction` 脱敏后再压缩上传。
66
+ - 设计建议:在 `draft_support_case` 阶段就标记「内容过大、建议转附件」,`submit_support_case`
67
+ 增加可选 `attachments` 参数(内容/路径列表),内部走 attachment set 流程。
68
+ - 优先级:比截图方案更实际、价值更高。medium effort。
69
+
70
+ ---
71
+
72
+ ## fetch → draft 上下文服务端中转(不依赖模型转发)
73
+
74
+ - 问题:fetch_* 的真实输出靠模型手动塞进 `draft_support_case` 的 `collected_context` 参数转发,
75
+ 弱模型(DeepSeek/千问,Cherry Studio 实测)不稳定,会重写/改名/丢字段/凭空编造:
76
+ - 实测一次:fetch 把大量日志**转储为附件文件**返回,模型没看到日志内容,于是编了假的
77
+ `error_logs_sample`(时间戳都是错的),还把真实附件路径 `attachment_files`/`logs_file` 丢了。
78
+ - 后果:draft 生成的工单**既无内联日志、也无附件**,日志彻底丢失,正文只剩 `[请补充: 错误日志]` 占位符。
79
+ - 复现脚本:`demo/repro_draft.py`。注:模型不稳定,重跑有时正常,非必现。
80
+ - 根因:模型是 fetch→draft 之间传数据的薄弱环节,靠 prompt 要求「原样传入」对弱模型不可靠。
81
+ - 修复(服务端 registry 中转,沿用 attachments / case-lock 已有模式):
82
+ - 在 `dedup.py`(或 attachments.py)加一个 per-session **fetch-context registry**,按
83
+ `normalize_case_key(资源标识)` 存储 fetch 的真实输出。
84
+ - fetch_* 收集完后把真实 `data` 写入该 registry(不依赖模型)。
85
+ - `draft_support_case` 按 `incoming_key` 取回,**盖在模型传的 collected_context 之上**
86
+ (真实 error_logs / attachment_files / logs_file / function_arn 等覆盖模型编造的)。
87
+ - 清理:提交成功后在 `reset_case_state()` 一并清空。
88
+ - **累积语义(关键,处理多次 fetch)**:registry 按资源 key 存但**合并而非覆盖**——
89
+ 模型可能用不同 `time_window_hours`(如先查12点、再查5点)多次 fetch,参数不同 → dedup 不拦 → 各自产出一个日志文件:
90
+ - `attachment_files`:取并集(所有批次的日志文件都作为附件上传,一条不丢)
91
+ - `error_logs`(内联):合并 + 按 (timestamp, message) 去重;合并后若超阈值可考虑重新转储(锦上添花,可后置)
92
+ - `function_arn`/`region` 等标识:取最新非空
93
+ - 注:draft 锁定后 fetch 会短路(already_drafted),所以多次 fetch 只发生在收集阶段,累积才是正确语义。
94
+ - 影响:`dedup.py`(新 registry)、`fetch_lambda.py` / `fetch_apigw.py`(写入)、
95
+ `draft_case.py`(取回+覆盖)+ 测试。medium effort。
96
+ - 优先级:高。这是工单内容质量的核心可靠性问题,但 demo 阶段模型表现尚可,故排期到 demo 之后。
@@ -0,0 +1,14 @@
1
+ {
2
+ "enabled": true,
3
+ "name": "Auto Build Wheel",
4
+ "description": "每轮 Kiro 执行结束后构建一次 whl 包到 dist/(仅当 src/ 有改动时),避免单轮多次构建",
5
+ "version": "2",
6
+ "when": {
7
+ "type": "agentStop"
8
+ },
9
+ "then": {
10
+ "type": "runCommand",
11
+ "command": "cd /home/ec2-user/kiro/case-drafter && newest=$(ls -t dist/*.whl 2>/dev/null | head -1); if [ -z \"$newest\" ] || [ -n \"$(find src -name '*.py' -newer \"$newest\" 2>/dev/null)\" ]; then uv build; else echo 'skip build: src 无改动'; fi",
12
+ "timeout": 60
13
+ }
14
+ }
@@ -0,0 +1,13 @@
1
+ {
2
+ "enabled": true,
3
+ "name": "Auto Git Commit",
4
+ "description": "每次 Kiro 完成执行后,自动将所有变更 git commit(如果有变更的话)",
5
+ "version": "1",
6
+ "when": {
7
+ "type": "agentStop"
8
+ },
9
+ "then": {
10
+ "type": "runCommand",
11
+ "command": "cd /home/ec2-user/kiro/case-drafter && git add -A && git diff --cached --quiet || git commit -m \"auto: $(git diff --cached --stat | tail -1)\""
12
+ }
13
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "mcpServers": {
3
+ "aws-case-drafter": {
4
+ "command": "/home/ec2-user/kiro/case-drafter/.venv/bin/aws-case-drafter",
5
+ "env": {
6
+ "AWS_REGION": "cn-north-1"
7
+ },
8
+ "disabled": true,
9
+ "autoApprove": [
10
+ "fetch_lambda_context",
11
+ "draft_support_case"
12
+ ]
13
+ }
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ {"specId": "689e6757-998e-4b46-b746-e0c4ec399c7a", "workflowType": "requirements-first", "specType": "feature"}