@aigis-ai/cli 2.0.1 → 2.0.2
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.
- package/README.md +58 -188
- package/aigis-ai-cli-2.0.1.tgz +0 -0
- package/package.json +1 -1
- package/cli-python/LICENSE +0 -21
- package/cli-python/README.md +0 -32
- package/cli-python/aigis_cli/SKILL.md +0 -70
- package/cli-python/aigis_cli/__init__.py +0 -3
- package/cli-python/aigis_cli/__pycache__/__init__.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/annotate.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/build.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/checksum.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/classify.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/cli.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/fetch.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/init_ide.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/keywords.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/__pycache__/search.cpython-313.pyc +0 -0
- package/cli-python/aigis_cli/annotate.py +0 -45
- package/cli-python/aigis_cli/auto_verify.py +0 -518
- package/cli-python/aigis_cli/build.py +0 -470
- package/cli-python/aigis_cli/checksum.py +0 -22
- package/cli-python/aigis_cli/classify.py +0 -192
- package/cli-python/aigis_cli/cli.py +0 -618
- package/cli-python/aigis_cli/content/index/audit-scan.md +0 -217
- package/cli-python/aigis_cli/content/index/auto-verify-rules.json +0 -439
- package/cli-python/aigis_cli/content/index/context-rules.json +0 -90
- package/cli-python/aigis_cli/content/index/frameworks.md +0 -82
- package/cli-python/aigis_cli/content/index/guardrails.json +0 -23
- package/cli-python/aigis_cli/content/index/taxonomy.md +0 -81
- package/cli-python/aigis_cli/content/resolvers/triggers.json +0 -229
- package/cli-python/aigis_cli/content/skills/areas/audit-logging.md +0 -176
- package/cli-python/aigis_cli/content/skills/areas/bias-monitoring.md +0 -172
- package/cli-python/aigis_cli/content/skills/areas/confidence-scoring.md +0 -180
- package/cli-python/aigis_cli/content/skills/areas/data-integrity.md +0 -257
- package/cli-python/aigis_cli/content/skills/areas/explainability.md +0 -174
- package/cli-python/aigis_cli/content/skills/areas/fallback-patterns.md +0 -200
- package/cli-python/aigis_cli/content/skills/areas/human-oversight.md +0 -220
- package/cli-python/aigis_cli/content/skills/areas/input-validation.md +0 -380
- package/cli-python/aigis_cli/content/skills/areas/monitoring.md +0 -207
- package/cli-python/aigis_cli/content/skills/areas/output-sanitization.md +0 -183
- package/cli-python/aigis_cli/content/skills/areas/pii-handling.md +0 -189
- package/cli-python/aigis_cli/content/skills/areas/prompt-security.md +0 -153
- package/cli-python/aigis_cli/content/skills/areas/rag-security.md +0 -230
- package/cli-python/aigis_cli/content/skills/areas/rate-limiting.md +0 -246
- package/cli-python/aigis_cli/content/skills/areas/supply-chain.md +0 -193
- package/cli-python/aigis_cli/content/skills/core.md +0 -62
- package/cli-python/aigis_cli/content/skills/infrastructure/logging.md +0 -202
- package/cli-python/aigis_cli/content/skills/infrastructure/rate-limiting.md +0 -169
- package/cli-python/aigis_cli/content/skills/infrastructure/secrets.md +0 -167
- package/cli-python/aigis_cli/content/skills/workflows/fastapi-llm.md +0 -86
- package/cli-python/aigis_cli/content/templates/ai-impact-assessment.md +0 -54
- package/cli-python/aigis_cli/content/templates/intended-purpose-doc.md +0 -39
- package/cli-python/aigis_cli/content/templates/risk-characterization.md +0 -34
- package/cli-python/aigis_cli/content/templates/third-party-assessment.md +0 -41
- package/cli-python/aigis_cli/content/verify/checklist-audit-logging.md +0 -13
- package/cli-python/aigis_cli/content/verify/checklist-bias-monitoring.md +0 -13
- package/cli-python/aigis_cli/content/verify/checklist-confidence-scoring.md +0 -13
- package/cli-python/aigis_cli/content/verify/checklist-data-integrity.md +0 -12
- package/cli-python/aigis_cli/content/verify/checklist-explainability.md +0 -13
- package/cli-python/aigis_cli/content/verify/checklist-fallback-patterns.md +0 -13
- package/cli-python/aigis_cli/content/verify/checklist-human-oversight.md +0 -14
- package/cli-python/aigis_cli/content/verify/checklist-input-validation.md +0 -16
- package/cli-python/aigis_cli/content/verify/checklist-monitoring.md +0 -13
- package/cli-python/aigis_cli/content/verify/checklist-output-sanitization.md +0 -14
- package/cli-python/aigis_cli/content/verify/checklist-pii-handling.md +0 -14
- package/cli-python/aigis_cli/content/verify/checklist-prompt-security.md +0 -13
- package/cli-python/aigis_cli/content/verify/checklist-rag-security.md +0 -12
- package/cli-python/aigis_cli/content/verify/checklist-rate-limiting.md +0 -13
- package/cli-python/aigis_cli/content/verify/checklist-supply-chain.md +0 -13
- package/cli-python/aigis_cli/fetch.py +0 -232
- package/cli-python/aigis_cli/init_ide.py +0 -159
- package/cli-python/aigis_cli/keywords.py +0 -73
- package/cli-python/aigis_cli/search.py +0 -69
- package/cli-python/aigis_cli.egg-info/PKG-INFO +0 -59
- package/cli-python/aigis_cli.egg-info/SOURCES.txt +0 -56
- package/cli-python/aigis_cli.egg-info/dependency_links.txt +0 -1
- package/cli-python/aigis_cli.egg-info/entry_points.txt +0 -2
- package/cli-python/aigis_cli.egg-info/requires.txt +0 -6
- package/cli-python/aigis_cli.egg-info/top_level.txt +0 -1
- package/cli-python/dist/aigis_cli-1.0.3-py3-none-any.whl +0 -0
- package/cli-python/dist/aigis_cli-1.0.3.tar.gz +0 -0
- package/cli-python/pyproject.toml +0 -49
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
"""Mirror of lib/build.js — `aigis build "<description>"` (Step 8).
|
|
2
|
-
|
|
3
|
-
Pure functions. CLI wrapper in cli.py handles the interactive prompt loop,
|
|
4
|
-
--confirm/--reject flags, TTY detection, and stdout. See lib/build.js for the
|
|
5
|
-
canonical design notes — this file mirrors it line-for-line in behavior.
|
|
6
|
-
|
|
7
|
-
Modes:
|
|
8
|
-
- auto (default): try buildFull at AUTO_FULL_CAP; on overflow, fall back
|
|
9
|
-
to compact with a warning the CLI surfaces on stderr.
|
|
10
|
-
- full : buildFull at FULL_HARD_CAP. Raises BriefTooLargeError.
|
|
11
|
-
- compact : buildCompact, no cap concern.
|
|
12
|
-
"""
|
|
13
|
-
|
|
14
|
-
from __future__ import annotations
|
|
15
|
-
|
|
16
|
-
import json
|
|
17
|
-
import re
|
|
18
|
-
from pathlib import Path
|
|
19
|
-
from datetime import datetime, timezone
|
|
20
|
-
|
|
21
|
-
import frontmatter
|
|
22
|
-
|
|
23
|
-
from .classify import classify
|
|
24
|
-
from .keywords import detect_traits_from_text
|
|
25
|
-
from .fetch import get_infra
|
|
26
|
-
|
|
27
|
-
CONTENT_DIR = Path(__file__).resolve().parent / "content"
|
|
28
|
-
|
|
29
|
-
AUTO_FULL_CAP = 120_000
|
|
30
|
-
FULL_HARD_CAP = 200_000
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class BriefTooLargeError(Exception):
|
|
34
|
-
def __init__(self, char_count: int, char_cap: int, areas: list[str]):
|
|
35
|
-
super().__init__(
|
|
36
|
-
f"Brief is {char_count} chars; cap is {char_cap}. Your description matched "
|
|
37
|
-
f"{len(areas)} area{'' if len(areas) == 1 else 's'} ({', '.join(areas)}). "
|
|
38
|
-
f"Try a more focused description, or split the build into per-domain runs. "
|
|
39
|
-
f'To see what would be included without rendering: aigis build "..." --list'
|
|
40
|
-
)
|
|
41
|
-
self.char_count = char_count
|
|
42
|
-
self.char_cap = char_cap
|
|
43
|
-
self.areas = areas
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
def normalize_description(raw: str) -> str:
|
|
47
|
-
if not isinstance(raw, str):
|
|
48
|
-
return ""
|
|
49
|
-
s = raw.strip()
|
|
50
|
-
s = re.sub(r"\s+", " ", s)
|
|
51
|
-
s = re.sub(r"[.!?]+$", "", s)
|
|
52
|
-
return s.lower()
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def phrase_to_slug(phrase: str) -> str:
|
|
56
|
-
slug = re.sub(r"[^a-z0-9]+", "-", phrase.lower())
|
|
57
|
-
slug = re.sub(r"-+", "-", slug).strip("-")
|
|
58
|
-
if len(slug) > 24:
|
|
59
|
-
truncated = slug[:24]
|
|
60
|
-
last_dash = truncated.rfind("-")
|
|
61
|
-
slug = truncated[:last_dash] if last_dash > 0 else truncated
|
|
62
|
-
return f"t-{slug or 'trigger'}"
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
def assign_unique_slugs(low_conf_matches: list[dict]) -> list[dict]:
|
|
66
|
-
slug_counts: dict[str, int] = {}
|
|
67
|
-
out: list[dict] = []
|
|
68
|
-
for m in low_conf_matches:
|
|
69
|
-
base = phrase_to_slug(m["phrase"])
|
|
70
|
-
count = slug_counts.get(base, 0)
|
|
71
|
-
slug_counts[base] = count + 1
|
|
72
|
-
slug = base if count == 0 else f"{base}-{count + 1}"
|
|
73
|
-
out.append({**m, "slug": slug})
|
|
74
|
-
return out
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def strip_frontmatter_raw(content: str) -> str:
|
|
78
|
-
if not content.startswith("---\n"):
|
|
79
|
-
return content.strip()
|
|
80
|
-
end = content.find("\n---\n", 4)
|
|
81
|
-
if end == -1:
|
|
82
|
-
return content.strip()
|
|
83
|
-
return content[end + 5:].strip()
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
def extract_infra_references(area_content: str) -> list[str]:
|
|
87
|
-
block = re.search(r"##\s+Related infrastructure\s*\n([\s\S]*?)(?:\n##\s|$)", area_content)
|
|
88
|
-
if not block:
|
|
89
|
-
return []
|
|
90
|
-
seen: set[str] = set()
|
|
91
|
-
out: list[str] = []
|
|
92
|
-
for m in re.finditer(r"aigis infra ([a-z0-9][a-z0-9-]*)", block.group(1), re.IGNORECASE):
|
|
93
|
-
i = m.group(1).lower()
|
|
94
|
-
if i not in seen:
|
|
95
|
-
seen.add(i)
|
|
96
|
-
out.append(i)
|
|
97
|
-
return out
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
def collect_infra_references(areas: list[str]) -> list[str]:
|
|
101
|
-
seen: set[str] = set()
|
|
102
|
-
out: list[str] = []
|
|
103
|
-
for area in areas:
|
|
104
|
-
try:
|
|
105
|
-
content = (CONTENT_DIR / "skills" / "areas" / f"{area}.md").read_text(encoding="utf-8")
|
|
106
|
-
except FileNotFoundError:
|
|
107
|
-
continue
|
|
108
|
-
for i in extract_infra_references(content):
|
|
109
|
-
if i not in seen:
|
|
110
|
-
seen.add(i)
|
|
111
|
-
out.append(i)
|
|
112
|
-
return out
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
def resolve_traits(detection: dict, decision_map: dict, *, uncertain_as_included: bool = True) -> dict:
|
|
116
|
-
confirmed: set[str] = set(detection["traits_auto_applied"])
|
|
117
|
-
uncertain: set[str] = set()
|
|
118
|
-
user_decisions: list[dict] = []
|
|
119
|
-
|
|
120
|
-
for sug in detection["low_confidence_matches"]:
|
|
121
|
-
raw = decision_map.get(sug["id"], "unsure" if uncertain_as_included else "no").lower()
|
|
122
|
-
if raw in ("y", "yes"):
|
|
123
|
-
decision = "yes"
|
|
124
|
-
elif raw in ("n", "no"):
|
|
125
|
-
decision = "no"
|
|
126
|
-
else:
|
|
127
|
-
decision = "unsure"
|
|
128
|
-
user_decisions.append({**sug, "user_decision": decision})
|
|
129
|
-
if decision == "yes":
|
|
130
|
-
for t in sug["traits"]:
|
|
131
|
-
confirmed.add(t)
|
|
132
|
-
elif decision == "unsure":
|
|
133
|
-
for t in sug["traits"]:
|
|
134
|
-
if t not in confirmed:
|
|
135
|
-
uncertain.add(t)
|
|
136
|
-
|
|
137
|
-
uncertain -= confirmed
|
|
138
|
-
return {
|
|
139
|
-
"confirmed_traits": sorted(confirmed),
|
|
140
|
-
"uncertain_traits": sorted(uncertain),
|
|
141
|
-
"all_traits": sorted(confirmed | uncertain),
|
|
142
|
-
"user_decisions": user_decisions,
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
def _read_title(subdir: str, file_id: str) -> str:
|
|
147
|
-
try:
|
|
148
|
-
raw = (CONTENT_DIR / subdir / f"{file_id}.md").read_text(encoding="utf-8")
|
|
149
|
-
parsed = frontmatter.loads(raw)
|
|
150
|
-
title = parsed.metadata.get("title")
|
|
151
|
-
return str(title) if title else file_id
|
|
152
|
-
except Exception:
|
|
153
|
-
return file_id
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
def _iso_ms(timestamp: datetime | None) -> str:
|
|
157
|
-
"""ISO-8601 with millisecond precision and 'Z' suffix — matches JS Date.toISOString()."""
|
|
158
|
-
dt = timestamp or datetime.now(timezone.utc)
|
|
159
|
-
if dt.tzinfo is None:
|
|
160
|
-
dt = dt.replace(tzinfo=timezone.utc)
|
|
161
|
-
return dt.astimezone(timezone.utc).isoformat(timespec="milliseconds").replace("+00:00", "Z")
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def _read_version() -> str:
|
|
165
|
-
try:
|
|
166
|
-
from . import __version__
|
|
167
|
-
return __version__
|
|
168
|
-
except Exception:
|
|
169
|
-
return "unknown"
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
def _prepare(description: str, decisions: dict) -> dict:
|
|
173
|
-
normalized = normalize_description(description)
|
|
174
|
-
if not normalized:
|
|
175
|
-
raise ValueError('Provide a description in quotes. Example: aigis build "customer chatbot with RAG"')
|
|
176
|
-
detection = detect_traits_from_text(normalized)
|
|
177
|
-
low_conf_with_slugs = assign_unique_slugs(detection["low_confidence_matches"])
|
|
178
|
-
detection_with_slugs = {**detection, "low_confidence_matches": low_conf_with_slugs}
|
|
179
|
-
|
|
180
|
-
numeric_decisions: dict[str, str] = {}
|
|
181
|
-
for m in low_conf_with_slugs:
|
|
182
|
-
if m["slug"] in decisions:
|
|
183
|
-
numeric_decisions[m["id"]] = decisions[m["slug"]]
|
|
184
|
-
elif m["id"] in decisions:
|
|
185
|
-
numeric_decisions[m["id"]] = decisions[m["id"]]
|
|
186
|
-
|
|
187
|
-
resolved = resolve_traits(detection_with_slugs, numeric_decisions, uncertain_as_included=True)
|
|
188
|
-
if not resolved["all_traits"]:
|
|
189
|
-
raise ValueError(
|
|
190
|
-
"No traits resolved from description. Try a more specific description, "
|
|
191
|
-
'or use `aigis classify --traits ...` directly.'
|
|
192
|
-
)
|
|
193
|
-
cls = classify(resolved["all_traits"])
|
|
194
|
-
areas = cls["implement_files"]
|
|
195
|
-
infra_ids = collect_infra_references(areas)
|
|
196
|
-
|
|
197
|
-
return {
|
|
198
|
-
"normalized": normalized,
|
|
199
|
-
"raw_input": description,
|
|
200
|
-
"detection": detection,
|
|
201
|
-
"low_conf_with_slugs": low_conf_with_slugs,
|
|
202
|
-
"resolved": resolved,
|
|
203
|
-
"cls": cls,
|
|
204
|
-
"areas": areas,
|
|
205
|
-
"infra_ids": infra_ids,
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
def _make_meta(prep: dict, brief: str, mode: str, cap: int | None, ts: str, version: str, fell_back: bool) -> dict:
|
|
210
|
-
return {
|
|
211
|
-
"mode": mode,
|
|
212
|
-
"auto_fallback": fell_back,
|
|
213
|
-
"normalized_description": prep["normalized"],
|
|
214
|
-
"input_was_normalized": prep["normalized"] != prep["raw_input"],
|
|
215
|
-
"raw_input": prep["raw_input"],
|
|
216
|
-
"confirmed_traits": prep["resolved"]["confirmed_traits"],
|
|
217
|
-
"uncertain_traits": prep["resolved"]["uncertain_traits"],
|
|
218
|
-
"all_traits": prep["resolved"]["all_traits"],
|
|
219
|
-
"risk_tier": prep["cls"]["risk_tier"],
|
|
220
|
-
"areas": prep["areas"],
|
|
221
|
-
"infra": prep["infra_ids"],
|
|
222
|
-
"templates": prep["cls"]["templates"],
|
|
223
|
-
"char_count": len(brief),
|
|
224
|
-
"char_cap": cap,
|
|
225
|
-
"low_confidence_matches": [
|
|
226
|
-
{
|
|
227
|
-
"slug": m["slug"],
|
|
228
|
-
"phrase": m["phrase"],
|
|
229
|
-
"traits": m["traits"],
|
|
230
|
-
"confirmation_prompt": m["confirmation_prompt"],
|
|
231
|
-
"notes": m["notes"],
|
|
232
|
-
}
|
|
233
|
-
for m in prep["low_conf_with_slugs"]
|
|
234
|
-
],
|
|
235
|
-
"user_decisions": prep["resolved"]["user_decisions"],
|
|
236
|
-
"generated_at": ts,
|
|
237
|
-
"version": version,
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
def _render_common_sections(*, normalized, version, ts, mode_note, cls, resolved, areas, infra_ids):
|
|
242
|
-
s: list[str] = []
|
|
243
|
-
s.append("# Aigis governance brief")
|
|
244
|
-
s.append("")
|
|
245
|
-
s.append(f'> Generated by `aigis build "{normalized}"`')
|
|
246
|
-
s.append(f"> aigis {version} — generated {ts}")
|
|
247
|
-
if mode_note:
|
|
248
|
-
s.append(f"> {mode_note}")
|
|
249
|
-
s.append("> Determinism note: same description + same trait decisions produces byte-identical brief (timestamp masked).")
|
|
250
|
-
s.append("")
|
|
251
|
-
|
|
252
|
-
s.append("## Input")
|
|
253
|
-
s.append("")
|
|
254
|
-
s.append(f"- Description: `{normalized}`")
|
|
255
|
-
s.append(f"- Risk tier: **{cls['risk_tier']}** _({cls['reason']})_")
|
|
256
|
-
confirmed_str = ", ".join(f"`{t}`" for t in resolved["confirmed_traits"]) or "(none)"
|
|
257
|
-
s.append(f"- Confirmed traits ({len(resolved['confirmed_traits'])}): {confirmed_str}")
|
|
258
|
-
if resolved["uncertain_traits"]:
|
|
259
|
-
s.append(f"- Uncertain traits ({len(resolved['uncertain_traits'])}, marked ⚠ in this brief):")
|
|
260
|
-
for t in resolved["uncertain_traits"]:
|
|
261
|
-
s.append(f" - ⚠ `{t}` — surfaced from a low-confidence trigger; treat as *possibly applicable*. Ask the user before assuming.")
|
|
262
|
-
else:
|
|
263
|
-
s.append("- Uncertain traits (0)")
|
|
264
|
-
s.append("")
|
|
265
|
-
|
|
266
|
-
s.append("## Instructions for the agent")
|
|
267
|
-
s.append("")
|
|
268
|
-
s.append("The following are governance areas Aigis identified based on the description above. **Treat them as a starting point, not a closed list.**")
|
|
269
|
-
s.append("")
|
|
270
|
-
s.append("1. Verify these match your understanding of *this* codebase before implementing. If any area clearly does not apply (e.g. `pii-handling` for a system that genuinely handles no user data), say so to the user and skip it with a written reason.")
|
|
271
|
-
s.append("2. If the codebase reveals concerns Aigis missed (a webhook surface, a privileged tool the LLM can call, a regulated jurisdiction), add the matching area. Run `aigis search --list` to see what's available.")
|
|
272
|
-
s.append("3. For each area below, follow the procedure step by step. Honor every **verification checkpoint** — those are not suggestions.")
|
|
273
|
-
s.append("4. Run `aigis verify <area> --auto .` after implementing each area. Fix any FAIL or OVERCLAIM before moving on.")
|
|
274
|
-
s.append("5. For uncertain traits (⚠ above), pause before implementing the dependent area and ask the user to confirm it applies.")
|
|
275
|
-
s.append("")
|
|
276
|
-
return s
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
def _render_verification(*, areas, resolved, cls):
|
|
280
|
-
s: list[str] = []
|
|
281
|
-
s.append("## Verification")
|
|
282
|
-
s.append("")
|
|
283
|
-
s.append("After implementing the areas above, the agent should confirm:")
|
|
284
|
-
s.append("")
|
|
285
|
-
s.append("- [ ] Every area's verification checkpoints pass.")
|
|
286
|
-
for area in areas:
|
|
287
|
-
s.append(f"- [ ] `aigis verify {area} --auto .` returns no FAIL or OVERCLAIM.")
|
|
288
|
-
s.append("- [ ] If any area was added or removed from the recommended set, document the reason in the PR description.")
|
|
289
|
-
if resolved["uncertain_traits"]:
|
|
290
|
-
plural = "" if len(resolved["uncertain_traits"]) == 1 else "s"
|
|
291
|
-
traits_str = ", ".join(f"`{t}`" for t in resolved["uncertain_traits"])
|
|
292
|
-
s.append(f"- [ ] Uncertain trait{plural} ({traits_str}) confirmed or rejected with the user before relevant code paths shipped.")
|
|
293
|
-
if cls["templates"]:
|
|
294
|
-
s.append("- [ ] Documentation templates generated:")
|
|
295
|
-
for t in cls["templates"]:
|
|
296
|
-
s.append(f" - [ ] `aigis template {t}`")
|
|
297
|
-
s.append("")
|
|
298
|
-
s.append("---")
|
|
299
|
-
s.append("")
|
|
300
|
-
s.append("*Generated by aigis. This brief is content, not a scaffold — Aigis writes nothing into your project. The agent and the user remain responsible for what ships.*")
|
|
301
|
-
s.append("")
|
|
302
|
-
return s
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
def build_compact(description: str, decisions: dict | None = None, *,
|
|
306
|
-
timestamp: datetime | None = None,
|
|
307
|
-
version_string: str | None = None,
|
|
308
|
-
fell_back_from_full: bool = False) -> dict:
|
|
309
|
-
decisions = decisions or {}
|
|
310
|
-
prep = _prepare(description, decisions)
|
|
311
|
-
ts = _iso_ms(timestamp)
|
|
312
|
-
version = version_string or _read_version()
|
|
313
|
-
|
|
314
|
-
if fell_back_from_full:
|
|
315
|
-
mode_note = (
|
|
316
|
-
f"Compact mode (auto-fallback): full brief would exceed {AUTO_FULL_CAP:,} chars. "
|
|
317
|
-
f'Run `aigis build "{prep["normalized"]}" --full` to force inlined content; '
|
|
318
|
-
f"you may need to split into per-domain runs."
|
|
319
|
-
)
|
|
320
|
-
else:
|
|
321
|
-
mode_note = f'Compact mode: pointer-only. Run `aigis build "{prep["normalized"]}" --full` to inline procedure content.'
|
|
322
|
-
|
|
323
|
-
s = _render_common_sections(
|
|
324
|
-
normalized=prep["normalized"], version=version, ts=ts, mode_note=mode_note,
|
|
325
|
-
cls=prep["cls"], resolved=prep["resolved"], areas=prep["areas"], infra_ids=prep["infra_ids"],
|
|
326
|
-
)
|
|
327
|
-
|
|
328
|
-
s.append(f"## Areas ({len(prep['areas'])})")
|
|
329
|
-
s.append("")
|
|
330
|
-
s.append("For each area below, run `aigis get <area>` to fetch the full procedure, then implement step by step. Run `aigis verify <area> --auto .` after.")
|
|
331
|
-
s.append("")
|
|
332
|
-
for i, area in enumerate(prep["areas"], 1):
|
|
333
|
-
title = _read_title("skills/areas", area)
|
|
334
|
-
s.append(f"{i}. **{area}** — {title}")
|
|
335
|
-
s.append(f" - Fetch: `aigis get {area}`")
|
|
336
|
-
s.append(f" - Verify: `aigis verify {area} --auto .`")
|
|
337
|
-
s.append("")
|
|
338
|
-
|
|
339
|
-
if prep["infra_ids"]:
|
|
340
|
-
s.append(f"## Infrastructure ({len(prep['infra_ids'])})")
|
|
341
|
-
s.append("")
|
|
342
|
-
s.append("The areas above reference these infrastructure files. Fetch as needed:")
|
|
343
|
-
s.append("")
|
|
344
|
-
for i in prep["infra_ids"]:
|
|
345
|
-
title = _read_title("skills/infrastructure", i)
|
|
346
|
-
s.append(f"- `aigis infra {i}` — {title}")
|
|
347
|
-
s.append("")
|
|
348
|
-
|
|
349
|
-
s.extend(_render_verification(areas=prep["areas"], resolved=prep["resolved"], cls=prep["cls"]))
|
|
350
|
-
brief = "\n".join(s)
|
|
351
|
-
return {"brief": brief, "meta": _make_meta(prep, brief, "compact", None, ts, version, fell_back_from_full)}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
def build_full(description: str, decisions: dict | None = None, *,
|
|
355
|
-
char_cap: int = FULL_HARD_CAP,
|
|
356
|
-
timestamp: datetime | None = None,
|
|
357
|
-
version_string: str | None = None) -> dict:
|
|
358
|
-
decisions = decisions or {}
|
|
359
|
-
prep = _prepare(description, decisions)
|
|
360
|
-
ts = _iso_ms(timestamp)
|
|
361
|
-
version = version_string or _read_version()
|
|
362
|
-
|
|
363
|
-
s = _render_common_sections(
|
|
364
|
-
normalized=prep["normalized"], version=version, ts=ts, mode_note=None,
|
|
365
|
-
cls=prep["cls"], resolved=prep["resolved"], areas=prep["areas"], infra_ids=prep["infra_ids"],
|
|
366
|
-
)
|
|
367
|
-
|
|
368
|
-
s.append("## Areas")
|
|
369
|
-
s.append("")
|
|
370
|
-
for i, area in enumerate(prep["areas"], 1):
|
|
371
|
-
try:
|
|
372
|
-
raw = (CONTENT_DIR / "skills" / "areas" / f"{area}.md").read_text(encoding="utf-8")
|
|
373
|
-
except FileNotFoundError:
|
|
374
|
-
continue
|
|
375
|
-
stripped = strip_frontmatter_raw(raw)
|
|
376
|
-
s.append(f"### {i}. {area}")
|
|
377
|
-
s.append("")
|
|
378
|
-
s.append(stripped)
|
|
379
|
-
s.append("")
|
|
380
|
-
s.append("---")
|
|
381
|
-
s.append("")
|
|
382
|
-
|
|
383
|
-
if prep["infra_ids"]:
|
|
384
|
-
s.append("## Infrastructure")
|
|
385
|
-
s.append("")
|
|
386
|
-
s.append("The areas above reference these infrastructure files. Apply whichever shape (from-scratch / existing) matches the project.")
|
|
387
|
-
s.append("")
|
|
388
|
-
for i in prep["infra_ids"]:
|
|
389
|
-
try:
|
|
390
|
-
raw = get_infra(i)
|
|
391
|
-
except Exception:
|
|
392
|
-
continue
|
|
393
|
-
stripped = strip_frontmatter_raw(raw)
|
|
394
|
-
s.append(f"### {i}")
|
|
395
|
-
s.append("")
|
|
396
|
-
s.append(stripped)
|
|
397
|
-
s.append("")
|
|
398
|
-
s.append("---")
|
|
399
|
-
s.append("")
|
|
400
|
-
|
|
401
|
-
s.extend(_render_verification(areas=prep["areas"], resolved=prep["resolved"], cls=prep["cls"]))
|
|
402
|
-
brief = "\n".join(s)
|
|
403
|
-
if len(brief) > char_cap:
|
|
404
|
-
raise BriefTooLargeError(len(brief), char_cap, prep["areas"])
|
|
405
|
-
return {"brief": brief, "meta": _make_meta(prep, brief, "full", char_cap, ts, version, False)}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
def build_brief(description: str, decisions: dict | None = None, *,
|
|
409
|
-
mode: str = "auto",
|
|
410
|
-
timestamp: datetime | None = None,
|
|
411
|
-
version_string: str | None = None) -> dict:
|
|
412
|
-
"""Dispatcher. mode ∈ {'auto', 'full', 'compact'}."""
|
|
413
|
-
decisions = decisions or {}
|
|
414
|
-
if mode == "compact":
|
|
415
|
-
r = build_compact(description, decisions, timestamp=timestamp, version_string=version_string)
|
|
416
|
-
return {**r, "mode": "compact", "auto_fallback": False}
|
|
417
|
-
if mode == "full":
|
|
418
|
-
r = build_full(description, decisions, char_cap=FULL_HARD_CAP, timestamp=timestamp, version_string=version_string)
|
|
419
|
-
return {**r, "mode": "full", "auto_fallback": False}
|
|
420
|
-
# auto
|
|
421
|
-
try:
|
|
422
|
-
r = build_full(description, decisions, char_cap=AUTO_FULL_CAP, timestamp=timestamp, version_string=version_string)
|
|
423
|
-
return {**r, "mode": "full", "auto_fallback": False}
|
|
424
|
-
except BriefTooLargeError as e:
|
|
425
|
-
compact = build_compact(description, decisions, timestamp=timestamp, version_string=version_string, fell_back_from_full=True)
|
|
426
|
-
return {
|
|
427
|
-
**compact,
|
|
428
|
-
"mode": "compact",
|
|
429
|
-
"auto_fallback": True,
|
|
430
|
-
"auto_fallback_full_chars": e.char_count,
|
|
431
|
-
"auto_fallback_full_cap": e.char_cap,
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
def build_list(description: str) -> str:
|
|
436
|
-
"""Shape A — text output for `aigis build --list`."""
|
|
437
|
-
prep = _prepare(description, {})
|
|
438
|
-
lines: list[str] = []
|
|
439
|
-
lines.append(f"Description: {prep['normalized']}")
|
|
440
|
-
lines.append(f"Risk tier: {prep['cls']['risk_tier']}")
|
|
441
|
-
lines.append("")
|
|
442
|
-
lines.append(f"Confirmed traits ({len(prep['resolved']['confirmed_traits'])}):")
|
|
443
|
-
lines.append(f" {', '.join(prep['resolved']['confirmed_traits']) or '(none)'}")
|
|
444
|
-
lines.append("")
|
|
445
|
-
lines.append(f"Uncertain traits ({len(prep['resolved']['uncertain_traits'])}):")
|
|
446
|
-
if not prep["low_conf_with_slugs"]:
|
|
447
|
-
lines.append(" (none)")
|
|
448
|
-
else:
|
|
449
|
-
for m in prep["low_conf_with_slugs"]:
|
|
450
|
-
lines.append(f" [{m['slug']}] {', '.join(m['traits'])} ← \"{m['phrase']}\"")
|
|
451
|
-
lines.append("")
|
|
452
|
-
lines.append("Pre-build flags (run non-interactively):")
|
|
453
|
-
slugs = ",".join(m["slug"] for m in prep["low_conf_with_slugs"])
|
|
454
|
-
lines.append(f' aigis build "{prep["normalized"]}" --confirm {slugs}')
|
|
455
|
-
lines.append(f' aigis build "{prep["normalized"]}" --reject {slugs}')
|
|
456
|
-
lines.append("")
|
|
457
|
-
lines.append(f"Recommended areas ({len(prep['areas'])}):")
|
|
458
|
-
for a in prep["areas"]:
|
|
459
|
-
lines.append(f" aigis get {a}")
|
|
460
|
-
if prep["infra_ids"]:
|
|
461
|
-
lines.append("")
|
|
462
|
-
lines.append(f"Referenced infrastructure ({len(prep['infra_ids'])}):")
|
|
463
|
-
for i in prep["infra_ids"]:
|
|
464
|
-
lines.append(f" aigis infra {i}")
|
|
465
|
-
if prep["cls"]["templates"]:
|
|
466
|
-
lines.append("")
|
|
467
|
-
lines.append(f"Documentation templates ({len(prep['cls']['templates'])}):")
|
|
468
|
-
for t in prep["cls"]["templates"]:
|
|
469
|
-
lines.append(f" aigis template {t}")
|
|
470
|
-
return "\n".join(lines) + "\n"
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"""Mirror of lib/checksum.js. Spec is the same: strip BOM, normalize CRLF/CR to LF, SHA-256."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import hashlib
|
|
6
|
-
from pathlib import Path
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def canonicalize(text: str) -> str:
|
|
10
|
-
if text.startswith("\ufeff"):
|
|
11
|
-
text = text[1:]
|
|
12
|
-
return text.replace("\r\n", "\n").replace("\r", "\n")
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def compute_checksum(text: str) -> str:
|
|
16
|
-
canonical = canonicalize(text)
|
|
17
|
-
return hashlib.sha256(canonical.encode("utf-8")).hexdigest()
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def compute_file_checksum(path: str | Path) -> str:
|
|
21
|
-
text = Path(path).read_text(encoding="utf-8")
|
|
22
|
-
return compute_checksum(text)
|