Repository navigation
aisync 0.2.0: rules as interfaces, loaded in layers, plus an MCP server - #5
Conversation
… server Rules: `rule add --when/--do/--not` writes a rule as an interface with a stable ID; `rule_spec = true` refuses any other shape; `rule lint`, `rule rewrite` (refuses a rewrite that drops a path, number or command), `rule enforcement` (optional sidecar of what keeps each rule; `require_enforcer = true` makes it mandatory), `--topic`, `--replaces` with a rules archive. `rulecheck` proves a cleanup lost no hard fact. Layers: a target with `layer = "core"` carries `core_topics` in full and folds the rest to one line each; the hook injects a folded topic once per session when the prompt or a tool call touches its `[shelf]` keywords. `progress_file` keeps agents.md byte-stable so prompt caches keep hitting. Tidy: `aisync tidy` proposes (duplicates, uncited rules, core budget) and never edits; the daily run is off by default (`tidy_daily`), never starts under a test, runs one at a time, niced, and scans no transcripts unless `tidy_usage_globs` is set. Any agent: `aisync mcp` serves rules, rule_add, log, claim, release, news, status and tidy over stdio; the SDK is the optional `aisync[mcp]` extra, the core stays standard-library only. Optional `instinct` habit list. Release: CI runs pytest plus tools/privacy_scan.py (tree, wheel and the commits since the last tag; guarded words kept as SHA-256 prefixes). watch.restart() refuses to execv a test runner. Demo, board, front screen, README (EN, ZH) and screenshot updated. Co-authored-by: Claude <[email protected]> Agent: claude-code
… tools, 4 weeks); example fits 80 columns Co-authored-by: Claude <[email protected]> Agent: claude-code
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bc804a4fd1
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| new_truth = merge_back(block, extract_block(truth_path.read_text()) or block) if target.slim else block | ||
| atomic_write(truth_path, replace_block(truth_path.read_text(), new_truth)) |
There was a problem hiding this comment.
Restore shelved topics before resolving in favor of a layered copy
When a layer = "core" target and preferences.md are both edited, resolving the conflict with --take target writes the folded target block directly into the source of truth. Unlike distribute()'s adoption path, this only restores superseded history for slim targets; it never calls layers.merge_back(). Consequently, every shelved topic's actual rules are replaced by its _Shelved placeholder and subsequently disappear from other copies too. Restore the layered target's omitted topics before writing the resolved truth.
Useful? React with 👍 / 👎.
| retired = [l for l in lines[s + 1:e] if l.startswith("- ")] | ||
| while s > 0 and lines[s - 1].strip() == "": | ||
| s -= 1 | ||
| del lines[s:e] |
There was a problem hiding this comment.
Preserve continuation lines when archiving retired rules
If a rule under ### 已取代 has indented continuation lines, normalization retains only its initial - line and deletes the entire original section. Any commands, paths, or explanations in those continuation lines are therefore lost from both preferences.md and rules-archive.md during the automatic sync cycle. Other rule-handling paths already recognize multiline bullets, including rulecheck.rules() and _insert_topic_rule(). Join each retired bullet's continuation lines before archiving it rather than filtering them out.
Useful? React with 👍 / 👎.
| gone = missing(paths) | ||
| if gone: | ||
| raise ValueError(f"--enforced-by path does not exist: {', '.join(gone)}") | ||
| return {"enforced_by": [_tilde(str(Path(p).expanduser())) for p in paths]} |
There was a problem hiding this comment.
Resolve enforcer paths before persisting the sidecar
When a caller supplies a relative enforcer path such as tests/test_api.py, validation succeeds in the caller's repository, but this expression stores the path unchanged. report() later checks that path against its own working directory, so running rule enforcement from another repository falsely reports the existing enforcer as missing and exits unsuccessfully; an identically named file could also incorrectly satisfy the check. Resolve paths against the adding process's working directory before applying the home-directory abbreviation and saving them.
Useful? React with 👍 / 👎.
| else: | ||
| bullet = f"- {_stamp()} ({who}): {text}" + (f" Reason: {' '.join(reason.split())}" if reason.strip() else "") | ||
| with core.locked(cfg): | ||
| written = _insert_rule(cfg, bullet, text) | ||
| added, bullet, rep = bool(written), written or bullet, {"moved": None} |
There was a problem hiding this comment.
Apply rule-spec validation to hubs without topic headings
On a newly initialized or otherwise ungrouped hub, setting rule_spec = true does not enforce the advertised interface requirement: this legacy branch accepts arbitrary prose without running rulespec.problems(). Even input supplied through --when/--do is wrapped in the legacy date-prefix format instead of the interface format, so the newly added rule fails rule lint. Enforce the configured specification independently of whether topic headings exist, and use the interface bullet format when that mode is enabled.
Useful? React with 👍 / 👎.
… parses on Python 3.11; privacy scan skips merge commits CI on 3.11 refused `rule add --agent x "text"` (unrecognized arguments): a positional list after an action positional only parses intermixed on 3.12+. The scan now skips merge commits, which GitHub synthesizes for pull_request runs under the account name. Co-authored-by: Claude <[email protected]> Agent: claude-code
Co-authored-by: Claude <[email protected]> Agent: claude-code
feat: aisync 0.2.0, rules as interfaces loaded in layers, plus an MCP server
Rules:
rule add --when/--do/--notwrites a rule as an interface with astable ID;
rule_spec = truerefuses any other shape;rule lint,rule rewrite(refuses a rewrite that drops a path, number or command),rule enforcement(optional sidecar of what keeps each rule;require_enforcer = truemakes it mandatory),--topic,--replaceswith a rules archive.
rulecheckproves a cleanup lost no hard fact.Layers: a target with
layer = "core"carriescore_topicsin full andfolds the rest to one line each; the hook injects a folded topic once per
session when the prompt or a tool call touches its
[shelf]keywords.progress_filekeeps agents.md byte-stable so prompt caches keep hitting.Tidy:
aisync tidyproposes (duplicates, uncited rules, core budget) andnever edits; the daily run is off by default (
tidy_daily), never startsunder a test, runs one at a time, niced, and scans no transcripts unless
tidy_usage_globsis set.Any agent:
aisync mcpserves rules, rule_add, log, claim, release, news,status and tidy over stdio; the SDK is the optional
aisync[mcp]extra,the core stays standard-library only. Optional
instincthabit list.Release: CI runs pytest plus tools/privacy_scan.py (tree, wheel and the
commits since the last tag; guarded words kept as SHA-256 prefixes).
watch.restart() refuses to execv a test runner. Demo, board, front screen,
README (EN, ZH) and screenshot updated.
Co-authored-by: Claude [email protected]
Agent: claude-code
Checks before this PR: full suite on a fresh clone (241 passed with pytest and the mcp extra), tools/privacy_scan.py over the tree, wheel, sdist and the new commits: 0 hits.