chaincompiler-accc 0.3.0__py3-none-any.whl
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.
- accc/__init__.py +15 -0
- accc/cli.py +76 -0
- accc/forge.py +87 -0
- accc/notation.py +45 -0
- accc/render.py +44 -0
- chaincompiler_accc-0.3.0.dist-info/METADATA +9 -0
- chaincompiler_accc-0.3.0.dist-info/RECORD +10 -0
- chaincompiler_accc-0.3.0.dist-info/WHEEL +5 -0
- chaincompiler_accc-0.3.0.dist-info/entry_points.txt +2 -0
- chaincompiler_accc-0.3.0.dist-info/top_level.txt +1 -0
accc/__init__.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""ACCC — Attention-Chain Compiler-Compiler. The atom of the cognition stack.
|
|
2
|
+
|
|
3
|
+
ACCC → CORCC → SCCC: a CoR step embeds a forged AC; a skill embeds a CoR.
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
__version__ = "0.3.0"
|
|
8
|
+
|
|
9
|
+
from .forge import Language, forge, gate, grammar, package, prime
|
|
10
|
+
from .render import attention_block, parse_ac
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"forge", "gate", "grammar", "prime", "package", "Language",
|
|
14
|
+
"attention_block", "parse_ac", "__version__",
|
|
15
|
+
]
|
accc/cli.py
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""accc — forge attention-chain languages, gate them, compile them to blocks."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
import tempfile
|
|
6
|
+
|
|
7
|
+
import click
|
|
8
|
+
|
|
9
|
+
from .forge import forge, gate, grammar, prime
|
|
10
|
+
from .notation import SEED_LANGUAGES
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@click.group()
|
|
14
|
+
@click.version_option(message="accc %(version)s")
|
|
15
|
+
def main() -> None:
|
|
16
|
+
"""Attention-Chain Compiler-Compiler."""
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@main.command()
|
|
20
|
+
@click.argument("name")
|
|
21
|
+
@click.argument("examples_file", type=click.Path(exists=True, dir_okay=False, path_type=Path))
|
|
22
|
+
@click.option("--db", default=".accc.db")
|
|
23
|
+
@click.option("--strict/--shape-only", default=False, help="Pin focus vocabulary (strict) or shape only.")
|
|
24
|
+
def forge_cmd(name: str, examples_file: Path, db: str, strict: bool) -> None:
|
|
25
|
+
"""Forge an AC language NAME from EXAMPLES_FILE (one chain per line)."""
|
|
26
|
+
examples = [ln for ln in examples_file.read_text(encoding="utf-8").splitlines() if ln.strip()]
|
|
27
|
+
lang = forge(name, examples, db=db, strict=strict)
|
|
28
|
+
click.echo(f"forged '{lang.name}' (scope {lang.scope}, {lang.rule_count} rules):")
|
|
29
|
+
for line in grammar(lang):
|
|
30
|
+
click.echo(" " + line)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
main.add_command(forge_cmd, name="forge")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@main.command()
|
|
37
|
+
def demo() -> None:
|
|
38
|
+
"""Forge two distinct AC languages, gate them, and emit a prime block."""
|
|
39
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
40
|
+
db = str(Path(tmp) / "accc.db")
|
|
41
|
+
|
|
42
|
+
click.echo("══ 1. FORGE — mint a generic AC language (shape only) ══")
|
|
43
|
+
generic = forge("generic", SEED_LANGUAGES["generic"], db=db)
|
|
44
|
+
for line in grammar(generic):
|
|
45
|
+
click.echo(" " + line)
|
|
46
|
+
|
|
47
|
+
click.echo("\n══ 2. FORGE — mint a DEBUG AC language (strict: pins the vocabulary) ══")
|
|
48
|
+
debug = forge("debug", SEED_LANGUAGES["debug"], db=db, strict=True)
|
|
49
|
+
click.echo(f" debug language scope={debug.scope}, {debug.rule_count} rules "
|
|
50
|
+
"(distinct from generic — domain-specific attention)")
|
|
51
|
+
|
|
52
|
+
click.echo("\n══ 3. PRIME — the re-injectable attention block for the debug language ══")
|
|
53
|
+
click.echo(prime(debug, "[Symptom] ⇒ [Logs] ⇒ [Hypothesis] ⇒ |Localize|"))
|
|
54
|
+
|
|
55
|
+
click.echo("\n══ 4. GATE — a valid debug AC (should pass) ══")
|
|
56
|
+
good = "[Symptom] ⇒ [Repro] ⇒ [Diff] ⇒ |Localize|"
|
|
57
|
+
v, _ = gate(debug, good)
|
|
58
|
+
click.echo(f" {good}\n → {'clean ✓' if not v else 'REJECTED'}")
|
|
59
|
+
|
|
60
|
+
click.echo("\n══ 5. GATE — an off-domain AC (planning foci in the debug language) ══")
|
|
61
|
+
wrong = "[Goal] ⇒ [Constraints] ⇒ [Evidence] ⇒ |Plan|"
|
|
62
|
+
v, fixes = gate(debug, wrong)
|
|
63
|
+
if v:
|
|
64
|
+
vio, fx = v[0], fixes[0]
|
|
65
|
+
click.echo(f" {wrong}\n ✗ {vio.verdict}: expected {vio.expected_token!r}, "
|
|
66
|
+
f"found {vio.found_token!r}; fix: {list(fx.candidate_tokens) or fx.reason}")
|
|
67
|
+
else:
|
|
68
|
+
click.echo(" (clean — shape matched; strict vocab not violated)")
|
|
69
|
+
|
|
70
|
+
click.echo("\n══ 6. The CC point ══")
|
|
71
|
+
click.echo(" Two attention-chain LANGUAGES were minted from examples — not hand-written. "
|
|
72
|
+
"CORCC will embed a forged AC inside each reasoning step.")
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
main()
|
accc/forge.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""ACCC — the Attention-Chain Compiler-Compiler. Made FROM ChainCompiler (DESIGN.md §2: ACCC imports CC).
|
|
2
|
+
|
|
3
|
+
The compiler-compiler move: `forge` mints a *new* AC language for a task/domain (it doesn't just compile
|
|
4
|
+
one chain). The generic machinery (forge a rulecatcher scope, gate against it, read the grammar, wrap a
|
|
5
|
+
body as SKILL.md) lives in `chaincompiler.forge`; ACCC specializes it to attention chains (the `ac:` kind
|
|
6
|
+
+ the attention-block render). CORCC consumes these: a reasoning step embeds a forged AC.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
# made FROM CC — the generic forge core (CC re-exports APE's write_skill/learn/gate underneath):
|
|
11
|
+
from chaincompiler import (
|
|
12
|
+
Language,
|
|
13
|
+
forge as _forge,
|
|
14
|
+
gate_language as _gate,
|
|
15
|
+
grammar as _grammar,
|
|
16
|
+
package_skill as _package,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
from .render import attention_block, parse_ac
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def forge(name: str, examples: list[str], *, db: str, strict: bool = False) -> Language:
|
|
23
|
+
"""Mint an AC language for `name` from example chains (CC's forge, `ac:` kind).
|
|
24
|
+
|
|
25
|
+
strict=False → learn the SHAPE only (next_kind): any focus vocabulary is allowed.
|
|
26
|
+
strict=True → also pin the focus vocabulary (next_token): the gate enforces
|
|
27
|
+
domain-specific foci (e.g. a debug AC must open on a Symptom).
|
|
28
|
+
"""
|
|
29
|
+
return _forge("ac", name, examples, db=db, strict=strict)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def gate(language: Language, ac: str) -> tuple[list, list]:
|
|
33
|
+
"""Lint a candidate attention chain against a forged language."""
|
|
34
|
+
return _gate(language, ac)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def grammar(language: Language) -> list[str]:
|
|
38
|
+
return _grammar(language)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def package(name: str, ac: str, *, out_dir: str, description: str | None = None):
|
|
42
|
+
"""Compile an attention chain to a publishable `<name>/SKILL.md` package.
|
|
43
|
+
|
|
44
|
+
The body is a markdown file carrying the AC in its custom syntax + how to use
|
|
45
|
+
it. The dir/SKILL.md wrapper is just so any agent auto-loads it.
|
|
46
|
+
"""
|
|
47
|
+
foci, held = parse_ac(ac)
|
|
48
|
+
# NOTE: no ": " in the default — write_skill (APE) does not YAML-escape the
|
|
49
|
+
# description, and a plain scalar containing ": " emits unparseable frontmatter.
|
|
50
|
+
desc = description or (
|
|
51
|
+
f"Attention template (how to think) — attend to {', '.join(foci)}"
|
|
52
|
+
+ (f" → hold {held}" if held else "") + "."
|
|
53
|
+
)
|
|
54
|
+
body = "\n".join([
|
|
55
|
+
"This is an **attention chain** — an INNER template for how to think about something "
|
|
56
|
+
"(a scaffold for a section or for your thinking). Not necessarily spoken.",
|
|
57
|
+
"",
|
|
58
|
+
"## Chain (custom syntax)",
|
|
59
|
+
"```rune",
|
|
60
|
+
ac.strip(),
|
|
61
|
+
"```",
|
|
62
|
+
"",
|
|
63
|
+
"## How to use it",
|
|
64
|
+
attention_block(name, ac),
|
|
65
|
+
])
|
|
66
|
+
return _package(name, body, out_dir=out_dir, description=desc, extra={"kind": "attention-chain"})
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def prime(language: Language, exemplar: str) -> str:
|
|
70
|
+
"""The re-injectable PRIME for a forged AC language."""
|
|
71
|
+
g = grammar(language)
|
|
72
|
+
block = attention_block(language.name, exemplar)
|
|
73
|
+
return "\n".join([
|
|
74
|
+
f'# PRIME — attention-chain language "{language.name}"',
|
|
75
|
+
"",
|
|
76
|
+
"Direct your attention using chains of this shape. Every chain you emit is "
|
|
77
|
+
"gated against the language; fix violations before continuing.",
|
|
78
|
+
"",
|
|
79
|
+
f"## Ratified grammar ({len(g)} rules)",
|
|
80
|
+
*(g or ["(none)"]),
|
|
81
|
+
"",
|
|
82
|
+
"## Exemplar (compiled to an attention block)",
|
|
83
|
+
block,
|
|
84
|
+
"",
|
|
85
|
+
"## Directive",
|
|
86
|
+
"Emit attention chains in this language. End on a bounded |Held| focus.",
|
|
87
|
+
])
|
accc/notation.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""The Attention-Chain notation + seed corpora.
|
|
2
|
+
|
|
3
|
+
An ATTENTION CHAIN (AC) is the atom of the cognition stack: a prompt block that
|
|
4
|
+
sequences attention foci and converges on a held focus. It is what powers ONE
|
|
5
|
+
reasoning step (a CoR step embeds an AC). Written in Dense Rune-Chain so HoneyC
|
|
6
|
+
compiles it and rulecatcher catches its grammar:
|
|
7
|
+
|
|
8
|
+
[Focus_1] ⇒ [Focus_2] ⇒ ... ⇒ |Held|
|
|
9
|
+
|
|
10
|
+
- each [Focus_i] is something to attend to, in order
|
|
11
|
+
- ⇒ flows attention forward
|
|
12
|
+
- |Held| (bounded) is the convergence point attention is stabilized on
|
|
13
|
+
|
|
14
|
+
Different domains forge different AC languages: the SHAPE is shared, the focus
|
|
15
|
+
vocabulary and the held target differ. That is what makes ACCC a
|
|
16
|
+
compiler-compiler — it mints AC *languages*, not just compiles one AC.
|
|
17
|
+
"""
|
|
18
|
+
from __future__ import annotations
|
|
19
|
+
|
|
20
|
+
# Generic planning attention chain: orient → converge on a plan.
|
|
21
|
+
GENERIC_AC = [
|
|
22
|
+
"[Goal] ⇒ [Constraints] ⇒ [Evidence] ⇒ |Plan|",
|
|
23
|
+
"[Goal] ⇒ [Risks] ⇒ [Evidence] ⇒ |Plan|",
|
|
24
|
+
"[Goal] ⇒ [Constraints] ⇒ [Options] ⇒ |Plan|",
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
# Domain-specific AC: debugging. Different vocabulary, different held target.
|
|
28
|
+
DEBUG_AC = [
|
|
29
|
+
"[Symptom] ⇒ [Repro] ⇒ [Hypothesis] ⇒ |Localize|",
|
|
30
|
+
"[Symptom] ⇒ [Logs] ⇒ [Hypothesis] ⇒ |Localize|",
|
|
31
|
+
"[Symptom] ⇒ [Repro] ⇒ [Diff] ⇒ |Localize|",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
# Another domain: literature research.
|
|
35
|
+
RESEARCH_AC = [
|
|
36
|
+
"[Question] ⇒ [Sources] ⇒ [Claims] ⇒ |Synthesis|",
|
|
37
|
+
"[Question] ⇒ [Sources] ⇒ [Conflicts] ⇒ |Synthesis|",
|
|
38
|
+
"[Question] ⇒ [Gaps] ⇒ [Claims] ⇒ |Synthesis|",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
SEED_LANGUAGES = {
|
|
42
|
+
"generic": GENERIC_AC,
|
|
43
|
+
"debug": DEBUG_AC,
|
|
44
|
+
"research": RESEARCH_AC,
|
|
45
|
+
}
|
accc/render.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"""Compile an attention chain into a usable attention-directing prompt block.
|
|
2
|
+
|
|
3
|
+
This is the AC-specific lens (HoneyC gives generic triples/prose; this turns an
|
|
4
|
+
AC into the actual block you inject to direct a model's attention).
|
|
5
|
+
"""
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from honeyc.ast_nodes import Bounded, Chain, Entity, Glyph, Symbol, TypeAnn
|
|
9
|
+
from honeyc.parser import parse_text
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _label(term: object) -> str:
|
|
13
|
+
if isinstance(term, Bounded):
|
|
14
|
+
return _label(term.term)
|
|
15
|
+
if isinstance(term, TypeAnn):
|
|
16
|
+
return _label(term.term)
|
|
17
|
+
if isinstance(term, Entity):
|
|
18
|
+
return term.id
|
|
19
|
+
if isinstance(term, Symbol):
|
|
20
|
+
return term.name
|
|
21
|
+
if isinstance(term, Glyph):
|
|
22
|
+
return term.name or term.id
|
|
23
|
+
return str(term)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def parse_ac(ac: str) -> tuple[list[str], str | None]:
|
|
27
|
+
"""Return (ordered foci, held focus) for an attention chain."""
|
|
28
|
+
program = parse_text(ac)
|
|
29
|
+
chain = next((s for s in program.statements if isinstance(s, Chain)), None)
|
|
30
|
+
if chain is None:
|
|
31
|
+
raise ValueError(f"not an attention chain: {ac!r}")
|
|
32
|
+
foci = [_label(t) for t in chain.terms if not isinstance(t, Bounded)]
|
|
33
|
+
held_term = next((t for t in chain.terms if isinstance(t, Bounded)), None)
|
|
34
|
+
return foci, (_label(held_term) if held_term is not None else None)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def attention_block(name: str, ac: str) -> str:
|
|
38
|
+
"""The injectable prompt block that directs attention along the chain."""
|
|
39
|
+
foci, held = parse_ac(ac)
|
|
40
|
+
lines = [f"# Attention chain — {name}", "Attend, in order:"]
|
|
41
|
+
lines += [f" {i}. {focus}" for i, focus in enumerate(foci, 1)]
|
|
42
|
+
if held:
|
|
43
|
+
lines.append(f"Hold: {held} ← converge attention here, then act")
|
|
44
|
+
return "\n".join(lines)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chaincompiler-accc
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Attention-Chain Compiler-Compiler — the atom of the cognition-chain stack
|
|
5
|
+
Requires-Python: >=3.11
|
|
6
|
+
Requires-Dist: chaincompiler==0.3.0
|
|
7
|
+
Requires-Dist: honeyc==0.3.0
|
|
8
|
+
Requires-Dist: rulecatcher==0.3.0
|
|
9
|
+
Requires-Dist: click
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
accc/__init__.py,sha256=bnQ9VCvNBKhTdlY13nr2-GiToLzaQb9LXVqJQJtKtmo,463
|
|
2
|
+
accc/cli.py,sha256=CPavOMqItOeAkPT4G81rt5GwFecAQZjuxQ_WxcqqAK8,3248
|
|
3
|
+
accc/forge.py,sha256=PumYqtANuGgyWL7euDukYmHsqYuu35T8oqnCDsYgd-4,3518
|
|
4
|
+
accc/notation.py,sha256=PAXrRBbHP23c1qoAoPE0CtSzPtpPuRI3S0hJHtup0Es,1660
|
|
5
|
+
accc/render.py,sha256=uD7LyEjXbpAHuESzKl03tpc7FeLUGYZRshCOKWOPiA8,1704
|
|
6
|
+
chaincompiler_accc-0.3.0.dist-info/METADATA,sha256=53bLlVIxYYEwv6glN_PxPF-65xhYX_FKUlO0PpGnRA8,291
|
|
7
|
+
chaincompiler_accc-0.3.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
8
|
+
chaincompiler_accc-0.3.0.dist-info/entry_points.txt,sha256=fNFz95ekeNUgHPzVGFiv6PFswWJYB9Z5IKjrUwFm_IU,39
|
|
9
|
+
chaincompiler_accc-0.3.0.dist-info/top_level.txt,sha256=cAgWuaOtwW4H43SrtL7M0TfzbtXbWgD4dREFovVxgVU,5
|
|
10
|
+
chaincompiler_accc-0.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
accc
|