instar 1.2.22 → 1.2.24

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.
@@ -2027,6 +2027,16 @@ Strip the \`[telegram:N]\` prefix before interpreting the message. Respond natur
2027
2027
  3. **If result says "warn"** — Pause and verify before proceeding.
2028
2028
  4. **Generate a reflection prompt**: \`POST http://localhost:${port}/coherence/reflect\` — produces a self-verification checklist.
2029
2029
 
2030
+ #### ORG-INTENT.md (Organizational Intent at Runtime)
2031
+
2032
+ If \`.instar/ORG-INTENT.md\` exists on disk, two runtime surfaces consume it: the Coherence Gate (Phase 1) reads it on every outbound message review, and the session-start hook (Phase 2) fetches it at session boot via \`GET /intent/org/session-context\` and injects the structured contract into your context. **Constraints** are mandatory (violations block), **goals** are organizational defaults (contradictions warn or block), **values** shape representation (drift warns), and the **tradeoff hierarchy** resolves ties when two values pull in opposite directions (earlier entry wins).
2033
+
2034
+ Manage it:
2035
+ - Scaffold a starter: \`instar intent org-init "Your Org Name"\`
2036
+ - Static validation against agent intent: \`instar intent validate\`
2037
+ - Inspect parsed structure: \`curl -H "Authorization: Bearer $AUTH" http://localhost:${port}/intent/org\`
2038
+ - Preview the session-start block: \`curl -H "Authorization: Bearer $AUTH" http://localhost:${port}/intent/org/session-context\`
2039
+
2030
2040
  **Topic-Project Bindings**: Each Telegram topic can be bound to a specific project. When switching topics, verify the binding matches your current working directory.
2031
2041
  - View bindings: \`GET http://localhost:${port}/topic-bindings\`
2032
2042
  - Create binding: \`POST http://localhost:${port}/topic-bindings\` with \`{"topicId": N, "binding": {"projectName": "...", "projectDir": "..."}}\`
@@ -2046,6 +2056,68 @@ Strip the \`[telegram:N]\` prefix before interpreting the message. Respond natur
2046
2056
  patched = true;
2047
2057
  result.upgraded.push('CLAUDE.md: added Coherence Gate section');
2048
2058
  }
2059
+ else if (!content.includes('ORG-INTENT.md (Organizational Intent at Runtime)') && !content.includes('Organizational Intent at Runtime')) {
2060
+ // Coherence Gate section is present but predates the ORG-INTENT runtime
2061
+ // wiring. Append the ORG-INTENT subsection inline after the
2062
+ // "Generate a reflection prompt" line so the agent learns that
2063
+ // ORG-INTENT.md now actually shapes outbound message review.
2064
+ const subsection = `
2065
+
2066
+ #### ORG-INTENT.md (Organizational Intent at Runtime)
2067
+
2068
+ If \`.instar/ORG-INTENT.md\` exists on disk, two runtime surfaces consume it: the Coherence Gate (Phase 1) reads it on every outbound message review, and the session-start hook (Phase 2) fetches it at session boot via \`GET /intent/org/session-context\` and injects the structured contract into your context. **Constraints** are mandatory (violations block), **goals** are organizational defaults (contradictions warn or block), **values** shape representation (drift warns), and the **tradeoff hierarchy** resolves ties when two values pull in opposite directions (earlier entry wins).
2069
+
2070
+ Manage it:
2071
+ - Scaffold a starter: \`instar intent org-init "Your Org Name"\`
2072
+ - Static validation against agent intent: \`instar intent validate\`
2073
+ - Inspect parsed structure: \`curl -H "Authorization: Bearer $AUTH" http://localhost:${port}/intent/org\`
2074
+ - Preview the session-start block: \`curl -H "Authorization: Bearer $AUTH" http://localhost:${port}/intent/org/session-context\`
2075
+ `;
2076
+ // Anchor: insert after "Topic-Project Bindings" header so it lands inside
2077
+ // the Coherence Gate section but before the Project Map subsection.
2078
+ const anchor = content.indexOf('**Topic-Project Bindings**');
2079
+ if (anchor >= 0) {
2080
+ content = content.slice(0, anchor) + subsection + '\n' + content.slice(anchor);
2081
+ patched = true;
2082
+ result.upgraded.push('CLAUDE.md: added ORG-INTENT.md runtime subsection (Phase 1+2) to Coherence Gate');
2083
+ }
2084
+ else {
2085
+ // Fallback: append at end if the Topic-Project Bindings anchor moved
2086
+ content += '\n' + subsection;
2087
+ patched = true;
2088
+ result.upgraded.push('CLAUDE.md: appended ORG-INTENT.md runtime subsection (anchor missing, fallback insert)');
2089
+ }
2090
+ }
2091
+ else if (content.includes('ORG-INTENT.md (Organizational Intent at Runtime)')
2092
+ && !content.includes('/intent/org/session-context')) {
2093
+ // CLAUDE.md already has the Phase 1 ORG-INTENT runtime subsection but
2094
+ // not the Phase 2 session-start injection mention. Rewrite the
2095
+ // subsection in place so the agent learns about both surfaces.
2096
+ // Match: from the heading line through the empty line before the next
2097
+ // ### heading (typically "### External Operation Safety" or
2098
+ // "## Agent Infrastructure").
2099
+ const headingPattern = /(####? ORG-INTENT\.md \(Organizational Intent at Runtime\))[\s\S]*?(?=\n## |\n### |$)/;
2100
+ const replacement = `$1
2101
+
2102
+ If \`.instar/ORG-INTENT.md\` exists on disk, two runtime surfaces consume it: the Coherence Gate (Phase 1) reads it on every outbound message review, and the session-start hook (Phase 2) fetches it at session boot via \`GET /intent/org/session-context\` and injects the structured contract into your context. **Constraints** are mandatory (violations block), **goals** are organizational defaults (contradictions warn or block), **values** shape representation (drift warns), and the **tradeoff hierarchy** resolves ties when two values pull in opposite directions (earlier entry wins).
2103
+
2104
+ Manage it:
2105
+ - Scaffold a starter: \`instar intent org-init "Your Org Name"\`
2106
+ - Static validation against agent intent: \`instar intent validate\`
2107
+ - Inspect parsed structure: \`curl -H "Authorization: Bearer $AUTH" http://localhost:${port}/intent/org\`
2108
+ - Preview the session-start block: \`curl -H "Authorization: Bearer $AUTH" http://localhost:${port}/intent/org/session-context\`
2109
+
2110
+ `;
2111
+ const before = content;
2112
+ content = content.replace(headingPattern, replacement);
2113
+ if (content !== before) {
2114
+ patched = true;
2115
+ result.upgraded.push('CLAUDE.md: upgraded ORG-INTENT.md subsection to mention Phase 2 session-start injection');
2116
+ }
2117
+ else {
2118
+ result.skipped.push('CLAUDE.md: ORG-INTENT.md subsection present but Phase 2 upgrade pattern did not match (skipping)');
2119
+ }
2120
+ }
2049
2121
  else {
2050
2122
  result.skipped.push('CLAUDE.md: Coherence Gate section already present');
2051
2123
  }
@@ -3359,6 +3431,35 @@ if [ -f "$INSTAR_DIR/config.json" ]; then
3359
3431
  fi
3360
3432
  fi
3361
3433
 
3434
+ # ORG-INTENT injection — Phase 2 of the ORG-INTENT runtime project.
3435
+ # Fetches the parsed three-rule contract (constraints / goals / values /
3436
+ # tradeoff hierarchy) from /intent/org/session-context and injects it at
3437
+ # session-start so the agent reasons with the organizational intent from
3438
+ # message one. The Coherence Gate (Phase 1) still enforces the same contract
3439
+ # at outbound-message review time — this just brings the same intent into the
3440
+ # agent's working context up front. Fail-open: route unreachable / absent
3441
+ # ORG-INTENT.md / 503 → silent skip, session continues normally.
3442
+ if [ -n "\$PORT" ] && [ -n "\$TOKEN" ]; then
3443
+ ORG_INTENT_RESPONSE=\$(curl -sf --max-time 4 -H "Authorization: Bearer \$TOKEN" \\
3444
+ "http://localhost:\${PORT}/intent/org/session-context" 2>/dev/null)
3445
+ if [ -n "\$ORG_INTENT_RESPONSE" ]; then
3446
+ ORG_INTENT_BLOCK=\$(echo "\$ORG_INTENT_RESPONSE" | python3 -c "
3447
+ import sys, json
3448
+ try:
3449
+ d = json.load(sys.stdin)
3450
+ if d.get('present') and d.get('block'):
3451
+ print(d['block'])
3452
+ except Exception:
3453
+ pass
3454
+ " 2>/dev/null)
3455
+ if [ -n "\$ORG_INTENT_BLOCK" ]; then
3456
+ echo ""
3457
+ echo "\$ORG_INTENT_BLOCK"
3458
+ echo ""
3459
+ fi
3460
+ fi
3461
+ fi
3462
+
3362
3463
  # BEGIN integrated-being-v2
3363
3464
  # INTEGRATED-BEING V2 — session-write binding (see docs/specs/integrated-being-ledger-v2.md §3)
3364
3465
  # Generates a session UUID, registers with /shared-state/session-bind, writes the