principles 0.0.7 → 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 +50 -42
- data/lib/principles/command_line.rb +22 -16
- data/lib/principles/command_routes.rb +20 -6
- data/lib/principles/controllers/acknowledgement.rb +29 -74
- data/lib/principles/controllers/acknowledgements.rb +154 -0
- data/lib/principles/controllers/after_commit_report.rb +44 -0
- data/lib/principles/controllers/answer.rb +48 -18
- data/lib/principles/controllers/answer_phase.rb +20 -3
- data/lib/principles/controllers/assessment.rb +32 -11
- data/lib/principles/controllers/audit.rb +43 -19
- data/lib/principles/controllers/audit_completion.rb +21 -12
- data/lib/principles/controllers/command.rb +13 -12
- data/lib/principles/controllers/correction.rb +15 -7
- data/lib/principles/controllers/first_audit_brief.rb +40 -0
- data/lib/principles/controllers/full_audit_request.rb +41 -82
- 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 +32 -21
- data/lib/principles/controllers/member_entries.rb +4 -4
- data/lib/principles/controllers/member_problems_report.rb +62 -16
- 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 +61 -6
- 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 -21
- data/lib/principles/data/schemas/acknowledgements-answer.schema.json +9 -2
- data/lib/principles/data/schemas/assessment-answer.schema.json +43 -22
- 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 +9 -9
- 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 +4 -4
- data/lib/principles/launch.rb +49 -0
- data/lib/principles/list_open_findings_options.rb +1 -1
- data/lib/principles/models/accepted_loading.rb +2 -2
- data/lib/principles/models/acknowledged_check.rb +23 -11
- data/lib/principles/models/acknowledgement.rb +34 -18
- data/lib/principles/models/acknowledgement_left_as_printed.rb +7 -15
- data/lib/principles/models/acknowledgement_refusal.rb +25 -10
- data/lib/principles/models/acknowledgements.rb +45 -29
- 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 +4 -4
- 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 +6 -7
- data/lib/principles/models/audit.rb +33 -34
- data/lib/principles/models/audit_record.rb +54 -28
- 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 +7 -7
- 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 +4 -4
- data/lib/principles/models/listed_members.rb +7 -9
- data/lib/principles/models/loaded_files.rb +4 -5
- data/lib/principles/models/loading_decision.rb +3 -3
- data/lib/principles/models/loading_facts.rb +1 -1
- data/lib/principles/models/loads_to_check.rb +1 -1
- 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 +8 -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 +14 -15
- data/lib/principles/models/member_repair_moves.rb +15 -9
- data/lib/principles/models/member_sighting.rb +10 -10
- 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 +26 -8
- data/lib/principles/models/project.rb +27 -19
- 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 +34 -31
- data/lib/principles/models/request_id.rb +18 -6
- data/lib/principles/models/runs_from.rb +7 -2
- data/lib/principles/models/sent_answer.rb +14 -12
- 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 +13 -6
- data/lib/principles/prose_list.rb +1 -1
- data/lib/principles/session_start_options.rb +1 -1
- data/lib/principles/start_audit_options.rb +46 -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 +97 -11
- 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 +50 -41
- data/lib/principles/views/assessment_request.rb +39 -36
- 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 +92 -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 +45 -34
- 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 +44 -25
- data/lib/principles/views/diff_since_last_audit.rb +8 -6
- data/lib/principles/views/findings_result.rb +17 -6
- 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 +14 -6
- 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 +8 -5
- 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 +2 -2
- data/lib/principles/views/members_a_commit_changed.rb +13 -10
- data/lib/principles/views/members_with_no_baseline.rb +3 -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 +7 -7
- data/lib/principles/views/open_findings_elsewhere_result.rb +5 -2
- data/lib/principles/views/open_findings_line.rb +25 -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 +39 -17
- data/lib/principles/views/problem_result.rb +40 -37
- 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/resolve-them-in-a-full-audit.md +1 -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/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/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/list-candidate-files.md +4 -3
- data/lib/principles/views/prompts/learn-what-a-command-does/list-member-problems.md +6 -6
- data/lib/principles/views/prompts/learn-what-a-command-does/list-open-findings.md +11 -11
- 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 +20 -18
- 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 +21 -22
- data/lib/principles/views/prompts/learn-what-a-command-does/submit-answer.md +5 -4
- 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 -1
- 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.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 +83 -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
data/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright 2026 Sidu Ponnappa and Ontic Pte. Ltd. (realfast.ai)
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
data/NOTICE
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# Principles
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/rb/principles)
|
|
4
|
+
|
|
5
|
+
**Tighter harness, longer leash: agents you can leave running.**
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Install the gem yourself. In Claude Code, the `!` prefix runs a shell command in your session:
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
! gem install principles
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Then ask your agent to map your project's principles. It runs `principles list-principles` and follows what each result tells it, so you never need to learn the commands. `principles` needs Ruby 3.4, and finds one installed by rbenv when the Ruby on your `PATH` is another version.
|
|
16
|
+
|
|
17
|
+
## The problem: harness drift
|
|
18
|
+
|
|
19
|
+
Your agent works the way its harness tells it to: `CLAUDE.md` files, rules, skills, subagents, hooks and the scripts they call. A team's operating principles, such as test first or never commit on a red build, each end up written in several of those files.
|
|
20
|
+
|
|
21
|
+
Then someone sharpens a rule in `CLAUDE.md` but not in the reviewer subagent. Every file still loads and nothing errors, but your agent now reads instructions that disagree. That is **drift**. Left to pile up, it becomes **debt**: the same rule at different strengths, stale exceptions, checks nobody remembers adding. No review catches it, because each edit looks fine on its own. The problem lives between the files.
|
|
22
|
+
|
|
23
|
+
## What `principles` does
|
|
24
|
+
|
|
25
|
+
- **Finds the principles you already have.** It surveys your guidance and shows which principles it carries, and where.
|
|
26
|
+
- **Maps each one.** A map names every place that carries a principle, and the part each place plays.
|
|
27
|
+
- **Catches drift.** `principles list-member-problems --short` names each mapped place that changed since its last audit, in a few lines made for a session-start hook.
|
|
28
|
+
- **Audits the places together.** Your agent judges whether they still agree. `principles` checks that every passage it cites exists, and records the result.
|
|
29
|
+
- **Makes debt deliberate.** Each finding is fixed, or recorded with whom it waits on.
|
|
30
|
+
- **Shows what to trim.** It points out rules stated twice, or loaded into every session when only some tasks need them.
|
|
31
|
+
|
|
32
|
+
`principles` never edits your harness and calls no model. Your agent reads and judges; `principles` keeps the books: what is mapped, what changed and which step comes next. Every result is JSON that names the next command. Maps and audits live in `.principles/`, committed beside your code, so your team shares them and their history.
|
|
33
|
+
|
|
34
|
+
## Why it matters
|
|
35
|
+
|
|
36
|
+
An agent working unsupervised is only as good as the guidance in its context, and nobody is watching when that guidance is wrong.
|
|
37
|
+
|
|
38
|
+
- **Context efficiency.** Every line the harness loads costs the agent attention, in every session it loads in. Mapping each principle shows where it is stated twice, stated stale, or loaded where it is never needed, so that text can be cut.
|
|
39
|
+
- **Context relevant to the task.** A principle can record when its work is in hand, such as only while specs are written. An audit then flags each place that loads into every session anyway.
|
|
40
|
+
- **No silent drift, no growing debt.** Each change to a mapped place is caught and checked against the others.
|
|
41
|
+
|
|
42
|
+
Together these lengthen the time, and widen the kinds of work, for which you can leave an agent running and still get great work.
|
|
43
|
+
|
|
44
|
+
## Example: one rename, three files
|
|
45
|
+
|
|
46
|
+
A project states its naming rule in three places:
|
|
47
|
+
|
|
48
|
+
```markdown
|
|
49
|
+
<!-- CLAUDE.md -->
|
|
50
|
+
Name every file and function for what it is. When a term changes, rename it everywhere in the same commit.
|
|
51
|
+
Settled terms live in `docs/glossary.md`.
|
|
52
|
+
|
|
53
|
+
<!-- docs/glossary.md -->
|
|
54
|
+
- **order**: a customer's request to buy, before payment.
|
|
55
|
+
|
|
56
|
+
<!-- .claude/agents/reviewer.md -->
|
|
57
|
+
Reject a term that is not in `docs/glossary.md`.
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
A teammate renames "order" to "basket" in the glossary alone. The one-line diff looks fine, but the reviewer will now reject every `order` left in the code. At the start of the next session, the agent runs:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
principles list-member-problems --short
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
```text
|
|
67
|
+
express-intent docs/glossary.md e6aabd6 Rename order to basket audit
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`principles start-audit express-intent` hands the agent all three places together. It reports the contradiction, citing each passage, and either finishes the rename or records an open finding. The audit is a file you commit: `.principles/audits/express-intent.json`. A typo fix costs less: the agent acknowledges that one place, saying in a line why its meaning is unchanged.
|
|
71
|
+
|
|
72
|
+
## One principle, many places
|
|
73
|
+
|
|
74
|
+
Take express intent: every name says what the thing is and why it exists, and changes when understanding does. This means the agent renames things continuously, as the team's understanding changes, so that names stay current. In code it renames with a tool that changes every reference at once, such as `ast-grep` or an IDE's rename over MCP. A project's root and nested `CLAUDE.md` files, its glossary, design docs, a reviewer subagent and its README can all carry that one principle. Its map names them, so a change to one is checked against the rest.
|
|
75
|
+
|
|
76
|
+
## Commands
|
|
77
|
+
|
|
78
|
+
Your agent drives these; each result names the next.
|
|
79
|
+
|
|
80
|
+
```sh
|
|
81
|
+
principles list-principles # where to start
|
|
82
|
+
principles list-candidate-files # survey the guidance you already have
|
|
83
|
+
principles create-principle express-intent --description "Every name says what the thing is and why it exists"
|
|
84
|
+
principles add-member express-intent CLAUDE.md --section "Name things by intent" --role "States the rule"
|
|
85
|
+
principles start-audit express-intent
|
|
86
|
+
principles submit-answer REQUEST_ID --file answer.json
|
|
87
|
+
principles list-member-problems --short # what changed since the last audit
|
|
88
|
+
principles list-open-findings # findings still waiting
|
|
89
|
+
principles show-meta-principle-passage # a passage for CLAUDE.md that keeps the agent checking
|
|
90
|
+
principles show-hook-setup # hook entries that report changes as a session starts and after a commit
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
The hook entries run `principles report-at-session-start` and `principles report-after-commit`, which a hook runs, not the agent.
|
|
94
|
+
|
|
95
|
+
`principles --help` lists every command, and `principles COMMAND --help` shows its steps. Each project keeps one `.principles/` at its root; `--project PATH` picks one, so projects in a monorepo stay independent.
|
|
96
|
+
|
|
97
|
+
## Harnesses
|
|
98
|
+
|
|
99
|
+
**Claude Code** is the first target. **Codex** agents can use the same CLI from a shell, and share the same maps and audits. `show-hook-setup` prints Codex hook entries too, not yet tried in a real Codex session; native Codex skills are not built yet, and loading estimates describe Claude Code only.
|
|
100
|
+
|
|
101
|
+
## Where it comes from
|
|
102
|
+
|
|
103
|
+
The project grows out of two practices developed through use: **express intent**, keeping names and definitions current as understanding changes; and **collaboration through agents**, helping people align on shared work through the agents they each work with.
|
|
104
|
+
|
|
105
|
+
## Issues
|
|
106
|
+
|
|
107
|
+
Report a bug or ask for a feature at [github.com/realfastAI/principles/issues](https://github.com/realfastAI/principles/issues).
|
|
108
|
+
|
|
109
|
+
## Licence
|
|
110
|
+
|
|
111
|
+
Principles is licensed under the [Apache License 2.0](LICENSE). Its [NOTICE](NOTICE) credits Sidu Ponnappa and Ontic Pte. Ltd. (realfast.ai) as copyright holders, and Apache 2.0 asks that every copy keep it.
|
data/exe/principles
CHANGED
|
@@ -6,5 +6,25 @@
|
|
|
6
6
|
require_relative "../lib/principles/supported_ruby"
|
|
7
7
|
Principles::SupportedRuby.new(RUBY_VERSION, ENV.to_h).run_here_or_on_another(__FILE__, ARGV)
|
|
8
8
|
|
|
9
|
+
# A hook runs report-after-commit after every shell call, and most calls commit nothing, so that case is told from
|
|
10
|
+
# git's files alone, loading nothing else of this tool but the read of stdin. Its input is read as the command reads
|
|
11
|
+
# it, by Data::HookInput, which stops waiting on a stdin left open and sending nothing, and Models::AfterCommitInput.read;
|
|
12
|
+
# any failure here leaves the run to the command, which reports it in one line and exits 0. Like the rest of this
|
|
13
|
+
# file, it is written so an older Ruby can still parse it and reach the refusal above.
|
|
14
|
+
if ARGV == ["report-after-commit"]
|
|
15
|
+
require "stringio"
|
|
16
|
+
require_relative "../lib/principles/data/hook_input"
|
|
17
|
+
hook_input = Principles::Data::HookInput.new($stdin).text
|
|
18
|
+
begin
|
|
19
|
+
require_relative "../lib/principles/models/head_moves"
|
|
20
|
+
call = Principles::Models::AfterCommitInput.read(hook_input, ENV.to_h, clock: Time.now.to_i, home: Dir.home,
|
|
21
|
+
pwd: Dir.pwd)
|
|
22
|
+
exit 0 if call.event.nil? || Principles::Models::HeadMoves.new(call).to_a.empty?
|
|
23
|
+
rescue StandardError
|
|
24
|
+
nil
|
|
25
|
+
end
|
|
26
|
+
$stdin = StringIO.new(hook_input)
|
|
27
|
+
end
|
|
28
|
+
|
|
9
29
|
require_relative "../lib/principles"
|
|
10
30
|
exit Principles::CLI.run(ARGV)
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
require_relative "invocation_options"
|
|
5
5
|
|
|
6
6
|
module Principles
|
|
7
|
-
# The options the plugin's after-commit hook gives list-member-problems, --commits-after and --hook-event
|
|
7
|
+
# The options the plugin's after-commit hook gives list-member-problems, --commits-after and --hook-event,
|
|
8
8
|
# and what is wrong with them as given, which CommandLine refuses as a usage error. list-candidate-files takes
|
|
9
|
-
# --commits-after for a range of its own, so CommandLine checks these on COMMAND alone
|
|
9
|
+
# --commits-after for a range of its own, so CommandLine checks these on COMMAND alone.
|
|
10
10
|
class AfterCommitHookOptions
|
|
11
11
|
# The events Claude Code runs the after-commit hook on, which --hook-event echoes back to it.
|
|
12
12
|
EVENTS = %w[PostToolUse PostToolUseFailure].freeze #: Array[String]
|
data/lib/principles/cli.rb
CHANGED
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
|
|
4
4
|
require "json"
|
|
5
|
-
require_relative "data/running_version"
|
|
6
5
|
require_relative "models/project"
|
|
7
6
|
require_relative "command_routes"
|
|
8
7
|
require_relative "controllers/help"
|
|
9
8
|
require_relative "command_line"
|
|
9
|
+
require_relative "failure_refusal"
|
|
10
|
+
require_relative "launch"
|
|
11
|
+
require_relative "data/hook_input"
|
|
12
|
+
require_relative "views/printed_json"
|
|
10
13
|
|
|
11
14
|
module Principles
|
|
12
15
|
# Parses one invocation, runs its step and prints the JSON result. Every refusal is one JSON object
|
|
13
16
|
# naming its code and repair, because an agent's shell may merge stdout and stderr.
|
|
14
17
|
class CLI
|
|
15
|
-
# The repair for a shape error raised from this tool's own code
|
|
16
|
-
|
|
17
|
-
SHAPE_REPAIR = "A file this command read is not in the shape this tool writes: the map in " \
|
|
18
|
-
".principles/maps/ID.json, its audit record in .principles/audits/ID.json, or the answer given " \
|
|
19
|
-
"with --file. Compare it with git, or with the request's response_template."
|
|
18
|
+
# The repair for a shape error raised from this tool's own code, which FailureRefusal owns.
|
|
19
|
+
SHAPE_REPAIR = FailureRefusal::SHAPE_REPAIR
|
|
20
20
|
|
|
21
21
|
# Runs one invocation and returns its exit status: 0 for a result, 1 for a refusal, 2 for a usage error, and 3
|
|
22
22
|
# when list-member-problems --short finds a member an audit assessed changed, or 4 when it finds only edits to
|
|
23
|
-
# members no audit has assessed
|
|
23
|
+
# members no audit has assessed. executable is the command every printed command
|
|
24
24
|
# names: the entry point says how it is run.
|
|
25
25
|
#: (Array[String], ?IO, ?IO, ?IO, ?executable: String) -> Integer
|
|
26
26
|
def self.run(argv, stdout = $stdout, stderr = $stderr, stdin = $stdin,
|
|
@@ -38,14 +38,42 @@ module Principles
|
|
|
38
38
|
|
|
39
39
|
#: (Array[String]) -> Integer
|
|
40
40
|
def run(argv)
|
|
41
|
-
|
|
41
|
+
hook = hook_command(argv)
|
|
42
|
+
hook ? run_for_a_hook(hook, argv) : run_refusing(argv)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
# Runs argv, refusing what does not fit with one JSON object on stderr and its status.
|
|
48
|
+
#: (Array[String]) -> Integer
|
|
49
|
+
def run_refusing(argv)
|
|
50
|
+
dispatch(command_line(argv))
|
|
42
51
|
rescue Error => e
|
|
43
52
|
refused(e.payload, 1)
|
|
44
53
|
rescue OptionParser::ParseError, KeyError, TypeError, NoMethodError, ArgumentError, SystemCallError => e
|
|
45
|
-
|
|
54
|
+
failed = FailureRefusal.new(e, executable: running_tool.executable)
|
|
55
|
+
refused(failed.payload, failed.status)
|
|
46
56
|
end
|
|
47
57
|
|
|
48
|
-
|
|
58
|
+
# Runs argv for the hook that runs command, which exits 0 whatever fails, since a host shows the user an error for
|
|
59
|
+
# any other status and gives the agent nothing: a failure is one line the agent reads instead.
|
|
60
|
+
#: (String, Array[String]) -> Integer
|
|
61
|
+
def run_for_a_hook(command, argv)
|
|
62
|
+
dispatch(command_line(argv))
|
|
63
|
+
rescue StandardError => e
|
|
64
|
+
@stdout.puts(visible("principles: #{command} failed: #{e.class}: #{e.message.lines.first.to_s.chomp}"))
|
|
65
|
+
0
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# The command argv names first when a hook runs it, as a host names it, passing its JSON on stdin, or nil for any
|
|
69
|
+
# other: a hook command's name later in argv is another command's argument.
|
|
70
|
+
#: (Array[String]) -> String?
|
|
71
|
+
def hook_command(argv) = argv.first.then { it if CommandRoutes::ROUTES[it]&.reads_hook_input }
|
|
72
|
+
|
|
73
|
+
#: (Array[String]) -> CommandLine
|
|
74
|
+
def command_line(argv)
|
|
75
|
+
CommandLine.new(argv, positional: CommandRoutes::POSITIONAL, executable: running_tool.executable)
|
|
76
|
+
end
|
|
49
77
|
|
|
50
78
|
#: (CommandLine) -> Integer
|
|
51
79
|
def dispatch(line)
|
|
@@ -66,37 +94,22 @@ module Principles
|
|
|
66
94
|
options = line.command_options
|
|
67
95
|
# One byte past the limit is enough for the answer's own check to refuse it as too large.
|
|
68
96
|
options["stdin"] = @stdin.read(Data::BoundedFile::LIMIT + 1).to_s if options["file"] == "-"
|
|
97
|
+
options["stdin"] = hook_input if CommandRoutes::ROUTES.fetch(command).reads_hook_input
|
|
69
98
|
project = selected_project(line)
|
|
70
99
|
CommandRoutes::CONTROLLERS.fetch(command).new(project, tool: running_tool)
|
|
71
100
|
.call(command, line.id, options)
|
|
72
101
|
end
|
|
73
102
|
|
|
103
|
+
# The JSON a host passes the hook that runs this command.
|
|
104
|
+
#: () -> String
|
|
105
|
+
def hook_input = Data::HookInput.new(@stdin).text
|
|
106
|
+
|
|
74
107
|
#: (CommandLine) -> Models::Project
|
|
75
108
|
def selected_project(line)
|
|
76
109
|
root = line.option("project")
|
|
77
110
|
line.project_given? ? Models::Project.at(root) : Models::Project.containing(root)
|
|
78
111
|
end
|
|
79
112
|
|
|
80
|
-
# The JSON object an agent reads for a failure that is not one of this tool's refusals.
|
|
81
|
-
#: (StandardError) -> Hash[untyped, untyped]
|
|
82
|
-
def refusal(error)
|
|
83
|
-
case error
|
|
84
|
-
when OptionParser::ParseError
|
|
85
|
-
failure(error, status: "usage_error", code: "invalid_invocation", repair: usage_repair(error))
|
|
86
|
-
when SystemCallError
|
|
87
|
-
failure(error, status: "refused", code: "filesystem_error",
|
|
88
|
-
repair: "Check the project path and file permissions, then retry.")
|
|
89
|
-
else
|
|
90
|
-
failure(error, status: "refused", code: "invalid_shape", repair: SHAPE_REPAIR)
|
|
91
|
-
end
|
|
92
|
-
end
|
|
93
|
-
|
|
94
|
-
# The repair a refused command line carries for the command it names, or the advice to see every command.
|
|
95
|
-
#: (OptionParser::ParseError) -> String
|
|
96
|
-
def usage_repair(error)
|
|
97
|
-
error.is_a?(CommandLine::UsageRefusal) ? error.repair : "To see every command: #{@executable} --help"
|
|
98
|
-
end
|
|
99
|
-
|
|
100
113
|
# Prints the refusal for the agent and returns the exit status.
|
|
101
114
|
#: (Hash[untyped, untyped], Integer) -> Integer
|
|
102
115
|
def refused(payload, status)
|
|
@@ -104,14 +117,9 @@ module Principles
|
|
|
104
117
|
status
|
|
105
118
|
end
|
|
106
119
|
|
|
107
|
-
#: (StandardError, status: String, code: String, repair: String) -> Hash[Symbol, String]
|
|
108
|
-
def failure(error, status:, code:, repair:)
|
|
109
|
-
{ status: status, code: code, message: error.message, repair: repair }
|
|
110
|
-
end
|
|
111
|
-
|
|
112
120
|
# json with every invisible formatting character and line or paragraph separator escaped, as JSON allows.
|
|
113
121
|
# Text from project files can hold a right-to-left override or a zero-width space, which makes a printed
|
|
114
|
-
# check or id look like something it is not
|
|
122
|
+
# check or id look like something it is not.
|
|
115
123
|
#: (String) -> String
|
|
116
124
|
def visible(json)
|
|
117
125
|
json.gsub(/[\p{Cf}\p{Zl}\p{Zp}]/) do |character|
|
|
@@ -124,7 +132,7 @@ module Principles
|
|
|
124
132
|
#: (untyped) -> Integer
|
|
125
133
|
def printed_result(result)
|
|
126
134
|
return printed(visible(result.text)) if result.is_a?(Views::JsonWithEntriesOnLines)
|
|
127
|
-
return printed(visible(
|
|
135
|
+
return printed(visible(Views::PrintedJson.text(result))) unless result.is_a?(Views::Lines)
|
|
128
136
|
|
|
129
137
|
@stdout.print(result.stdout)
|
|
130
138
|
@stderr.print(result.stderr)
|
|
@@ -142,15 +150,15 @@ module Principles
|
|
|
142
150
|
Controllers::Help.new(tool: running_tool)
|
|
143
151
|
end
|
|
144
152
|
|
|
145
|
-
# This run of the tool
|
|
153
|
+
# This run of the tool, as its entry point launched it.
|
|
146
154
|
#: () -> Controllers::RunningTool
|
|
147
|
-
def running_tool =
|
|
155
|
+
def running_tool = Launch.new(@executable).running_tool
|
|
148
156
|
|
|
149
|
-
# The version of this tool that is running, as
|
|
157
|
+
# The version of this tool that is running, as --version prints it.
|
|
150
158
|
#: () -> String
|
|
151
|
-
def running_version =
|
|
159
|
+
def running_version = running_tool.version
|
|
152
160
|
|
|
153
|
-
# The page help COMMAND asks for, as COMMAND --help prints it, or the overview for help alone
|
|
161
|
+
# The page help COMMAND asks for, as COMMAND --help prints it, or the overview for help alone.
|
|
154
162
|
#: (CommandLine) -> String
|
|
155
163
|
def help_topic(line)
|
|
156
164
|
topic = line.help_topic
|
|
@@ -19,7 +19,7 @@ module Principles
|
|
|
19
19
|
REQUIRED_OPTION_WORDS = { "file" => "--file FILE, or --file - for stdin" }.freeze #: Hash[String, String]
|
|
20
20
|
|
|
21
21
|
# argv is parsed at once; positional names each command's positional arguments, in order; executable is the
|
|
22
|
-
# invocation a refusal tells the agent to run --help with
|
|
22
|
+
# invocation a refusal tells the agent to run --help with.
|
|
23
23
|
#: (Array[String], positional: Hash[String, Array[String]], executable: String) -> void
|
|
24
24
|
def initialize(argv, positional:, executable:)
|
|
25
25
|
@positional = positional
|
|
@@ -27,13 +27,13 @@ module Principles
|
|
|
27
27
|
@options = InvocationOptions.new #: InvocationOptions
|
|
28
28
|
@arguments = argv.dup #: Array[String]
|
|
29
29
|
# The words as typed: parsing takes the options out of @arguments, and a value option is checked against
|
|
30
|
-
# the word that followed it
|
|
30
|
+
# the word that followed it.
|
|
31
31
|
@words = argv.dup.freeze #: Array[String]
|
|
32
32
|
parse(argv)
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
# A usage refusal that carries the repair for the command it names, which CLI prints in place of its
|
|
36
|
-
# general advice
|
|
36
|
+
# general advice. It stays an OptionParser::ParseError, so it exits 2 like every usage refusal.
|
|
37
37
|
class UsageRefusal < OptionParser::ParseError
|
|
38
38
|
#: String
|
|
39
39
|
attr_reader :repair
|
|
@@ -59,7 +59,7 @@ module Principles
|
|
|
59
59
|
#: () -> bool
|
|
60
60
|
def project_given? = @options.given.include?("project")
|
|
61
61
|
|
|
62
|
-
# Whether the words ask for help by word, as help or help COMMAND, which an agent tries before --help
|
|
62
|
+
# Whether the words ask for help by word, as help or help COMMAND, which an agent tries before --help.
|
|
63
63
|
#: () -> bool
|
|
64
64
|
def help_words? = @arguments.first == "help"
|
|
65
65
|
|
|
@@ -94,10 +94,12 @@ module Principles
|
|
|
94
94
|
positionals.id
|
|
95
95
|
end
|
|
96
96
|
|
|
97
|
-
# The options, with every positional argument but the id under its name
|
|
97
|
+
# The options, with every positional argument but the id under its name; project only when --project was given,
|
|
98
|
+
# so a command's printed commands name it only then.
|
|
98
99
|
#: () -> Hash[String, untyped]
|
|
99
100
|
def command_options
|
|
100
|
-
@options.to_h.merge(positionals.bindings)
|
|
101
|
+
options = @options.to_h.merge(positionals.bindings)
|
|
102
|
+
project_given? ? options : options.except("project")
|
|
101
103
|
end
|
|
102
104
|
|
|
103
105
|
private
|
|
@@ -106,8 +108,8 @@ module Principles
|
|
|
106
108
|
def positionals = PositionalArguments.new(@positional.fetch(command.to_s), @arguments.drop(1))
|
|
107
109
|
|
|
108
110
|
# Each argument the command needs and was not given, named in one refusal: an agent that met one refusal per
|
|
109
|
-
# missing argument repaired them one at a time
|
|
110
|
-
# The repair names the command's usage, which shows what to give
|
|
111
|
+
# missing argument repaired them one at a time. Each option command-steps.json says it requires is one.
|
|
112
|
+
# The repair names the command's usage, which shows what to give.
|
|
111
113
|
#: (String) -> void
|
|
112
114
|
def check_missing(name)
|
|
113
115
|
missing = positionals.missing + missing_options(name)
|
|
@@ -142,8 +144,8 @@ module Principles
|
|
|
142
144
|
raise UsageRefusal.new("#{name} does not take #{unknown.join(", ")}", help_repair(name))
|
|
143
145
|
end
|
|
144
146
|
|
|
145
|
-
# An option that takes a value takes the next word, whatever it is, so --member --help took --help as the member
|
|
146
|
-
#
|
|
147
|
+
# An option that takes a value takes the next word, whatever it is, so --member --help took --help as the member.
|
|
148
|
+
# Only this tool's own option words are refused there, since a quote may start with dashes; such a word is
|
|
147
149
|
# given as a value after =, as --starting-at=--role is.
|
|
148
150
|
#: (String) -> void
|
|
149
151
|
def check_values_are_not_options(name)
|
|
@@ -157,18 +159,22 @@ module Principles
|
|
|
157
159
|
end
|
|
158
160
|
end
|
|
159
161
|
|
|
160
|
-
# Options checked together, each set owning what is wrong with it as given: --session-start
|
|
161
|
-
# after-commit hook's pair on the command it runs
|
|
162
|
-
# list-open-findings prints
|
|
162
|
+
# Options checked together, each set owning what is wrong with it as given: --session-start, the
|
|
163
|
+
# after-commit hook's pair on the command it runs, the audit start-audit begins and the form
|
|
164
|
+
# list-open-findings prints; the first fault is refused.
|
|
163
165
|
#: (String) -> void
|
|
164
166
|
def check_combined_options(name)
|
|
165
167
|
hook = (AfterCommitHookOptions.new(@options) if name == AfterCommitHookOptions::COMMAND)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
+
start_audit = StartAuditOptions.new(@options, several_ids: several_ids?(name))
|
|
169
|
+
sets = [SessionStartOptions.new(@options), hook, start_audit, ListOpenFindingsOptions.new(@options)].compact
|
|
168
170
|
fault = sets.filter_map(&:fault).first or return
|
|
169
171
|
raise UsageRefusal.new(fault, help_repair(name))
|
|
170
172
|
end
|
|
171
173
|
|
|
174
|
+
# Whether command name is start-audit given more than one principle id.
|
|
175
|
+
#: (String) -> bool
|
|
176
|
+
def several_ids?(name) = name == "start-audit" && !positionals.bindings.fetch("other_ids", []).empty?
|
|
177
|
+
|
|
172
178
|
# Parses argv's options; an option no command defines fails here, before the command is checked, and is
|
|
173
179
|
# repaired with the help of the command argv names, or left to CLI's general advice when it names none.
|
|
174
180
|
#: (Array[String]) -> void
|
|
@@ -189,7 +195,7 @@ module Principles
|
|
|
189
195
|
def steps(name) = Models::CommandSteps.load.command(name)
|
|
190
196
|
|
|
191
197
|
# The command's usage, which names every option it takes, so a near-miss such as --heading for --section shows
|
|
192
|
-
# beside the refusal
|
|
198
|
+
# beside the refusal, then where to see what each takes. The usage leaves out the executable, so it is not
|
|
193
199
|
# read as a command to run as printed.
|
|
194
200
|
#: (String) -> String
|
|
195
201
|
def help_repair(name)
|