principles 0.0.6 → 0.0.8
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +383 -0
- data/LICENSE +202 -0
- data/NOTICE +4 -0
- data/README.md +111 -0
- data/exe/principles +20 -0
- data/lib/principles/after_commit_hook_options.rb +2 -2
- data/lib/principles/cli.rb +58 -41
- data/lib/principles/command_line.rb +37 -14
- data/lib/principles/command_routes.rb +21 -7
- data/lib/principles/controllers/acknowledgement.rb +50 -118
- data/lib/principles/controllers/acknowledgements.rb +154 -0
- data/lib/principles/controllers/after_commit_report.rb +44 -0
- data/lib/principles/controllers/answer.rb +52 -21
- data/lib/principles/controllers/answer_phase.rb +20 -3
- data/lib/principles/controllers/assessment.rb +41 -28
- data/lib/principles/controllers/audit.rb +59 -15
- data/lib/principles/controllers/audit_completion.rb +25 -12
- data/lib/principles/controllers/command.rb +13 -12
- data/lib/principles/controllers/correction.rb +26 -11
- data/lib/principles/controllers/first_audit_brief.rb +40 -0
- data/lib/principles/controllers/full_audit_request.rb +47 -83
- data/lib/principles/controllers/hook_setup.rb +49 -0
- data/lib/principles/controllers/inventory.rb +10 -8
- data/lib/principles/controllers/mapping.rb +2 -2
- data/lib/principles/controllers/member_acknowledgement.rb +148 -0
- data/lib/principles/controllers/member_entries.rb +4 -4
- data/lib/principles/controllers/member_problems_report.rb +84 -30
- data/lib/principles/controllers/members_a_commit_changed.rb +3 -3
- data/lib/principles/controllers/members_to_assess.rb +23 -20
- data/lib/principles/controllers/meta_principle_setup.rb +5 -6
- data/lib/principles/controllers/open_correction.rb +42 -0
- data/lib/principles/controllers/parts_to_read.rb +117 -0
- data/lib/principles/controllers/repoint.rb +1 -1
- data/lib/principles/controllers/running_tool.rb +56 -6
- data/lib/principles/controllers/session_start_report.rb +62 -0
- data/lib/principles/controllers/survey.rb +2 -2
- data/lib/principles/data/audit_files.rb +7 -7
- data/lib/principles/data/bounded_file.rb +1 -1
- data/lib/principles/data/candidate_files_found.rb +6 -3
- data/lib/principles/data/command-steps.json +67 -12
- data/lib/principles/data/expected_type.rb +3 -3
- data/lib/principles/data/first_parent_log.rb +1 -1
- data/lib/principles/data/head_reflog.rb +74 -0
- data/lib/principles/data/hook_input.rb +59 -0
- data/lib/principles/data/ignored_by_git.rb +2 -2
- data/lib/principles/data/known_fields.rb +1 -1
- data/lib/principles/data/linked_path.rb +1 -1
- data/lib/principles/data/map_files.rb +2 -2
- data/lib/principles/data/principles_on_path.rb +83 -0
- data/lib/principles/data/principles_subfolder.rb +1 -1
- data/lib/principles/data/project_files.rb +10 -3
- data/lib/principles/data/repository.rb +14 -7
- data/lib/principles/data/running_version.rb +10 -8
- data/lib/principles/data/schema_check.rb +5 -5
- data/lib/principles/data/schemas/acknowledgement-answer.schema.json +86 -20
- data/lib/principles/data/schemas/acknowledgements-answer.schema.json +95 -0
- data/lib/principles/data/schemas/assessment-answer.schema.json +55 -20
- data/lib/principles/data/schemas/audit-record.schema.json +29 -20
- data/lib/principles/data/schemas/command-steps.schema.json +1 -1
- data/lib/principles/data/schemas/correction-answer-guide.schema.json +1 -1
- data/lib/principles/data/schemas/correction-answer.schema.json +14 -62
- data/lib/principles/data/schemas/member-map.schema.json +3 -3
- data/lib/principles/data/schemas/repointing-answer.schema.json +1 -1
- data/lib/principles/error.rb +4 -4
- data/lib/principles/failure_refusal.rb +57 -0
- data/lib/principles/invocation_options.rb +7 -6
- data/lib/principles/launch.rb +49 -0
- data/lib/principles/list_open_findings_options.rb +23 -0
- data/lib/principles/models/accepted_loading.rb +2 -2
- data/lib/principles/models/acknowledged_check.rb +106 -0
- data/lib/principles/models/acknowledgement.rb +51 -53
- data/lib/principles/models/acknowledgement_left_as_printed.rb +18 -5
- data/lib/principles/models/acknowledgement_refusal.rb +25 -10
- data/lib/principles/models/acknowledgements.rb +115 -0
- data/lib/principles/models/acknowledgements_across.rb +68 -0
- data/lib/principles/models/activation.rb +2 -2
- data/lib/principles/models/after_commit_input.rb +115 -0
- data/lib/principles/models/agent_loads.rb +1 -1
- data/lib/principles/models/answer_fields.rb +2 -2
- data/lib/principles/models/answer_place.rb +3 -3
- data/lib/principles/models/answer_text.rb +2 -2
- data/lib/principles/models/answered_time.rb +12 -3
- data/lib/principles/models/assessment_answer.rb +10 -10
- data/lib/principles/models/assessment_basis.rb +2 -2
- data/lib/principles/models/assessment_left_as_printed.rb +1 -1
- data/lib/principles/models/assessment_report.rb +14 -15
- data/lib/principles/models/audit.rb +46 -34
- data/lib/principles/models/audit_record.rb +58 -27
- data/lib/principles/models/audit_records.rb +13 -13
- data/lib/principles/models/audit_start.rb +3 -3
- data/lib/principles/models/audited_member_lines.rb +1 -1
- data/lib/principles/models/candidate_files.rb +18 -10
- data/lib/principles/models/candidate_inventory.rb +6 -6
- data/lib/principles/models/candidate_outline.rb +9 -9
- data/lib/principles/models/carried_assessments.rb +18 -3
- data/lib/principles/models/carried_member.rb +5 -5
- data/lib/principles/models/changed_regions.rb +92 -0
- data/lib/principles/models/check_result_guide.rb +50 -0
- data/lib/principles/models/check_since_last_audit.rb +5 -4
- data/lib/principles/models/cited_files.rb +4 -4
- data/lib/principles/models/command_steps.rb +3 -3
- data/lib/principles/models/commits_brought_in.rb +1 -1
- data/lib/principles/models/commits_since_base.rb +1 -1
- data/lib/principles/models/correction_answer.rb +2 -2
- data/lib/principles/models/correction_basis.rb +19 -10
- data/lib/principles/models/dated_line.rb +1 -2
- data/lib/principles/models/decided_prior_findings.rb +6 -6
- data/lib/principles/models/declared_map_changes.rb +5 -5
- data/lib/principles/models/disposition.rb +21 -21
- data/lib/principles/models/entry_file.rb +1 -1
- data/lib/principles/models/entry_files.rb +1 -1
- data/lib/principles/models/evidence_item.rb +1 -1
- data/lib/principles/models/evidence_lines_since.rb +2 -2
- data/lib/principles/models/evidence_replacements.rb +3 -3
- data/lib/principles/models/finding_write_ups.rb +12 -5
- data/lib/principles/models/findings_left_open.rb +4 -4
- data/lib/principles/models/first_full_audit.rb +32 -0
- data/lib/principles/models/first_raised_claim.rb +1 -1
- data/lib/principles/models/fix_only_fields.rb +1 -1
- data/lib/principles/models/head_moves.rb +66 -0
- data/lib/principles/models/hook_commands.rb +49 -4
- data/lib/principles/models/ignored_candidates.rb +1 -1
- data/lib/principles/models/instruction_named.rb +2 -3
- data/lib/principles/models/json_digest.rb +2 -2
- data/lib/principles/models/json_path_query.rb +1 -1
- data/lib/principles/models/kept_prior_finding.rb +9 -9
- data/lib/principles/models/last_completed_revision.rb +4 -5
- data/lib/principles/models/left_as_printed.rb +2 -2
- data/lib/principles/models/line_diff.rb +113 -0
- data/lib/principles/models/line_span.rb +1 -1
- data/lib/principles/models/list_member_problems_check.rb +80 -0
- data/lib/principles/models/listed_members.rb +47 -0
- data/lib/principles/models/loaded_files.rb +4 -5
- data/lib/principles/models/loading_decision.rb +19 -10
- data/lib/principles/models/loading_facts.rb +1 -1
- data/lib/principles/models/loads_to_check.rb +1 -2
- data/lib/principles/models/located_text.rb +1 -1
- data/lib/principles/models/mapped_principles.rb +2 -2
- data/lib/principles/models/member.rb +31 -4
- data/lib/principles/models/member_assessments.rb +17 -8
- data/lib/principles/models/member_elsewhere.rb +4 -4
- data/lib/principles/models/member_file.rb +4 -4
- data/lib/principles/models/member_grounds.rb +1 -1
- data/lib/principles/models/member_hashes_as_written.rb +1 -1
- data/lib/principles/models/member_lines.rb +29 -61
- data/lib/principles/models/member_loads.rb +2 -2
- data/lib/principles/models/member_moves.rb +1 -1
- data/lib/principles/models/member_problems.rb +21 -18
- data/lib/principles/models/member_repair_moves.rb +15 -9
- data/lib/principles/models/member_sighting.rb +12 -15
- data/lib/principles/models/member_snapshots.rb +1 -1
- data/lib/principles/models/member_state.rb +1 -1
- data/lib/principles/models/members_across_principles.rb +77 -0
- data/lib/principles/models/members_elsewhere.rb +2 -2
- data/lib/principles/models/members_sharing_lines.rb +7 -7
- data/lib/principles/models/meta_principle.rb +11 -4
- data/lib/principles/models/missing_files.rb +3 -3
- data/lib/principles/models/new_findings.rb +4 -4
- data/lib/principles/models/open_correction.rb +57 -0
- data/lib/principles/models/open_finding.rb +36 -31
- data/lib/principles/models/open_findings_elsewhere.rb +2 -2
- data/lib/principles/models/other_principles.rb +2 -2
- data/lib/principles/models/other_templates_placeholders.rb +17 -16
- data/lib/principles/models/outline_budget.rb +7 -7
- data/lib/principles/models/outline_group.rb +1 -1
- data/lib/principles/models/outline_section.rb +2 -2
- data/lib/principles/models/part_named.rb +41 -0
- data/lib/principles/models/placement.rb +2 -2
- data/lib/principles/models/principle.rb +13 -13
- data/lib/principles/models/principle_history.rb +8 -8
- data/lib/principles/models/principle_members.rb +14 -7
- data/lib/principles/models/principles_folder_move.rb +1 -1
- data/lib/principles/models/principles_on_path.rb +29 -0
- data/lib/principles/models/principles_package.rb +3 -3
- data/lib/principles/models/prior_decision_fields.rb +8 -8
- data/lib/principles/models/prior_finding_decision.rb +8 -8
- data/lib/principles/models/prior_finding_outcomes.rb +1 -1
- data/lib/principles/models/prior_findings.rb +5 -5
- data/lib/principles/models/problem_report.rb +42 -9
- data/lib/principles/models/project.rb +29 -20
- data/lib/principles/models/project_history.rb +18 -12
- data/lib/principles/models/quoted_change.rb +8 -8
- data/lib/principles/models/recent_decision.rb +3 -3
- data/lib/principles/models/record_format.rb +16 -10
- data/lib/principles/models/record_judged_against.rb +4 -4
- data/lib/principles/models/recorded_entry.rb +17 -8
- data/lib/principles/models/recorded_finding.rb +9 -9
- data/lib/principles/models/recorded_findings.rb +2 -2
- data/lib/principles/models/recorded_hashes.rb +2 -2
- data/lib/principles/models/recorded_members.rb +13 -13
- data/lib/principles/models/refusal_before_shape.rb +2 -2
- data/lib/principles/models/repoint.rb +3 -3
- data/lib/principles/models/report_hooks.rb +69 -0
- data/lib/principles/models/reported_check.rb +42 -36
- data/lib/principles/models/request_id.rb +19 -7
- data/lib/principles/models/runs_from.rb +7 -2
- data/lib/principles/models/sent_answer.rb +38 -16
- data/lib/principles/models/sent_prior_decisions.rb +1 -1
- data/lib/principles/models/session_start_input.rb +37 -0
- data/lib/principles/models/shape_problems_beside.rb +1 -1
- data/lib/principles/models/skill_loads.rb +1 -1
- data/lib/principles/models/stale_request.rb +59 -0
- data/lib/principles/models/still_holds_restatement.rb +6 -6
- data/lib/principles/models/submitted_answer.rb +1 -1
- data/lib/principles/models/template_placeholders.rb +6 -6
- data/lib/principles/models/text_within.rb +1 -1
- data/lib/principles/models/tracked_paths.rb +38 -0
- data/lib/principles/models/unchecked_members.rb +2 -2
- data/lib/principles/models/uncommitted_files.rb +1 -1
- data/lib/principles/models/uncommitted_outside_the_map.rb +2 -2
- data/lib/principles/models/waits_on.rb +1 -1
- data/lib/principles/models/write_up_opening.rb +5 -5
- data/lib/principles/models/write_up_pointer.rb +3 -3
- data/lib/principles/models/write_up_repoint.rb +2 -3
- data/lib/principles/positional_arguments.rb +15 -7
- data/lib/principles/prose_list.rb +1 -1
- data/lib/principles/session_start_options.rb +3 -3
- data/lib/principles/start_audit_options.rb +54 -12
- data/lib/principles/supported_ruby.rb +24 -7
- data/lib/principles/version.rb +2 -2
- data/lib/principles/views/acknowledged_since_last_audit.rb +2 -2
- data/lib/principles/views/acknowledgement_result.rb +137 -17
- data/lib/principles/views/activation_in_hand.rb +1 -1
- data/lib/principles/views/answered_request.rb +6 -2
- data/lib/principles/views/assessed_members.rb +68 -38
- data/lib/principles/views/assessment_request.rb +43 -21
- data/lib/principles/views/audit_changes.rb +4 -4
- data/lib/principles/views/audit_commit.rb +5 -4
- data/lib/principles/views/audit_result.rb +100 -53
- data/lib/principles/views/candidate_files_result.rb +7 -6
- data/lib/principles/views/check_notes.rb +29 -6
- data/lib/principles/views/check_result_template.rb +51 -39
- data/lib/principles/views/completed_audit_next_step.rb +44 -0
- data/lib/principles/views/context_parts.rb +112 -0
- data/lib/principles/views/correction_request.rb +49 -33
- data/lib/principles/views/diff_since_last_audit.rb +8 -6
- data/lib/principles/views/findings_result.rb +33 -1
- data/lib/principles/views/first_audit_brief.rb +51 -0
- data/lib/principles/views/first_audit_line.rb +45 -0
- data/lib/principles/views/help.rb +4 -4
- data/lib/principles/views/hook_setup_result.rb +91 -0
- data/lib/principles/views/instruction.rb +3 -3
- data/lib/principles/views/invocation.rb +32 -9
- data/lib/principles/views/json_with_entries_on_lines.rb +6 -35
- data/lib/principles/views/landed_since_base.rb +1 -1
- data/lib/principles/views/line_history_since_last_audit.rb +35 -0
- data/lib/principles/views/lines_shared_with_member.rb +6 -6
- data/lib/principles/views/loads_to_check_result.rb +11 -7
- data/lib/principles/views/map_added_to.rb +3 -3
- data/lib/principles/views/map_result.rb +9 -9
- data/lib/principles/views/member_change_since_baseline.rb +44 -23
- data/lib/principles/views/member_lines_beside_text.rb +43 -0
- data/lib/principles/views/member_repairs.rb +3 -2
- data/lib/principles/views/member_row.rb +61 -0
- data/lib/principles/views/members_a_commit_changed.rb +15 -11
- data/lib/principles/views/members_with_no_baseline.rb +10 -3
- data/lib/principles/views/meta_principle_passage.rb +1 -1
- data/lib/principles/views/meta_principle_result.rb +12 -5
- data/lib/principles/views/one_member_check_result_template.rb +24 -12
- data/lib/principles/views/open_findings_elsewhere_result.rb +5 -2
- data/lib/principles/views/open_findings_line.rb +26 -36
- data/lib/principles/views/other_principles_unjudged_result.rb +6 -3
- data/lib/principles/views/outside_the_map_result.rb +5 -2
- data/lib/principles/views/package_since_last_audit_result.rb +29 -6
- data/lib/principles/views/parts_index_result.rb +60 -0
- data/lib/principles/views/principle_read_result.rb +5 -6
- data/lib/principles/views/principle_with_changed_members.rb +1 -1
- data/lib/principles/views/principles_with_no_completed_audit.rb +1 -2
- data/lib/principles/views/printed_json.rb +51 -0
- data/lib/principles/views/printed_principle.rb +1 -1
- data/lib/principles/views/prior_finding_decisions_result.rb +4 -4
- data/lib/principles/views/prior_findings_result.rb +17 -14
- data/lib/principles/views/problem_lines.rb +70 -45
- data/lib/principles/views/problem_result.rb +75 -43
- data/lib/principles/views/prompts/acknowledge-a-change/judge-each-member-once-for-every-principle.md +2 -0
- data/lib/principles/views/prompts/acknowledge-a-change/read-the-deferred-findings-it-keeps.md +1 -0
- data/lib/principles/views/prompts/acknowledge-a-change/report-the-exit-status-its-own-listing-gives.md +3 -0
- data/lib/principles/views/prompts/acknowledge-a-change/resolve-them-in-a-full-audit.md +1 -0
- data/lib/principles/views/prompts/acknowledge-a-change/say-whether-each-change-keeps-its-meaning.md +8 -0
- data/lib/principles/views/prompts/acknowledge-a-change/say-whether-the-change-keeps-the-meaning.md +3 -3
- data/lib/principles/views/prompts/assess-every-member/confirm-each-write-up-pointer-the-answer-drops.md +2 -0
- data/lib/principles/views/prompts/assess-every-member/decide-each-member-loading.md +2 -1
- data/lib/principles/views/prompts/assess-every-member/have-a-changed-check-reviewed-before-running-it.md +1 -1
- data/lib/principles/views/prompts/assess-every-member/have-a-new-check-reviewed-before-running-it.md +1 -1
- data/lib/principles/views/prompts/assess-every-member/judge-a-carried-assessment-citing-a-decided-finding.md +3 -0
- data/lib/principles/views/prompts/assess-every-member/judge-a-submitted-carried-assessment-citing-a-decided-finding.md +5 -0
- data/lib/principles/views/prompts/assess-every-member/judge-the-keeping-under-the-release-since-the-last-audit.md +1 -1
- data/lib/principles/views/prompts/assess-every-member/keep-the-printed-review-basis-or-replace-it.md +1 -0
- data/lib/principles/views/prompts/assess-every-member/name-the-commit-that-made-the-check.md +1 -0
- data/lib/principles/views/prompts/assess-every-member/read-a-trimmed-instruction-whole.md +1 -1
- data/lib/principles/views/prompts/assess-every-member/read-the-request-in-parts.md +1 -0
- data/lib/principles/views/prompts/assess-every-member/run-the-check-then-report-it.md +2 -2
- data/lib/principles/views/prompts/assess-every-member/run-the-reviewed-check-and-say-what-its-review-rested-on.md +5 -3
- data/lib/principles/views/prompts/assess-every-member/why-each-member-is-judged-again.md +3 -2
- data/lib/principles/views/prompts/dispose-of-each-finding/answer-guide.json +1 -1
- data/lib/principles/views/prompts/dispose-of-each-finding/confirm-each-deferral-written-up-nowhere.md +2 -0
- data/lib/principles/views/prompts/dispose-of-each-finding/retain-assessment-and-correction.md +4 -4
- data/lib/principles/views/prompts/find-a-principle-to-map/where-the-inventory-looks.md +2 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/every-command-and-how-they-chain.md +1 -2
- data/lib/principles/views/prompts/learn-what-a-command-does/list-candidate-files.md +4 -3
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +16 -16
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +65 -61
- data/lib/principles/views/prompts/learn-what-a-command-does/report-after-commit.md +14 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/report-at-session-start.md +26 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-answer-check.md +22 -20
- data/lib/principles/views/prompts/learn-what-a-command-does/show-first-audit-brief.md +19 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-hook-setup.md +13 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/show-meta-principle-passage.md +3 -1
- data/lib/principles/views/prompts/learn-what-a-command-does/show-open-correction.md +12 -0
- data/lib/principles/views/prompts/learn-what-a-command-does/start-audit.md +27 -28
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +39 -38
- data/lib/principles/views/prompts/report-the-completed-audit/commit-only-what-the-audit-changed.md +2 -2
- data/lib/principles/views/prompts/run-a-first-audit-in-the-background/follow-the-brief.md +18 -0
- data/lib/principles/views/prompts/set-principles-up/offer-the-report-hooks.md +2 -0
- data/lib/principles/views/prompts/set-principles-up/wire-the-report-hooks-with-the-user.md +8 -0
- data/lib/principles/views/prompts/start-a-session/act-on-the-open-findings.md +3 -4
- data/lib/principles/views/prompts/start-a-session/every-loaded-line-costs-every-session.md +1 -0
- data/lib/principles/views/prompts/start-a-session/hand-the-first-audit-to-a-subagent.md +3 -0
- data/lib/principles/views/prompts/start-a-session/run-each-command-above.md +1 -0
- data/lib/principles/views/prompts/start-a-session/start-no-second-first-audit.md +2 -0
- data/lib/principles/views/prompts/start-a-session/start-with-the-principles-skill.md +1 -0
- data/lib/principles/views/prompts.rb +1 -1
- data/lib/principles/views/read_the_change.rb +36 -0
- data/lib/principles/views/record_waiting_on_an_upgrade.rb +2 -2
- data/lib/principles/views/repoint_result.rb +1 -1
- data/lib/principles/views/report_hooks_offer.rb +25 -0
- data/lib/principles/views/request_part.rb +5 -5
- data/lib/principles/views/request_parts.rb +1 -1
- data/lib/principles/views/session_start_report.rb +46 -0
- data/lib/principles/views/shell_word.rb +1 -1
- data/lib/principles/views/trimmed_instructions_note.rb +30 -0
- data/lib/principles/views/visible_text.rb +1 -1
- data/lib/principles/views/workflow_diagram.rb +1 -1
- data/principles.gemspec +44 -0
- metadata +95 -14
- data/lib/principles/views/prompts/start-a-session/it-returns-after-each-clear-or-compaction-too.md +0 -1
- data/lib/principles/views/prompts/start-a-session/it-returns-at-each-session-start.md +0 -1
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
module Principles
|
|
5
|
+
module Models
|
|
6
|
+
# The hooks that run this tool's two hook commands for a project without the principles plugin, on each host: the
|
|
7
|
+
# file the project's own hooks go in, and the command each event runs. Claude Code runs a hook after a failed shell
|
|
8
|
+
# call under an event of its own; Codex has none, its PostToolUse running after every call.
|
|
9
|
+
class ReportHooks
|
|
10
|
+
# One hook: the event that runs it, the matcher that picks which of the event's runs, and its command.
|
|
11
|
+
class Hook
|
|
12
|
+
#: String
|
|
13
|
+
attr_reader :event, :matcher, :command
|
|
14
|
+
|
|
15
|
+
#: (String, String, String) -> void
|
|
16
|
+
def initialize(event, matcher, command)
|
|
17
|
+
@event = event
|
|
18
|
+
@matcher = matcher
|
|
19
|
+
@command = command
|
|
20
|
+
freeze
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# One host's hooks: its name, the file they go in, from the project's root, the hooks, and why its block is
|
|
25
|
+
# offered, as a clause, unless the project holds folder, the host's own, when that is why.
|
|
26
|
+
class Host
|
|
27
|
+
#: String
|
|
28
|
+
attr_reader :name, :file
|
|
29
|
+
#: Array[Hook]
|
|
30
|
+
attr_reader :hooks
|
|
31
|
+
|
|
32
|
+
#: (String, String, Array[Hook], offered: String, ?folder: String?) -> void
|
|
33
|
+
def initialize(name, file, hooks, offered:, folder: nil)
|
|
34
|
+
@name = name
|
|
35
|
+
@file = file
|
|
36
|
+
@hooks = hooks.freeze #: Array[Hook]
|
|
37
|
+
@offered = offered
|
|
38
|
+
@folder = folder
|
|
39
|
+
freeze
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# Why its block is offered in project.
|
|
43
|
+
#: (Project) -> String
|
|
44
|
+
def offered_in(project)
|
|
45
|
+
folder = @folder
|
|
46
|
+
folder && project.folder?(folder) ? "since #{folder}/ exists in this project" : @offered
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# The hook at each session's start, from any source, and the one after each shell call.
|
|
51
|
+
SESSION_START = Hook.new("SessionStart", "startup|resume|clear|compact", "report-at-session-start") #: Hook
|
|
52
|
+
AFTER_A_CALL = Hook.new("PostToolUse", "Bash", "report-after-commit") #: Hook
|
|
53
|
+
|
|
54
|
+
# The commands the hooks run, once each.
|
|
55
|
+
COMMANDS = [SESSION_START.command, AFTER_A_CALL.command].freeze #: Array[String]
|
|
56
|
+
|
|
57
|
+
# Claude Code first, its file the gitignored local one, since a committed one would run for a teammate without
|
|
58
|
+
# this tool and fail every session start of theirs.
|
|
59
|
+
HOSTS = [
|
|
60
|
+
Host.new("Claude Code", ".claude/settings.local.json",
|
|
61
|
+
[SESSION_START, AFTER_A_CALL, Hook.new("PostToolUseFailure", "Bash", "report-after-commit")],
|
|
62
|
+
offered: "always, as the host this tool serves first"),
|
|
63
|
+
Host.new("Codex", ".codex/hooks.json", [SESSION_START, AFTER_A_CALL],
|
|
64
|
+
offered: "always, since this command does not tell which host runs this project's sessions",
|
|
65
|
+
folder: ".codex")
|
|
66
|
+
].freeze #: Array[Host]
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -4,42 +4,43 @@
|
|
|
4
4
|
require_relative "../error"
|
|
5
5
|
require_relative "answer_place"
|
|
6
6
|
require_relative "answer_text"
|
|
7
|
+
require_relative "check_result_guide"
|
|
7
8
|
require_relative "dated_line"
|
|
8
9
|
require_relative "template_placeholders"
|
|
9
10
|
|
|
10
11
|
module Principles
|
|
11
12
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
12
13
|
module Models
|
|
13
|
-
# One member's check and the result an agent reports for it
|
|
14
|
+
# One member's check and the result an agent reports for it. This tool never runs the check: it
|
|
14
15
|
# refuses a report that cannot be about the member's own check, and cannot confirm the run happened.
|
|
15
16
|
class ReportedCheck
|
|
16
|
-
SHAPES = "Merge one inner example from answer_guide.check_result.examples into that member's " \
|
|
17
|
-
"response_template.check_result as copy_from says."
|
|
18
17
|
# How review_basis records a review the agent made itself, which the placeholder and the repair both give.
|
|
19
18
|
SELF_REVIEWED = "\"Self-reviewed by the agent: <what you checked it against>\"" #: String
|
|
20
19
|
# The not_run_reason a template prints beside exit_status's placeholder, which an answer that leaves it as
|
|
21
|
-
# printed has not given, so filling exit_status alone reports a run
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
# printed has not given, so filling exit_status alone reports a run. Short, as the template's rule on
|
|
21
|
+
# fields left as printed says the rest.
|
|
22
|
+
NOT_RUN_PLACEHOLDER = "Only if the check could not run here: why" #: String
|
|
24
23
|
# The review_basis a template prints for a check no audit ran, or one changed since, which an exit_status needs
|
|
25
|
-
# beside it, and which beside not_run_reason left as printed is not given
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
"Leave this as printed only beside not_run_reason".freeze #: String
|
|
24
|
+
# beside it, and which beside not_run_reason left as printed is not given; what to write is the
|
|
25
|
+
# check's instruction.
|
|
26
|
+
REVIEW_BASIS_PLACEHOLDER = "One line: what the review before the run rested on" #: String
|
|
29
27
|
# Why an exit status for a check no audit ran is refused without review_basis, and when given its placeholder.
|
|
30
28
|
NEEDS_BASIS = "check_result needs review_basis beside exit_status, since no audit ran this command" #: String
|
|
31
29
|
LEFT_BASIS = "check_result.review_basis is the template's placeholder, unchanged, and an exit_status for a " \
|
|
32
30
|
"command no audit ran needs it" #: String
|
|
31
|
+
# The exit_status a template prints where the run's status goes, what to do being the check's instruction.
|
|
32
|
+
EXIT_STATUS_PLACEHOLDER = "the check's exit status, an integer" #: String
|
|
33
33
|
# The placeholder a template prints in each field an answer may leave as printed to give none.
|
|
34
|
-
PLACEHOLDERS = TemplatePlaceholders.new({ "
|
|
34
|
+
PLACEHOLDERS = TemplatePlaceholders.new({ "exit_status" => EXIT_STATUS_PLACEHOLDER,
|
|
35
|
+
"not_run_reason" => NOT_RUN_PLACEHOLDER,
|
|
35
36
|
"review_basis" => REVIEW_BASIS_PLACEHOLDER }) #: TemplatePlaceholders
|
|
36
37
|
# The review_basis a template prints for a check the last audit ran, which left as printed keeps the line that
|
|
37
|
-
# audit kept, and replaced gives a new one
|
|
38
|
-
KEPT_BASIS_PLACEHOLDER = "Only
|
|
39
|
-
"printed to keep the line the last audit kept, if any" #: String
|
|
38
|
+
# audit kept, and replaced gives a new one.
|
|
39
|
+
KEPT_BASIS_PLACEHOLDER = "Only for a new line on what this run's review rested on; else kept" #: String
|
|
40
40
|
# The placeholders a template prints for a check the last audit ran.
|
|
41
41
|
UNCHANGED_PLACEHOLDERS = TemplatePlaceholders.new(
|
|
42
|
-
{ "
|
|
42
|
+
{ "exit_status" => EXIT_STATUS_PLACEHOLDER, "not_run_reason" => NOT_RUN_PLACEHOLDER,
|
|
43
|
+
"review_basis" => KEPT_BASIS_PLACEHOLDER }
|
|
43
44
|
) #: TemplatePlaceholders
|
|
44
45
|
BASIS = "Say in review_basis, in one line, what the review before the run rested on, such as " \
|
|
45
46
|
"\"The owner reviewed the command in this session.\" or the document that confirms it. If you did " \
|
|
@@ -48,16 +49,18 @@ module Principles
|
|
|
48
49
|
"kept, say so, such as \"Reviewed in an earlier session; basis not kept.\"".freeze #: String
|
|
49
50
|
|
|
50
51
|
# assessment is the place of the member's assessment in the answer, whose check_result each refusal points
|
|
51
|
-
# into
|
|
52
|
+
# into. ran is the command the principle's stored record was given an exit status for, nil when it ran
|
|
52
53
|
# none; a check it did not run is reviewed before it runs, and the result says in review_basis what that review
|
|
53
|
-
# rested on
|
|
54
|
-
# review_basis_since, which an unchanged check's result carries until the answer gives another
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
# rested on. kept is the line the stored record keeps for that run's review, with its
|
|
55
|
+
# review_basis_since, which an unchanged check's result carries until the answer gives another. guide is
|
|
56
|
+
# the guidance the request prints, which each repair names.
|
|
57
|
+
#: (AnswerPlace, String, ran: String?, kept: Hash[String, untyped], ?guide: CheckResultGuide) -> void
|
|
58
|
+
def initialize(assessment, check, ran:, kept:, guide: CheckResultGuide::FULL_AUDIT)
|
|
57
59
|
@assessment = assessment
|
|
58
60
|
@check = check
|
|
59
61
|
@ran = ran
|
|
60
62
|
@kept = kept
|
|
63
|
+
@guide = guide
|
|
61
64
|
freeze
|
|
62
65
|
end
|
|
63
66
|
|
|
@@ -76,14 +79,18 @@ module Principles
|
|
|
76
79
|
private
|
|
77
80
|
|
|
78
81
|
# The fields reported gives, leaving out those the template left as printed: an exit_status still the
|
|
79
|
-
# placeholder string that says how to run the check, and each field as its placeholder
|
|
82
|
+
# placeholder string that says how to run the check, and each field as its placeholder; and a null
|
|
83
|
+
# not_run_reason, or a null review_basis but for an unchanged check's, whose null drops its kept line.
|
|
80
84
|
#: (Hash[String, untyped]) -> Hash[String, untyped]
|
|
81
85
|
def filled(reported)
|
|
82
|
-
placeholders.given(reported).reject
|
|
86
|
+
placeholders.given(reported).reject do |field, value|
|
|
87
|
+
(field == "exit_status" && value.is_a?(String)) ||
|
|
88
|
+
(value.nil? && (field == "not_run_reason" || (field == "review_basis" && @ran != @check)))
|
|
89
|
+
end
|
|
83
90
|
end
|
|
84
91
|
|
|
85
92
|
# The placeholders the template printed for this check: for one the stored record ran, a review_basis that
|
|
86
|
-
# left as printed keeps its line; for any other, one an exit_status needs replaced
|
|
93
|
+
# left as printed keeps its line; for any other, one an exit_status needs replaced.
|
|
87
94
|
#: () -> TemplatePlaceholders
|
|
88
95
|
def placeholders = @ran == @check ? UNCHANGED_PLACEHOLDERS : PLACEHOLDERS
|
|
89
96
|
|
|
@@ -99,9 +106,7 @@ module Principles
|
|
|
99
106
|
#: () -> bot
|
|
100
107
|
def missing_result
|
|
101
108
|
refuse(@assessment, "the member has a check, which context.members gives, so its assessment needs a " \
|
|
102
|
-
"check_result",
|
|
103
|
-
"Report the member's check once you have run it, after a review if " \
|
|
104
|
-
"answer_guide.check_result.limits asks for one. #{SHAPES}")
|
|
109
|
+
"check_result", @guide.missing)
|
|
105
110
|
end
|
|
106
111
|
|
|
107
112
|
#: (String) -> void
|
|
@@ -109,12 +114,11 @@ module Principles
|
|
|
109
114
|
return if command == @check
|
|
110
115
|
|
|
111
116
|
refuse(reported_at("command"), "check_result.command is not the member's check as context.members gives it",
|
|
112
|
-
|
|
113
|
-
"answer_guide.check_result.limits asks for one.")
|
|
117
|
+
@guide.command)
|
|
114
118
|
end
|
|
115
119
|
|
|
116
120
|
# Refuses a result that gives neither field but text in exit_status: the template's placeholder, or other text
|
|
117
|
-
# written where only the status goes, so the repair says what replaces it
|
|
121
|
+
# written where only the status goes, so the repair says what replaces it.
|
|
118
122
|
#: (Hash[String, untyped], Hash[String, untyped]) -> void
|
|
119
123
|
def unfilled_status(reported, given)
|
|
120
124
|
return if given.key?("exit_status") || given.key?("not_run_reason") || !reported["exit_status"].is_a?(String)
|
|
@@ -128,8 +132,7 @@ module Principles
|
|
|
128
132
|
def status_or_reason(reported)
|
|
129
133
|
unless reported.key?("exit_status") ^ reported.key?("not_run_reason")
|
|
130
134
|
refuse(reported_at, "check_result needs exactly one of exit_status and not_run_reason",
|
|
131
|
-
|
|
132
|
-
"no review it needed was possible. #{SHAPES}")
|
|
135
|
+
@guide.status_or_reason)
|
|
133
136
|
end
|
|
134
137
|
return if !reported.key?("not_run_reason") || AnswerText.new(reported["not_run_reason"]).written?
|
|
135
138
|
|
|
@@ -140,11 +143,11 @@ module Principles
|
|
|
140
143
|
# Refuses an exit status for a check the stored record did not run unless review_basis says what its review
|
|
141
144
|
# rested on, and any review_basis that is not one written line. What the line says is the agent's: this tool
|
|
142
145
|
# keeps it and cannot verify it. left says the template's placeholder was sent back in it, which the refusal
|
|
143
|
-
# names
|
|
146
|
+
# names.
|
|
144
147
|
#: (Hash[String, untyped], left: bool) -> void
|
|
145
148
|
def review_basis(reported, left:)
|
|
146
149
|
if reported.key?("review_basis")
|
|
147
|
-
return if AnswerText.new(reported["review_basis"]).one_line?
|
|
150
|
+
return if reported["review_basis"].nil? || AnswerText.new(reported["review_basis"]).one_line?
|
|
148
151
|
|
|
149
152
|
refuse(reported_at("review_basis"), "check_result.review_basis is not one written line", BASIS)
|
|
150
153
|
end
|
|
@@ -154,16 +157,19 @@ module Principles
|
|
|
154
157
|
end
|
|
155
158
|
|
|
156
159
|
# The result as the record keeps it: an unchanged check's exit status with the kept line and its date when the
|
|
157
|
-
# answer gives the same line or none, or the answer's new line alone;
|
|
160
|
+
# answer gives the same line or none, or the answer's new line alone; an unchanged check not run without the
|
|
161
|
+
# kept line, which its template prints; any other result as reported.
|
|
158
162
|
#: (Hash[String, untyped]) -> Hash[String, untyped]
|
|
159
163
|
def carrying_review(reported)
|
|
160
|
-
return reported unless
|
|
164
|
+
return reported unless @ran == @check
|
|
165
|
+
return reported.reject { |field, line| field == "review_basis" && line == @kept["review_basis"] } \
|
|
166
|
+
unless reported.key?("exit_status")
|
|
161
167
|
|
|
162
168
|
line = DatedLine.new(reported.fetch("review_basis", @kept["review_basis"]), field: "review_basis")
|
|
163
169
|
reported.except("review_basis").merge(line.kept_over(@kept))
|
|
164
170
|
end
|
|
165
171
|
|
|
166
|
-
# Refuses with what is wrong at place, which the refusal names with whose it is and points at
|
|
172
|
+
# Refuses with what is wrong at place, which the refusal names with whose it is and points at.
|
|
167
173
|
#: (AnswerPlace, String, String) -> bot
|
|
168
174
|
def refuse(place, message, repair)
|
|
169
175
|
raise place.refusal(Error.new("invalid_check_result", message, repair))
|
|
@@ -10,9 +10,9 @@ module Principles
|
|
|
10
10
|
# The id of a judgement request: the principle, the phase and a digest of everything the request
|
|
11
11
|
# depends on, as ID.PHASE.DIGEST. This tool stores no request, so an answer is matched by recomputing
|
|
12
12
|
# the digest from the project as it is now: a different digest means something the request depended
|
|
13
|
-
# on has changed
|
|
13
|
+
# on has changed. The digest has no secret, so it catches mistakes, not forgery.
|
|
14
14
|
class RequestId
|
|
15
|
-
PHASES = %w[assessment correction acknowledgement repointing].freeze
|
|
15
|
+
PHASES = %w[assessment correction acknowledgement acknowledgements repointing].freeze
|
|
16
16
|
FORMAT = /\A(?<principle>[a-z0-9]+(?:-[a-z0-9]+)*)\.(?<phase>[a-z]+)\.(?<digest>[0-9a-f]{12})\z/
|
|
17
17
|
|
|
18
18
|
#: String
|
|
@@ -21,7 +21,7 @@ module Principles
|
|
|
21
21
|
attr_reader :phase
|
|
22
22
|
|
|
23
23
|
# The id of a request in phase for principle_id, which depends on parts, digested by what they say, so an answer
|
|
24
|
-
# whose keys are reordered, as `jq -S` does, still matches
|
|
24
|
+
# whose keys are reordered, as `jq -S` does, still matches.
|
|
25
25
|
#: (principle_id: String, phase: String, parts: Array[untyped]) -> RequestId
|
|
26
26
|
def self.for(principle_id:, phase:, parts:)
|
|
27
27
|
new(principle_id, phase, JsonDigest.new([principle_id, phase, *parts]).to_s[0, 12].to_s)
|
|
@@ -29,13 +29,17 @@ module Principles
|
|
|
29
29
|
|
|
30
30
|
# The id of a request whose answer hands part of it back: its digest's first half digests what is handed back
|
|
31
31
|
# alone and its second the parts this tool recomputes, so an answer that edited what it hands back is told apart
|
|
32
|
-
# from a project that changed
|
|
32
|
+
# from a project that changed.
|
|
33
33
|
#: (principle_id: String, phase: String, handed: untyped, parts: Array[untyped]) -> RequestId
|
|
34
34
|
def self.handing_back(principle_id:, phase:, handed:, parts:)
|
|
35
35
|
half = ->(digested) { JsonDigest.new([principle_id, phase, digested]).to_s[0, 6].to_s }
|
|
36
36
|
new(principle_id, phase, half.call(handed) + half.call(parts))
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
# What every id of a request in phase for principle_id starts with, before its digest.
|
|
40
|
+
#: (principle_id: String, phase: String) -> String
|
|
41
|
+
def self.prefix(principle_id:, phase:) = "#{principle_id}.#{phase}."
|
|
42
|
+
|
|
39
43
|
# An id as an agent passed it, refused unless it has the shape this tool prints.
|
|
40
44
|
#: (String) -> RequestId
|
|
41
45
|
def self.parse(text)
|
|
@@ -61,8 +65,16 @@ module Principles
|
|
|
61
65
|
def check_answer(answer)
|
|
62
66
|
return if answer.is_a?(Hash) && answer["request_id"] == to_s
|
|
63
67
|
|
|
64
|
-
raise Error.new("request_mismatch", "answer.request_id must equal #{self}",
|
|
65
|
-
|
|
68
|
+
raise Error.new("request_mismatch", "answer.request_id must equal #{self}", "Start from #{answer_to_fill}.")
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# Where the answer to fill this request is printed, as a repair names it: a correction request prints none, since
|
|
72
|
+
# show-open-correction prints it alone; every other request prints it as its response_template.
|
|
73
|
+
#: () -> String
|
|
74
|
+
def answer_to_fill
|
|
75
|
+
return "the response_template of this request" unless @phase == "correction"
|
|
76
|
+
|
|
77
|
+
"the answer show-open-correction #{@principle_id} prints"
|
|
66
78
|
end
|
|
67
79
|
|
|
68
80
|
# What of a handing_back id differs in other: :handed, what the answer hands back, before :parts, what this tool
|
|
@@ -78,7 +90,7 @@ module Principles
|
|
|
78
90
|
|
|
79
91
|
#: () -> String
|
|
80
92
|
def to_s
|
|
81
|
-
"#{@principle_id
|
|
93
|
+
"#{RequestId.prefix(principle_id: @principle_id, phase: @phase)}#{@digest}"
|
|
82
94
|
end
|
|
83
95
|
|
|
84
96
|
#: (untyped) -> bool
|
|
@@ -6,8 +6,8 @@ module Principles
|
|
|
6
6
|
module Models
|
|
7
7
|
# Where this run of the tool comes from, by the executable its printed commands name. The Claude Code plugin's
|
|
8
8
|
# bin/principles is the one entry point that names itself bare, since its folder is on the Bash tool's PATH
|
|
9
|
-
# while the plugin is enabled
|
|
10
|
-
# plugin does its session-start hook report beside CLAUDE.md
|
|
9
|
+
# while the plugin is enabled; a checkout or an installed gem names a Ruby and a path. Only under the
|
|
10
|
+
# plugin does its session-start hook report beside CLAUDE.md.
|
|
11
11
|
class RunsFrom
|
|
12
12
|
# The executable the plugin's entry point names itself by.
|
|
13
13
|
PLUGIN_EXECUTABLE = "principles"
|
|
@@ -27,6 +27,11 @@ module Principles
|
|
|
27
27
|
#: () -> bool
|
|
28
28
|
def session_start_hook_in_this_session? = plugin?
|
|
29
29
|
|
|
30
|
+
# Whether the principles skill, /principles, is installed for the session this run is part of, which only the
|
|
31
|
+
# plugin installs; an installed gem or a checkout has none.
|
|
32
|
+
#: () -> bool
|
|
33
|
+
def principles_skill_in_this_session? = plugin?
|
|
34
|
+
|
|
30
35
|
private
|
|
31
36
|
|
|
32
37
|
#: () -> bool
|
|
@@ -5,40 +5,62 @@ require_relative "../data/schema_check"
|
|
|
5
5
|
require_relative "../data/project_files"
|
|
6
6
|
require_relative "../error"
|
|
7
7
|
require_relative "refusal_before_shape"
|
|
8
|
+
require_relative "request_id"
|
|
8
9
|
|
|
9
10
|
module Principles
|
|
10
11
|
module Models
|
|
11
12
|
# An answer an agent sent for a phase's request, read from its source, whose head, the fields every answer hands
|
|
12
|
-
# back as its request printed them, is checked on arrival: they say whether it still answers that request
|
|
13
|
-
#
|
|
14
|
-
# the phase's schema
|
|
13
|
+
# back as its request printed them, is checked on arrival: they say whether it still answers that request.
|
|
14
|
+
# The rest is checked only once that request is known, against the placeholders its template printed and
|
|
15
|
+
# the phase's schema.
|
|
15
16
|
class SentAnswer
|
|
16
17
|
HEAD = %w[request_id basis].freeze #: Array[String]
|
|
17
18
|
|
|
18
19
|
# What a refusal's message calls the answer: the agent holds its file's path, which cost context in every
|
|
19
|
-
# repair
|
|
20
|
+
# repair.
|
|
20
21
|
NAMED = "The answer" #: String
|
|
21
|
-
# What a refusal to read its file calls that file
|
|
22
|
+
# What a refusal to read its file calls that file.
|
|
22
23
|
FILE_NAMED = "The answer file" #: String
|
|
23
24
|
|
|
25
|
+
# The repair of a field-by-field shape refusal for a phase that prints its answer to fill as response_template,
|
|
26
|
+
# such as the acknowledgements phase, whose controller refuses its own fields.
|
|
24
27
|
REPAIR = "Repair each field listed, starting from the request's response_template." #: String
|
|
25
28
|
|
|
26
|
-
# The answer read from the file or stdin the agent named,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
# The answer read from the file or stdin the agent named, to the request given, the REQUEST_ID the agent typed,
|
|
30
|
+
# or when it typed none the request_id the answer names, as its template printed it, using that request's
|
|
31
|
+
# phase's schema.
|
|
32
|
+
#: (Data::ProjectFiles, String, stdin: String?, given: String?) -> SentAnswer
|
|
33
|
+
def self.read(files, file, stdin:, given:)
|
|
29
34
|
parsed = if file == "-" then files.parse_json(stdin.to_s, "-", named: NAMED)
|
|
30
35
|
else files.read_json(file, named: FILE_NAMED)
|
|
31
36
|
end
|
|
32
|
-
new(parsed, file,
|
|
37
|
+
new(parsed, file, RequestId.parse(given || named_request(parsed)))
|
|
33
38
|
end
|
|
34
39
|
|
|
35
|
-
#
|
|
36
|
-
#: (untyped
|
|
37
|
-
def
|
|
40
|
+
# The request_id the answer names, refused when it names none, since no REQUEST_ID was typed either.
|
|
41
|
+
#: (untyped) -> String
|
|
42
|
+
def self.named_request(parsed)
|
|
43
|
+
named = parsed["request_id"] if parsed.is_a?(Hash)
|
|
44
|
+
return named if named.is_a?(String)
|
|
45
|
+
|
|
46
|
+
raise Error.new("unknown_request", "#{NAMED} names no request_id, and no REQUEST_ID was given",
|
|
47
|
+
"Keep in the answer the request_id its template printed, or give it as REQUEST_ID.")
|
|
48
|
+
end
|
|
49
|
+
private_class_method :named_request
|
|
50
|
+
|
|
51
|
+
#: RequestId
|
|
52
|
+
attr_reader :request_id
|
|
53
|
+
|
|
54
|
+
# parsed is the answer as its source, a file or - for stdin, holds it, to request_id, whose phase's answer schema
|
|
55
|
+
# it is checked against.
|
|
56
|
+
#: (untyped, String, RequestId) -> void
|
|
57
|
+
def initialize(parsed, source, request_id)
|
|
38
58
|
@parsed = parsed
|
|
39
59
|
@source = source
|
|
40
|
-
@
|
|
41
|
-
check.
|
|
60
|
+
@request_id = request_id
|
|
61
|
+
@check = Data::SchemaCheck.new("#{request_id.phase}-answer") #: Data::SchemaCheck
|
|
62
|
+
@repair = "Repair each field listed, starting from #{request_id.answer_to_fill}." #: String
|
|
63
|
+
@check.only(HEAD).checked(parsed, code: "invalid_answer", source: source, repair: @repair, named: NAMED)
|
|
42
64
|
freeze
|
|
43
65
|
end
|
|
44
66
|
|
|
@@ -49,12 +71,12 @@ module Principles
|
|
|
49
71
|
# The whole answer, once each refusal its request's rules make before its shape, in order, then its shape, is
|
|
50
72
|
# checked: such as a stray check_result on a member with no check, a field holding a placeholder its
|
|
51
73
|
# request's template did not print, and a one-member audit's field left as its template printed it, each handed
|
|
52
|
-
# the shape's problems to name beside its own
|
|
74
|
+
# the shape's problems to name beside its own.
|
|
53
75
|
#: (Array[RefusalBeforeShape]) -> untyped
|
|
54
76
|
def checked(before_shape)
|
|
55
77
|
shape_problems = @check.problems(@parsed)
|
|
56
78
|
before_shape.each { |refusal| refusal.refuse_in(@parsed, @source, shape_problems) }
|
|
57
|
-
@check.checked(@parsed, code: "invalid_answer", source: @source, repair:
|
|
79
|
+
@check.checked(@parsed, code: "invalid_answer", source: @source, repair: @repair, named: NAMED)
|
|
58
80
|
end
|
|
59
81
|
end
|
|
60
82
|
end
|
|
@@ -8,7 +8,7 @@ module Principles
|
|
|
8
8
|
module Models
|
|
9
9
|
# An assessment answer's prior_finding_decisions as sent, before each is checked against the finding it decides:
|
|
10
10
|
# a decision still the placeholder start-audit --as template printed is no decision, so the answer's one refusal
|
|
11
|
-
# names it with every other judgement left so
|
|
11
|
+
# names it with every other judgement left so.
|
|
12
12
|
class SentPriorDecisions
|
|
13
13
|
# decisions is the answer's prior_finding_decisions as sent, a list.
|
|
14
14
|
#: (Array[untyped]) -> void
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "json"
|
|
5
|
+
|
|
6
|
+
module Principles
|
|
7
|
+
module Models
|
|
8
|
+
# The JSON a SessionStart hook is given on stdin, as far as report-at-session-start reads it: the source the
|
|
9
|
+
# session started from. Input that is not JSON, or names no source a host sends, reads as a startup, since a
|
|
10
|
+
# hook reports what it can rather than refuse.
|
|
11
|
+
class SessionStartInput
|
|
12
|
+
# The sources a SessionStart hook names.
|
|
13
|
+
SOURCES = %w[startup resume clear compact].freeze #: Array[String]
|
|
14
|
+
|
|
15
|
+
# The source the session started from: startup, resume, clear or compact.
|
|
16
|
+
#: String
|
|
17
|
+
attr_reader :source
|
|
18
|
+
|
|
19
|
+
#: (String) -> void
|
|
20
|
+
def initialize(text)
|
|
21
|
+
given = parsed(text)
|
|
22
|
+
given = given["source"] if given.is_a?(Hash)
|
|
23
|
+
@source = SOURCES.include?(given) ? given.to_s : "startup" #: String
|
|
24
|
+
freeze
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
private
|
|
28
|
+
|
|
29
|
+
#: (String) -> untyped
|
|
30
|
+
def parsed(text)
|
|
31
|
+
JSON.parse(text)
|
|
32
|
+
rescue JSON::ParserError
|
|
33
|
+
nil
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -5,7 +5,7 @@ module Principles
|
|
|
5
5
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
6
6
|
module Models
|
|
7
7
|
# The problems an answer's shape has beside those a refusal before the shape names, which that refusal names too,
|
|
8
|
-
# so one refusal lists every repair
|
|
8
|
+
# so one refusal lists every repair, and says so in its message, which an agent reads first.
|
|
9
9
|
class ShapeProblemsBeside
|
|
10
10
|
# What the message adds when there are any.
|
|
11
11
|
MESSAGE = ", and fields not in the shape this tool reads" #: String
|
|
@@ -11,7 +11,7 @@ module Principles
|
|
|
11
11
|
# When Claude Code loads a skill: its body when the skill is invoked, and its description, which tells the
|
|
12
12
|
# model the skill exists, at session start, on the files its paths field names, or, for a skill in a folder
|
|
13
13
|
# below the project root, when a file there is first touched. A skill only a person invokes puts nothing in
|
|
14
|
-
# the model's context until they do. This follows Claude Code's skills documentation
|
|
14
|
+
# the model's context until they do. This follows Claude Code's skills documentation.
|
|
15
15
|
# This tool shows the paths field as written, and reads disable-model-invocation only as a plain true or false.
|
|
16
16
|
class SkillLoads
|
|
17
17
|
# A skill's own file: SKILL.md in a skill's folder in a .claude/skills folder, at the root or below it.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# typed: strict
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative "../error"
|
|
5
|
+
require_relative "../prose_list"
|
|
6
|
+
require_relative "request_id"
|
|
7
|
+
|
|
8
|
+
module Principles
|
|
9
|
+
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
10
|
+
module Models
|
|
11
|
+
# The refusal of an answer to one principle's audit request that no longer matches the project: its cause, the
|
|
12
|
+
# members changed since the request's base commit when any are known, or else every input the request depends on,
|
|
13
|
+
# and its repair: to answer the audit's open correction when members alone changed, or else to start again.
|
|
14
|
+
class StaleRequest
|
|
15
|
+
# principle_id is the principle audited; changed names the members whose text differs from the base commit's;
|
|
16
|
+
# correction_open says whether the principle's record is open, its correction asked for and not yet answered.
|
|
17
|
+
#: (String, ?Array[String], ?correction_open: bool) -> void
|
|
18
|
+
def initialize(principle_id, changed = [], correction_open: false)
|
|
19
|
+
@principle_id = principle_id
|
|
20
|
+
@changed = changed
|
|
21
|
+
@correction_open = correction_open
|
|
22
|
+
freeze
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
#: () -> Error
|
|
26
|
+
def refusal
|
|
27
|
+
Error.new("stale_request", "This request no longer matches #{@principle_id}: #{cause}", repair)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
private
|
|
31
|
+
|
|
32
|
+
# The members changed since the base commit, which a request is printed only once they are committed; otherwise
|
|
33
|
+
# every input that may have changed.
|
|
34
|
+
#: () -> String
|
|
35
|
+
def cause
|
|
36
|
+
unless @changed.empty?
|
|
37
|
+
return "#{ProseList.new(@changed)} #{@changed.one? ? "has" : "have"} changed since its base commit"
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
"its map, a member, the commit it was based on, or what says when a listed member loads and how big it is " \
|
|
41
|
+
"(project settings, frontmatter or a listed file), has changed since it was printed, or another release " \
|
|
42
|
+
"or checkout of principles printed it"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# To start the audit again; but while its correction is open and only members changed, that correction stays
|
|
46
|
+
# answerable, since it is checked against the members at the base commit, so the repair names the command that
|
|
47
|
+
# prints its answer again from the open record.
|
|
48
|
+
#: () -> String
|
|
49
|
+
def repair
|
|
50
|
+
start = "#{Error::EXECUTABLE} start-audit #{@principle_id}"
|
|
51
|
+
return "Start the audit again and answer the new request: #{start}" unless @correction_open && @changed.any?
|
|
52
|
+
|
|
53
|
+
"This audit's correction is still open, and fixing members leaves it current: answer it rather than start " \
|
|
54
|
+
"again, saving its answer from this command's output, filling only its dispositions, and submitting it: " \
|
|
55
|
+
"#{Error::EXECUTABLE} show-open-correction #{@principle_id}"
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -11,8 +11,8 @@ module Principles
|
|
|
11
11
|
# The domain logic, and the mediation of persistence. models/CLAUDE.md owns the boundary.
|
|
12
12
|
module Models
|
|
13
13
|
# What a decision on a prior finding restates of that finding, which only a still_holds decision may: its
|
|
14
|
-
# problem, which its record may lack
|
|
15
|
-
#
|
|
14
|
+
# problem, which its record may lack, a new pointer to its write-up, the evidence its record lacks
|
|
15
|
+
# and a new place for each kept evidence item no longer found.
|
|
16
16
|
# PriorFindingDecision checks the rest of the decision, and refuses for this through refuse.
|
|
17
17
|
class StillHoldsRestatement
|
|
18
18
|
# finding is the prior finding as its record left it open; place is the decision's place in the answer; refuse
|
|
@@ -46,9 +46,9 @@ module Principles
|
|
|
46
46
|
|
|
47
47
|
private
|
|
48
48
|
|
|
49
|
-
# The evidence a still_holds decision may give: a finding whose record keeps none, its evidence
|
|
49
|
+
# The evidence a still_holds decision may give: a finding whose record keeps none, its evidence, and one
|
|
50
50
|
# whose record keeps it, the new place of each kept item no longer found, which EvidenceReplacements checks, so a
|
|
51
|
-
# decision never rewrites what an audit found
|
|
51
|
+
# decision never rewrites what an audit found. This checks only that each pointer resolves.
|
|
52
52
|
#: (^(Locator) -> void) -> void
|
|
53
53
|
def evidence(locate)
|
|
54
54
|
unless @decision["decision"] == "still_holds"
|
|
@@ -63,7 +63,7 @@ module Principles
|
|
|
63
63
|
lacking(locate, place)
|
|
64
64
|
end
|
|
65
65
|
|
|
66
|
-
# The evidence a decision gives a finding whose record keeps none, which has nothing to replace
|
|
66
|
+
# The evidence a decision gives a finding whose record keeps none, which has nothing to replace.
|
|
67
67
|
#: (^(Locator) -> void, AnswerPlace) -> void
|
|
68
68
|
def lacking(locate, place)
|
|
69
69
|
given = @decision["problem_evidence"]
|
|
@@ -74,7 +74,7 @@ module Principles
|
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
# The problem its record lacks, or a restatement of the one it states when a term in it was renamed or a fact it
|
|
77
|
-
# names moved, which keeps the finding's id and first_raised_at
|
|
77
|
+
# names moved, which keeps the finding's id and first_raised_at.
|
|
78
78
|
#: () -> void
|
|
79
79
|
def problem
|
|
80
80
|
@refuse.call("problem must be one line", nil) unless AnswerText.new(@decision["problem"]).one_line?
|
|
@@ -8,7 +8,7 @@ module Principles
|
|
|
8
8
|
# The domain logic, which loads and saves itself through data/. models/CLAUDE.md owns the boundary.
|
|
9
9
|
module Models
|
|
10
10
|
# An answer submitted to the request request_id names, its shape checked, with the prior findings a full
|
|
11
|
-
# audit's request listed, which checking its head found
|
|
11
|
+
# audit's request listed, which checking its head found, or nil for any other phase.
|
|
12
12
|
class SubmittedAnswer
|
|
13
13
|
#: RequestId
|
|
14
14
|
attr_reader :request_id
|