trae-coding-engine 0.1.0

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 (57) hide show
  1. package/README.md +91 -0
  2. package/bin/coding-engine.js +16 -0
  3. package/lib/cli.js +86 -0
  4. package/lib/index.js +6 -0
  5. package/lib/setup.js +290 -0
  6. package/package.json +32 -0
  7. package/templates/.agents/skills/coding-architecture/SKILL.md +347 -0
  8. package/templates/.agents/skills/coding-code-review/SKILL.md +95 -0
  9. package/templates/.agents/skills/coding-cve-remediation/SKILL.md +163 -0
  10. package/templates/.agents/skills/coding-db-schema/SKILL.md +273 -0
  11. package/templates/.agents/skills/coding-deploy-config/SKILL.md +129 -0
  12. package/templates/.agents/skills/coding-docs-audit/SKILL.md +285 -0
  13. package/templates/.agents/skills/coding-docs-audit-autofix/SKILL.md +33 -0
  14. package/templates/.agents/skills/coding-http-api/SKILL.md +269 -0
  15. package/templates/.agents/skills/coding-issue-autodev/SKILL.md +172 -0
  16. package/templates/.agents/skills/coding-merge-request/SKILL.md +199 -0
  17. package/templates/.agents/skills/coding-observability/SKILL.md +193 -0
  18. package/templates/.agents/skills/coding-refactor-insight/SKILL.md +89 -0
  19. package/templates/.agents/skills/coding-release-merge/SKILL.md +224 -0
  20. package/templates/.agents/skills/coding-runtime-adapter/SKILL.md +115 -0
  21. package/templates/.agents/skills/coding-testing/SKILL.md +169 -0
  22. package/templates/AGENTS.md +179 -0
  23. package/templates/MR-Template-Default.md +33 -0
  24. package/templates/Makefile +370 -0
  25. package/templates/REGISTRY.md +53 -0
  26. package/templates/scripts/check-adr.sh +283 -0
  27. package/templates/scripts/check-comment-i18n.py +209 -0
  28. package/templates/scripts/check-comment-i18n.sh +38 -0
  29. package/templates/scripts/check-doc-refs.sh +40 -0
  30. package/templates/scripts/check-docs.sh +103 -0
  31. package/templates/scripts/check-go-names.sh +59 -0
  32. package/templates/scripts/check-iam-actions.py +126 -0
  33. package/templates/scripts/check-migration-sql-immutability.sh +232 -0
  34. package/templates/scripts/check-mr-desc.sh +165 -0
  35. package/templates/scripts/check-mr-size.sh +128 -0
  36. package/templates/scripts/check-mr-title.sh +123 -0
  37. package/templates/scripts/check-openapi.py +221 -0
  38. package/templates/scripts/check-rdb-structured-queries.sh +98 -0
  39. package/templates/scripts/check-repository-transactions.sh +100 -0
  40. package/templates/scripts/check-runbooks.sh +229 -0
  41. package/templates/scripts/check-skill-router-sync.py +331 -0
  42. package/templates/scripts/check-skills.sh +243 -0
  43. package/templates/scripts/docs-audit-to-issues.py +373 -0
  44. package/templates/scripts/docs-verification-reminder.sh +63 -0
  45. package/templates/scripts/find-ci-failures.sh +133 -0
  46. package/templates/scripts/find-stale-mrs.sh +72 -0
  47. package/templates/scripts/gen-adr-index.sh +122 -0
  48. package/templates/scripts/open-mr.sh +536 -0
  49. package/templates/scripts/regen-agent-md.sh +149 -0
  50. package/templates/scripts/run-mr-hygiene.sh +140 -0
  51. package/templates/scripts/runbook.sh +91 -0
  52. package/templates/scripts/self-maintenance-digest.py +125 -0
  53. package/templates/scripts/send-self-maintenance-lark-card.py +116 -0
  54. package/templates/scripts/skill-graph.sh +114 -0
  55. package/templates/scripts/skill-impact.sh +134 -0
  56. package/templates/scripts/skill-propose.sh +302 -0
  57. package/templates/scripts/skill-router-hook.sh +152 -0
@@ -0,0 +1,133 @@
1
+ #!/usr/bin/env bash
2
+ # Find recent CI failures and file create-only [ci-failure] issues.
3
+ # Also emit a platform-health verdict (meta-circuit-breaker L1 seed).
4
+ set -euo pipefail
5
+ cd "$(dirname "$0")/.."
6
+
7
+ source scripts/lib/codebase-json.sh
8
+
9
+ # Built-in transient signatures — never escalated to issues on first sight.
10
+ # Source of truth lives HERE, not in any UI/external config (spec §3.1).
11
+ TRANSIENT_SIGNATURES=(
12
+ "job context marshal fail" # Bits control-plane transient (see memory: re-run, not a code fix)
13
+ )
14
+ [[ -n "${CI_TRANSIENT_EXTRA:-}" ]] && TRANSIENT_SIGNATURES+=("$CI_TRANSIENT_EXTRA")
15
+
16
+ CHECKS_JSON=""
17
+ HEALTH_OUT=""
18
+ DRY_RUN=0
19
+ REPO="${CODEBASE_REPO:-epscp/coding_engine}"
20
+ UNHEALTHY_THRESHOLD="${CI_UNHEALTHY_THRESHOLD:-3}"
21
+ # Which branch's CI to watch. Parameterized so a cron on a cherry-pick/hotfix
22
+ # branch (e.g. release-0.2.0) monitors ITS OWN CI, not the gated-green mainline.
23
+ # The pulse pipeline passes the running branch via CI_WATCH_BRANCH=${{Head.Branch}};
24
+ # --branch overrides. Empty or an unresolved pipeline expression falls back to
25
+ # release (see normalization below) so a misconfigured cron never watches "".
26
+ WATCH_BRANCH="${CI_WATCH_BRANCH:-release}"
27
+
28
+ while [[ $# -gt 0 ]]; do
29
+ case "$1" in
30
+ --checks-json) CHECKS_JSON="$2"; shift 2 ;;
31
+ --health-out) HEALTH_OUT="$2"; shift 2 ;;
32
+ --branch) WATCH_BRANCH="$2"; shift 2 ;;
33
+ --dry-run) DRY_RUN=1; shift ;;
34
+ *) echo "error: unknown argument: $1" >&2; exit 2 ;;
35
+ esac
36
+ done
37
+
38
+ # Defensive: a cron that interpolates an undefined pipeline variable yields an
39
+ # empty string or a literal "${{...}}". Never query that — fall back to release.
40
+ if [[ -z "$WATCH_BRANCH" || "$WATCH_BRANCH" == *'{{'* ]]; then
41
+ echo "[find-ci-failures] WARN: watch branch unresolved ('$WATCH_BRANCH'); falling back to release" >&2
42
+ WATCH_BRANCH="release"
43
+ fi
44
+
45
+ codebase_json_require
46
+
47
+ # Test-injection seam: offline tests point this at a stub so the create-only
48
+ # issue call (and open-issue.sh's live dedup scan) never touches the network.
49
+ # Production default is the real script; a set-but-missing override is an error,
50
+ # not a silent fallback.
51
+ OPEN_ISSUE_CMD="${OPEN_ISSUE_TEST_OVERRIDE:-scripts/open-issue.sh}"
52
+ if [[ -n "${OPEN_ISSUE_TEST_OVERRIDE:-}" && ! -x "$OPEN_ISSUE_TEST_OVERRIDE" ]]; then
53
+ echo "error: OPEN_ISSUE_TEST_OVERRIDE set but not executable: $OPEN_ISSUE_TEST_OVERRIDE" >&2
54
+ exit 2
55
+ fi
56
+
57
+ get_checks() {
58
+ if [[ -n "$CHECKS_JSON" ]]; then
59
+ cat "$CHECKS_JSON"
60
+ else
61
+ bytedcli --json codebase checks list -R "$REPO" --branch "$WATCH_BRANCH"
62
+ fi
63
+ }
64
+
65
+ echo "[find-ci-failures] watching repo=$REPO branch=$WATCH_BRANCH"
66
+
67
+ is_transient() {
68
+ local name="$1"
69
+ for t in "${TRANSIENT_SIGNATURES[@]}"; do
70
+ [[ "$name" == *"$t"* ]] && return 0
71
+ done
72
+ return 1
73
+ }
74
+
75
+ # Fetch + parse CI checks. Distinguish a genuine "no failures this tick" (verdict
76
+ # follows the count) from an inability to observe (fetch or parse failed) — in the
77
+ # latter case the verdict is `unknown`, NEVER `healthy`: a fail-noisy meta-probe must
78
+ # not report green when it could not look. Do not let `|| true` mask the failure.
79
+ observe_ok=1
80
+ checks_raw=$(get_checks) || observe_ok=0
81
+ fail_lines=""
82
+ if [[ "$observe_ok" -eq 1 ]]; then
83
+ fail_lines=$(printf '%s' "$checks_raw" | codebase_json_ci_failure_signatures) || observe_ok=0
84
+ fi
85
+ fail_count=0
86
+ filed_count=0
87
+
88
+ while IFS=$'\t' read -r sig name conclusion; do
89
+ [[ -z "$sig" ]] && continue
90
+ fail_count=$((fail_count + 1))
91
+ if is_transient "$name"; then
92
+ echo "[find-ci-failures] skipping transient: $name"
93
+ continue
94
+ fi
95
+ filed_count=$((filed_count + 1))
96
+ body_file=$(mktemp)
97
+ {
98
+ printf 'CI check `%s` failed (conclusion: %s).\n\n' "$name" "$conclusion"
99
+ printf '<!-- severity:Minor -->\n'
100
+ printf '<!-- evidence:ci/%s -->\n' "$sig"
101
+ } > "$body_file"
102
+ cmd=("$OPEN_ISSUE_CMD"
103
+ --title "[ci-failure] ${name}"
104
+ --status todo
105
+ --dedup-key "ci-failure:${sig}"
106
+ --body-file "$body_file")
107
+ [[ "$DRY_RUN" -eq 1 ]] && cmd+=(--dry-run)
108
+ echo "[find-ci-failures] ${cmd[*]}"
109
+ "${cmd[@]}" || echo "[find-ci-failures] open-issue failed for ${name}" >&2
110
+ rm -f "$body_file"
111
+ done <<< "$fail_lines"
112
+
113
+ # Platform-health verdict: recomputed every tick, never sticky.
114
+ # L1 health gates on NON-TRANSIENT failures only ($filed_count) — built-in
115
+ # transient signatures are control-plane noise and must never be the vote that
116
+ # flips the verdict to unhealthy. It is a crude fixed-count gate
117
+ # (>= CI_UNHEALTHY_THRESHOLD this tick); a failure-rate denominator refinement is
118
+ # deferred to L2 (do not over-build).
119
+ if [[ "$observe_ok" -eq 0 ]]; then
120
+ echo "[find-ci-failures] WARN: could not fetch/parse CI checks; reporting health=unknown" >&2
121
+ verdict="unknown"
122
+ elif [[ "$filed_count" -ge "$UNHEALTHY_THRESHOLD" ]]; then
123
+ verdict="unhealthy"
124
+ else
125
+ verdict="healthy"
126
+ fi
127
+ echo "[find-ci-failures] failures=$fail_count filed=$filed_count health=$verdict"
128
+ # Use an if-block, not `[[ ... ]] && printf`: as the final statement the latter
129
+ # would exit 1 whenever --health-out is omitted (the test is false), spuriously
130
+ # tripping the caller's `|| echo "...soft-failed"`. The if-block exits 0.
131
+ if [[ -n "$HEALTH_OUT" ]]; then
132
+ printf '%s\n' "$verdict" > "$HEALTH_OUT"
133
+ fi
@@ -0,0 +1,72 @@
1
+ #!/usr/bin/env bash
2
+ # Find stale open MRs and file create-only [stale-mr] issues.
3
+ # Read-only discovery (L1+): issues are the only write, via open-issue.sh.
4
+ set -euo pipefail
5
+ cd "$(dirname "$0")/.."
6
+
7
+ source scripts/lib/codebase-json.sh
8
+
9
+ MR_JSON="" # test injection: read MR list JSON from a file instead of CLI
10
+ DRY_RUN=0
11
+ MINOR_DAYS=14
12
+ MAJOR_DAYS=30
13
+ REPO="${CODEBASE_REPO:-epscp/coding_engine}"
14
+
15
+ while [[ $# -gt 0 ]]; do
16
+ case "$1" in
17
+ --mr-json) MR_JSON="$2"; shift 2 ;;
18
+ --dry-run) DRY_RUN=1; shift ;;
19
+ --minor-days) MINOR_DAYS="$2"; shift 2 ;;
20
+ --major-days) MAJOR_DAYS="$2"; shift 2 ;;
21
+ *) echo "error: unknown argument: $1" >&2; exit 2 ;;
22
+ esac
23
+ done
24
+
25
+ codebase_json_require
26
+ now="${STALE_MR_NOW_EPOCH:-$(date +%s)}"
27
+
28
+ # Test-injection seam: offline tests point this at a stub so the create-only
29
+ # issue call (and open-issue.sh's live dedup scan) never touches the network.
30
+ # Production default is the real script; a set-but-missing override is an error,
31
+ # not a silent fallback.
32
+ OPEN_ISSUE_CMD="${OPEN_ISSUE_TEST_OVERRIDE:-scripts/open-issue.sh}"
33
+ if [[ -n "${OPEN_ISSUE_TEST_OVERRIDE:-}" && ! -x "$OPEN_ISSUE_TEST_OVERRIDE" ]]; then
34
+ echo "error: OPEN_ISSUE_TEST_OVERRIDE set but not executable: $OPEN_ISSUE_TEST_OVERRIDE" >&2
35
+ exit 2
36
+ fi
37
+
38
+ get_mr_list() {
39
+ if [[ -n "$MR_JSON" ]]; then
40
+ cat "$MR_JSON"
41
+ else
42
+ bytedcli --json codebase mr list -R "$REPO" --state open --limit 100
43
+ fi
44
+ }
45
+
46
+ mr_lines=$(get_mr_list | codebase_json_mr_stale_lines "$now" "$MINOR_DAYS" "$MAJOR_DAYS")
47
+
48
+ if [[ -z "$mr_lines" ]]; then
49
+ echo "[find-stale-mrs] no stale MRs"
50
+ exit 0
51
+ fi
52
+
53
+ while IFS=$'\t' read -r number days severity; do
54
+ [[ -z "$number" ]] && continue
55
+ body_file=$(mktemp)
56
+ {
57
+ printf 'MR #%s has had no activity for %s days.\n\n' "$number" "$days"
58
+ printf 'Review, rebase, or close it.\n\n'
59
+ printf '<!-- severity:%s -->\n' "$severity"
60
+ printf '<!-- evidence:mr/%s -->\n' "$number"
61
+ } > "$body_file"
62
+
63
+ cmd=("$OPEN_ISSUE_CMD"
64
+ --title "[stale-mr] MR #${number} idle ${days}d"
65
+ --status todo
66
+ --dedup-key "stale-mr:${number}"
67
+ --body-file "$body_file")
68
+ [[ "$DRY_RUN" -eq 1 ]] && cmd+=(--dry-run)
69
+ echo "[find-stale-mrs] ${cmd[*]}"
70
+ "${cmd[@]}" || echo "[find-stale-mrs] open-issue failed for MR #${number}" >&2
71
+ rm -f "$body_file"
72
+ done <<< "$mr_lines"
@@ -0,0 +1,122 @@
1
+ #!/usr/bin/env bash
2
+ # Generate docs/adr/INDEX.md from each ADR's **Topic**/**Status**/**Date**
3
+ # metafields. The whole file is derived — never hand-edited. Mirrors the
4
+ # regen-agent-md pattern, but whole-file (not marker-block) because there is no
5
+ # hand-written content to preserve.
6
+ #
7
+ # Usage:
8
+ # gen-adr-index.sh rewrite $INDEX_OUT (default docs/adr/INDEX.md)
9
+ # gen-adr-index.sh --check print nothing on sync; diff + exit 1 if stale
10
+ set -euo pipefail
11
+ cd "$(dirname "$0")/.."
12
+
13
+ # shellcheck source=scripts/lib/adr-meta.sh
14
+ . scripts/lib/adr-meta.sh
15
+
16
+ INDEX_OUT="${INDEX_OUT:-docs/adr/INDEX.md}"
17
+
18
+ mode="write"
19
+ case "${1:-}" in
20
+ "") ;;
21
+ --check) mode="check" ;;
22
+ -h|--help) echo "Usage: $0 [--check]"; exit 0 ;;
23
+ *) echo "error: unknown flag: $1" >&2; exit 2 ;;
24
+ esac
25
+
26
+ # Section order is the $ADR_TOPICS order (defined once in scripts/lib/adr-meta.sh,
27
+ # sourced above); unknown topics sort last. Sharing the list with check-adr.sh
28
+ # guarantees the validated set and the rendered set never drift.
29
+
30
+ render() {
31
+ echo '<!-- AUTO-GENERATED by `make regen-adr-index`; DO NOT EDIT. Source of truth: each ADR'\''s **Topic**/**Status** metafields. -->'
32
+ echo
33
+ echo '# ADR Index'
34
+ echo
35
+ echo 'Generated from `docs/adr/*.md`. Regenerate with `make regen-adr-index`.'
36
+ echo
37
+
38
+ # --- By-topic sections ---
39
+ echo '## By topic'
40
+ echo
41
+ local topic f num title st date
42
+ for topic in $ADR_TOPICS __unknown__; do
43
+ local rows=""
44
+ while IFS= read -r f; do
45
+ [ -z "$f" ] && continue
46
+ local t; t="$(adr_field "$f" Topic)"
47
+ [ -z "$t" ] && t="__unknown__"
48
+ [ "$t" = "$topic" ] || continue
49
+ num="$(adr_num "$f")"
50
+ title="$(awk 'NR==1{sub(/^#[[:space:]]*[0-9]+[[:space:]]*-[[:space:]]*/,"");print;exit}' "$f")"
51
+ st="$(adr_field "$f" Status)"
52
+ date="$(adr_field "$f" Date)"
53
+ rows+="| ${num} | ${title} | ${st} | ${date} |"$'\n'
54
+ done < <(adr_files)
55
+ [ -z "$rows" ] && continue
56
+ [ "$topic" = "__unknown__" ] && echo "## (no topic)" || echo "## ${topic}"
57
+ echo
58
+ echo '| ADR | Title | Status | Date |'
59
+ echo '|---|---|---|---|'
60
+ printf '%s' "$rows"
61
+ echo
62
+ done
63
+
64
+ # --- Supersede graph ---
65
+ echo '## Supersede graph'
66
+ echo
67
+ local edges=""
68
+ while IFS= read -r f; do
69
+ [ -z "$f" ] && continue
70
+ local tgt; tgt="$(adr_supersede_target "$f")"
71
+ [ -z "$tgt" ] && continue
72
+ edges+="- $(adr_num "$f") → ${tgt}"$'\n'
73
+ done < <(adr_files)
74
+ if [ -n "$edges" ]; then printf '%s\n' "$edges"; else echo '_None._'; echo; fi
75
+
76
+ # --- Lifecycle rollup ---
77
+ echo '## Lifecycle rollup'
78
+ echo
79
+ local accepted=0 deprecated=0 superseded=0 other=0
80
+ while IFS= read -r f; do
81
+ [ -z "$f" ] && continue
82
+ local s; s="$(adr_field "$f" Status)"
83
+ case "$s" in
84
+ Accepted) accepted=$((accepted+1)) ;;
85
+ Deprecated) deprecated=$((deprecated+1)) ;;
86
+ "Superseded by "*) superseded=$((superseded+1)) ;;
87
+ *) other=$((other+1)) ;;
88
+ esac
89
+ done < <(adr_files)
90
+ echo "| Status | Count |"
91
+ echo "|---|---|"
92
+ echo "| Accepted | ${accepted} |"
93
+ echo "| Deprecated | ${deprecated} |"
94
+ echo "| Superseded | ${superseded} |"
95
+ [ "$other" -gt 0 ] && echo "| Other | ${other} |"
96
+ echo
97
+ echo '### Graveyard (Deprecated / Superseded)'
98
+ echo
99
+ while IFS= read -r f; do
100
+ [ -z "$f" ] && continue
101
+ local s; s="$(adr_field "$f" Status)"
102
+ case "$s" in
103
+ Deprecated|"Superseded by "*)
104
+ echo "- $(adr_num "$f") — $(awk 'NR==1{sub(/^#[[:space:]]*[0-9]+[[:space:]]*-[[:space:]]*/,"");print;exit}' "$f") (${s})" ;;
105
+ esac
106
+ done < <(adr_files)
107
+ }
108
+
109
+ if [ "$mode" = "check" ]; then
110
+ diff_tmp="$(mktemp)"
111
+ if ! diff -u "$INDEX_OUT" <(render) >"$diff_tmp" 2>&1; then
112
+ echo " [VIOLATION] $INDEX_OUT is out of sync. Run: make regen-adr-index" >&2
113
+ cat "$diff_tmp" >&2
114
+ rm -f "$diff_tmp"
115
+ exit 1
116
+ fi
117
+ rm -f "$diff_tmp"
118
+ echo " [OK] $INDEX_OUT in sync"
119
+ else
120
+ render > "$INDEX_OUT"
121
+ echo " [OK] wrote $INDEX_OUT"
122
+ fi