claude-dev-env 1.38.1 → 1.40.0
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.
- package/CLAUDE.md +10 -36
- package/_shared/pr-loop/audit-reply-template.md +147 -0
- package/_shared/pr-loop/fix-protocol.md +25 -4
- package/_shared/pr-loop/gh-payloads.md +37 -50
- package/_shared/pr-loop/scripts/code_rules_gate.py +0 -60
- package/_shared/pr-loop/scripts/config/post_audit_thread_constants.py +199 -0
- package/_shared/pr-loop/scripts/config/reviews_disabled_constants.py +8 -0
- package/_shared/pr-loop/scripts/post_audit_thread.py +1242 -0
- package/_shared/pr-loop/scripts/preflight.py +129 -2
- package/_shared/pr-loop/scripts/reviews_disabled.py +59 -0
- package/_shared/pr-loop/scripts/tests/test_code_rules_gate.py +0 -19
- package/_shared/pr-loop/scripts/tests/test_post_audit_thread.py +1116 -0
- package/_shared/pr-loop/scripts/tests/test_post_audit_thread_constants.py +127 -0
- package/_shared/pr-loop/scripts/tests/test_preflight.py +41 -0
- package/_shared/pr-loop/scripts/tests/test_reviews_disabled.py +36 -0
- package/_shared/pr-loop/state-schema.md +1 -1
- package/agents/clean-coder.md +2 -2
- package/agents/pr-description-writer.md +150 -52
- package/bin/install.mjs +6 -7
- package/bin/install.test.mjs +8 -0
- package/commands/doc-gist.md +16 -0
- package/commands/plan.md +0 -2
- package/commands/review-plan.md +1 -1
- package/docs/CODE_RULES.md +122 -2
- package/docs/PR_DESCRIPTION_GUIDE.md +127 -64
- package/hooks/blocking/bot_mention_comment_blocker.py +75 -0
- package/hooks/blocking/code_rules_enforcer.py +1143 -129
- package/hooks/blocking/convergence_gate_blocker.py +130 -0
- package/hooks/blocking/destructive_command_blocker.py +74 -0
- package/hooks/blocking/gh_body_arg_blocker.py +30 -0
- package/hooks/blocking/md_to_html_blocker.py +119 -0
- package/hooks/blocking/pr_description_enforcer.py +57 -22
- package/hooks/blocking/test_bot_mention_comment_blocker.py +131 -0
- package/hooks/blocking/test_code_rules_enforcer.py +21 -0
- package/hooks/blocking/test_code_rules_enforcer_any_exempt_files.py +70 -0
- package/hooks/blocking/test_code_rules_enforcer_any_imports_and_cast.py +92 -0
- package/hooks/blocking/test_code_rules_enforcer_banned_import_alias.py +143 -0
- package/hooks/blocking/test_code_rules_enforcer_banned_prefixes.py +152 -0
- package/hooks/blocking/test_code_rules_enforcer_bare_except.py +120 -0
- package/hooks/blocking/test_code_rules_enforcer_boundary_types.py +175 -0
- package/hooks/blocking/test_code_rules_enforcer_cap_meta.py +0 -1
- package/hooks/blocking/test_code_rules_enforcer_collection_prefix.py +50 -0
- package/hooks/blocking/test_code_rules_enforcer_docstring_format.py +255 -0
- package/hooks/blocking/test_code_rules_enforcer_inline_tuple_string_magic.py +130 -0
- package/hooks/blocking/test_code_rules_enforcer_stub_implementations.py +141 -0
- package/hooks/blocking/test_code_rules_enforcer_test_branching.py +143 -0
- package/hooks/blocking/test_code_rules_enforcer_thin_wrapper_files.py +169 -0
- package/hooks/blocking/test_code_rules_enforcer_todo_markers.py +99 -0
- package/hooks/blocking/test_code_rules_enforcer_typed_dict_pairs.py +141 -0
- package/hooks/blocking/test_convergence_gate_blocker.py +63 -0
- package/hooks/blocking/test_destructive_command_blocker.py +146 -0
- package/hooks/blocking/test_destructive_command_blocker_no_verify.py +102 -0
- package/hooks/blocking/test_gh_body_arg_blocker.py +45 -0
- package/hooks/blocking/test_md_to_html_blocker.py +317 -0
- package/hooks/blocking/test_pr_description_enforcer.py +69 -8
- package/hooks/config/any_type_config.py +7 -0
- package/hooks/config/banned_identifiers_constants.py +11 -0
- package/hooks/config/blocking_check_limits.py +38 -0
- package/hooks/config/bot_mention_comment_blocker_constants.py +20 -0
- package/hooks/config/code_rules_enforcer_constants.py +53 -0
- package/hooks/config/convergence_branch_constants.py +9 -0
- package/hooks/config/doc_gist_auto_publish_constants.py +18 -0
- package/hooks/config/html_companion_constants.py +20 -0
- package/hooks/config/inline_tuple_string_magic_constants.py +22 -0
- package/hooks/config/pr_description_enforcer_constants.py +14 -0
- package/hooks/config/test_banned_identifiers_constants.py +17 -0
- package/hooks/hooks.json +28 -20
- package/hooks/pyproject.toml +69 -0
- package/hooks/validators/mypy_integration.py +47 -1
- package/hooks/validators/run_all_validators.py +3 -3
- package/hooks/validators/test_mypy_integration.py +50 -1
- package/hooks/workflow/doc_gist_auto_publish.py +144 -0
- package/hooks/workflow/md_to_html_companion.py +365 -0
- package/hooks/workflow/test_doc_gist_auto_publish.py +117 -0
- package/hooks/workflow/test_md_to_html_companion.py +452 -0
- package/package.json +1 -1
- package/rules/gh-body-file.md +2 -0
- package/scripts/Install-SweepEmptyDirs.ps1 +111 -0
- package/scripts/check.ps1 +106 -0
- package/scripts/config/timing.py +11 -0
- package/scripts/sweep_empty_dirs.py +138 -0
- package/scripts/sync_to_cursor/rules.py +1 -1
- package/scripts/test_sweep_empty_dirs.py +183 -0
- package/skills/_shared/pr-loop/prompts/pr-consistency-audit.xml +323 -0
- package/skills/_shared/pr-loop/scripts/_cli_utils.py +22 -0
- package/skills/_shared/pr-loop/scripts/_path_resolver.py +165 -0
- package/skills/_shared/pr-loop/scripts/_xml_utils.py +20 -0
- package/skills/_shared/pr-loop/scripts/build_audit_prompt.py +182 -0
- package/skills/_shared/pr-loop/scripts/build_fix_prompt.py +185 -0
- package/skills/_shared/pr-loop/scripts/config/__init__.py +0 -0
- package/skills/_shared/pr-loop/scripts/config/path_resolver_constants.py +78 -0
- package/skills/_shared/pr-loop/scripts/init_loop_state.py +135 -0
- package/skills/_shared/pr-loop/scripts/teardown_worktrees.py +175 -0
- package/skills/_shared/pr-loop/scripts/write_audit_outcomes.py +182 -0
- package/skills/_shared/pr-loop/scripts/write_fix_outcomes.py +206 -0
- package/skills/bugteam/CONSTRAINTS.md +21 -22
- package/skills/bugteam/EXAMPLES.md +3 -3
- package/skills/bugteam/PROMPTS.md +227 -67
- package/skills/bugteam/SKILL.md +132 -455
- package/skills/bugteam/reference/README.md +1 -1
- package/skills/bugteam/reference/audit-and-teammates.md +112 -39
- package/skills/bugteam/reference/audit-contract.md +4 -22
- package/skills/bugteam/reference/copilot-gap-analysis.md +8 -5
- package/skills/bugteam/reference/design-rationale.md +2 -2
- package/skills/bugteam/reference/github-pr-reviews.md +50 -57
- package/skills/bugteam/reference/obstacles/audit-assign-ids.md +13 -0
- package/skills/bugteam/reference/obstacles/audit-capture-excerpts.md +13 -0
- package/skills/bugteam/reference/obstacles/audit-walk-categories.md +13 -0
- package/skills/bugteam/reference/obstacles/audit-write-xml.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-append-summary.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-apply-fixes.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-git-add-commit.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-git-push.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-post-reply.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-publish-summary.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-py-compile.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-read-files.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-resolve-thread.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-test-suite.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-violation-count.md +13 -0
- package/skills/bugteam/reference/obstacles/fix-write-xml.md +13 -0
- package/skills/bugteam/reference/team-setup.md +111 -9
- package/skills/bugteam/reference/teardown-publish-permissions.md +39 -8
- package/skills/bugteam/scripts/README.md +60 -0
- package/skills/bugteam/scripts/_claude_permissions_common.py +358 -0
- package/skills/bugteam/scripts/bugteam_code_rules_gate.py +976 -0
- package/skills/bugteam/scripts/bugteam_fix_hookspath.py +375 -0
- package/skills/bugteam/scripts/bugteam_preflight.py +328 -0
- package/skills/bugteam/scripts/config/bugteam_code_rules_gate_constants.py +25 -0
- package/skills/bugteam/scripts/config/bugteam_fix_hookspath_constants.py +26 -0
- package/skills/bugteam/scripts/config/bugteam_preflight_constants.py +35 -0
- package/skills/bugteam/scripts/config/claude_permissions_common_constants.py +20 -0
- package/skills/bugteam/scripts/config/probe_code_rules_enforcer_check_constants.py +12 -0
- package/skills/bugteam/scripts/config/windows_safe_rmtree_constants.py +7 -0
- package/skills/bugteam/scripts/grant_project_claude_permissions.py +175 -0
- package/skills/bugteam/scripts/probe_code_rules_enforcer_check.py +107 -0
- package/skills/bugteam/scripts/revoke_project_claude_permissions.py +220 -0
- package/skills/bugteam/scripts/test__claude_permissions_common.py +112 -0
- package/skills/bugteam/scripts/test_bugteam_code_rules_gate.py +400 -0
- package/skills/bugteam/scripts/test_bugteam_fix_hookspath.py +384 -0
- package/skills/bugteam/scripts/test_bugteam_preflight.py +309 -0
- package/skills/bugteam/scripts/test_claude_permissions_common.py +195 -0
- package/skills/bugteam/scripts/test_grant_project_claude_permissions.py +55 -0
- package/skills/bugteam/scripts/test_probe_code_rules_enforcer_check.py +76 -0
- package/skills/bugteam/scripts/test_revoke_project_claude_permissions.py +55 -0
- package/skills/bugteam/scripts/test_windows_safe_rmtree.py +108 -0
- package/skills/bugteam/scripts/windows_safe_rmtree.py +100 -0
- package/skills/bugteam/test_skill_additions.py +1 -11
- package/skills/code/SKILL.md +176 -0
- package/skills/copilot-review/SKILL.md +16 -0
- package/skills/doc-gist/SKILL.md +99 -0
- package/skills/doc-gist/references/examples/01-exploration-code-approaches.html +453 -0
- package/skills/doc-gist/references/examples/02-exploration-visual-designs.html +515 -0
- package/skills/doc-gist/references/examples/03-code-review-pr.html +638 -0
- package/skills/doc-gist/references/examples/04-code-understanding.html +491 -0
- package/skills/doc-gist/references/examples/05-design-system.html +629 -0
- package/skills/doc-gist/references/examples/06-component-variants.html +605 -0
- package/skills/doc-gist/references/examples/07-prototype-animation.html +455 -0
- package/skills/doc-gist/references/examples/08-prototype-interaction.html +396 -0
- package/skills/doc-gist/references/examples/09-slide-deck.html +592 -0
- package/skills/doc-gist/references/examples/10-svg-illustrations.html +492 -0
- package/skills/doc-gist/references/examples/11-status-report.html +528 -0
- package/skills/doc-gist/references/examples/12-incident-report.html +596 -0
- package/skills/doc-gist/references/examples/13-flowchart-diagram.html +395 -0
- package/skills/doc-gist/references/examples/14-research-feature-explainer.html +381 -0
- package/skills/doc-gist/references/examples/15-research-concept-explainer.html +368 -0
- package/skills/doc-gist/references/examples/16-implementation-plan.html +702 -0
- package/skills/doc-gist/references/examples/17-pr-writeup.html +595 -0
- package/skills/doc-gist/references/examples/18-editor-triage-board.html +573 -0
- package/skills/doc-gist/references/examples/19-editor-feature-flags.html +663 -0
- package/skills/doc-gist/references/examples/20-editor-prompt-tuner.html +722 -0
- package/skills/doc-gist/references/examples/README.md +5 -0
- package/skills/doc-gist/scripts/config/__init__.py +0 -0
- package/skills/doc-gist/scripts/config/gist_upload_constants.py +16 -0
- package/skills/doc-gist/scripts/gist_upload.py +177 -0
- package/skills/doc-gist/scripts/test_gist_upload.py +51 -0
- package/skills/findbugs/SKILL.md +96 -2
- package/skills/monitor-open-prs/SKILL.md +14 -32
- package/skills/monitor-open-prs/test_skill_contract.py +0 -11
- package/skills/pr-consistency-audit/SKILL.md +112 -0
- package/skills/pr-consistency-audit/reference/detection-rules.md +96 -0
- package/skills/pr-consistency-audit/reference/illustrations.md +78 -0
- package/skills/pr-converge/SKILL.md +229 -23
- package/skills/pr-converge/config/__init__.py +0 -0
- package/skills/pr-converge/config/constants.py +63 -0
- package/skills/pr-converge/reference/convergence-gates.md +138 -44
- package/skills/pr-converge/reference/examples.md +43 -11
- package/skills/pr-converge/reference/fix-protocol.md +6 -5
- package/skills/pr-converge/reference/ground-rules.md +5 -3
- package/skills/pr-converge/reference/multi-pr-orchestration.md +44 -19
- package/skills/pr-converge/reference/obstacles/fix-post-replies.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-publish-summary.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-push.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-read-filelines.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-reset-state.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-resolve-threads.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-spawn-clean-coder.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-stage-commit.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-trigger-bugbot.md +13 -0
- package/skills/pr-converge/reference/obstacles/fix-write-test.md +13 -0
- package/skills/pr-converge/reference/per-tick.md +107 -31
- package/skills/pr-converge/reference/state-schema.md +22 -1
- package/skills/pr-converge/reference/stop-conditions.md +9 -7
- package/skills/pr-converge/scripts/README.md +34 -46
- package/skills/pr-converge/scripts/check_bugbot_ci.py +279 -0
- package/skills/pr-converge/scripts/check_convergence.py +497 -0
- package/skills/pr-converge/scripts/check_pending_reviews.py +154 -0
- package/skills/pr-converge/scripts/config/pr_converge_constants.py +118 -0
- package/skills/pr-converge/scripts/fetch_copilot_reviews.py +134 -0
- package/skills/pr-converge/scripts/post_fix_reply.py +168 -0
- package/skills/pr-converge/scripts/test_check_bugbot_ci.py +312 -0
- package/skills/pr-converge/workflows/schedule-wakeup-loop.md +5 -12
- package/skills/qbug/SKILL.md +157 -27
- package/skills/session-log/SKILL.md +216 -114
- package/skills/session-tidy/SKILL.md +1 -1
- package/skills/skill-builder/SKILL.md +138 -56
- package/skills/skill-builder/references/delegation-map.md +72 -113
- package/skills/skill-builder/references/progressive-disclosure.md +122 -0
- package/skills/skill-builder/references/self-audit-checklist.md +92 -0
- package/skills/skill-builder/references/skill-types.md +228 -0
- package/skills/skill-builder/references/thariq-x-post-skills.json +33 -0
- package/skills/skill-builder/templates/gap-analysis.md +15 -8
- package/skills/skill-builder/workflows/improve-skill.md +86 -57
- package/skills/skill-builder/workflows/new-skill.md +80 -168
- package/skills/skill-builder/workflows/polish-skill.md +78 -54
- package/skills/structure-prompt/SKILL.md +50 -0
- package/skills/structure-prompt/reference/adversarial-tuning.md +62 -0
- package/skills/structure-prompt/reference/block-classification.md +27 -0
- package/skills/structure-prompt/reference/canonical-case.md +48 -0
- package/skills/structure-prompt/reference/citation-depth.md +70 -0
- package/skills/structure-prompt/reference/cleanup.md +33 -0
- package/skills/structure-prompt/reference/constraints.md +33 -0
- package/skills/structure-prompt/reference/directives.md +37 -0
- package/skills/structure-prompt/reference/examples.md +72 -0
- package/skills/structure-prompt/reference/instantiation.md +51 -0
- package/skills/structure-prompt/reference/output-contract.md +72 -0
- package/skills/structure-prompt/reference/per-category.md +23 -0
- package/skills/structure-prompt/reference/persona.md +38 -0
- package/skills/structure-prompt/reference/research.md +33 -0
- package/skills/structure-prompt/reference/structure.md +28 -0
- package/agents/code-standards-agent.md +0 -93
- package/agents/groq-coder.md +0 -113
- package/agents/plan-executor.md +0 -226
- package/agents/project-docs-analyzer.md +0 -53
- package/agents/project-structure-organizer-agent.md +0 -72
- package/agents/skill-to-agent-converter.md +0 -370
- package/agents/skill-writer-agent.md +0 -470
- package/agents/user-docs-writer.md +0 -67
- package/agents/workflow-visual-documenter.md +0 -82
- package/commands/readability-review.md +0 -20
- package/hooks/mypy.ini +0 -2
- package/hooks/notification/attention_needed_notify.py +0 -71
- package/hooks/notification/claude_notification_handler.py +0 -67
- package/hooks/notification/notification_utils.py +0 -267
- package/hooks/notification/subagent_complete_notify.py +0 -381
- package/hooks/notification/test_attention_needed_notify.py +0 -47
- package/hooks/notification/test_claude_notification_handler.py +0 -54
- package/hooks/notification/test_notification_utils.py +0 -91
- package/hooks/notification/test_subagent_complete_notify.py +0 -79
- package/scripts/config/groq_bugteam_config.py +0 -230
- package/scripts/config/test_groq_bugteam_config.py +0 -83
- package/scripts/config/test_spec_implementer_prompt.py +0 -32
- package/scripts/groq_bugteam.README.md +0 -131
- package/scripts/groq_bugteam.py +0 -647
- package/scripts/groq_bugteam_dotenv.py +0 -40
- package/scripts/groq_bugteam_spec.py +0 -226
- package/scripts/test_groq_bugteam.py +0 -529
- package/scripts/test_groq_bugteam_apply_fix_from_spec.py +0 -426
- package/scripts/test_groq_bugteam_dotenv.py +0 -66
- package/scripts/test_groq_bugteam_spec.py +0 -338
- package/skills/bugteam/SKILL_EVALS.md +0 -309
- package/skills/dream/SKILL.md +0 -118
- package/skills/ingest/SKILL.md +0 -40
- package/skills/npm-creator/SKILL.md +0 -187
- package/skills/readability-review/SKILL.md +0 -127
- package/skills/resume-review/SKILL.md +0 -261
- package/skills/rule-audit/SKILL.md +0 -307
- package/skills/rule-creator/SKILL.md +0 -150
- package/skills/searching-obsidian-vault/SKILL.md +0 -131
- package/skills/skill-writer/REFERENCE.md +0 -284
- package/skills/skill-writer/SKILL.md +0 -222
- package/skills/tdd-team/SKILL.md +0 -128
|
@@ -0,0 +1,722 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Birchline — Support reply prompt tuner</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
--ivory: #FAF9F5;
|
|
10
|
+
--slate: #141413;
|
|
11
|
+
--clay: #D97757;
|
|
12
|
+
--clay-d: #B85C3E;
|
|
13
|
+
--oat: #E3DACC;
|
|
14
|
+
--olive: #788C5D;
|
|
15
|
+
--gray-50: #F0EEE6;
|
|
16
|
+
--gray-200: #D1CFC5;
|
|
17
|
+
--gray-500: #87867F;
|
|
18
|
+
--gray-800: #3D3D3A;
|
|
19
|
+
--white: #ffffff;
|
|
20
|
+
--serif: ui-serif, Georgia, "Times New Roman", serif;
|
|
21
|
+
--sans: system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
22
|
+
--mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
|
|
23
|
+
}
|
|
24
|
+
* { box-sizing: border-box; }
|
|
25
|
+
html, body {
|
|
26
|
+
margin: 0;
|
|
27
|
+
background: var(--ivory);
|
|
28
|
+
color: var(--slate);
|
|
29
|
+
font-family: var(--sans);
|
|
30
|
+
font-size: 14px;
|
|
31
|
+
line-height: 1.5;
|
|
32
|
+
}
|
|
33
|
+
.wrap {
|
|
34
|
+
max-width: 1180px;
|
|
35
|
+
margin: 0 auto;
|
|
36
|
+
padding: 48px 32px 64px;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* ---------- header ---------- */
|
|
40
|
+
header { margin-bottom: 22px; }
|
|
41
|
+
.eyebrow {
|
|
42
|
+
font-family: var(--mono);
|
|
43
|
+
font-size: 11px;
|
|
44
|
+
letter-spacing: 0.08em;
|
|
45
|
+
text-transform: uppercase;
|
|
46
|
+
color: var(--gray-500);
|
|
47
|
+
}
|
|
48
|
+
h1 {
|
|
49
|
+
font-family: var(--serif);
|
|
50
|
+
font-weight: 500;
|
|
51
|
+
font-size: 30px;
|
|
52
|
+
letter-spacing: -0.01em;
|
|
53
|
+
margin: 6px 0 4px;
|
|
54
|
+
}
|
|
55
|
+
.sub {
|
|
56
|
+
color: var(--gray-500);
|
|
57
|
+
max-width: 640px;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* ---------- toolbar ---------- */
|
|
61
|
+
.toolbar {
|
|
62
|
+
position: sticky;
|
|
63
|
+
top: 0;
|
|
64
|
+
z-index: 10;
|
|
65
|
+
display: flex;
|
|
66
|
+
align-items: center;
|
|
67
|
+
gap: 10px;
|
|
68
|
+
background: var(--ivory);
|
|
69
|
+
padding: 10px 0 14px;
|
|
70
|
+
margin-bottom: 6px;
|
|
71
|
+
border-bottom: 1px solid var(--gray-200);
|
|
72
|
+
}
|
|
73
|
+
.toolbar .spacer { flex: 1; }
|
|
74
|
+
.toolbar .hint {
|
|
75
|
+
font-family: var(--mono);
|
|
76
|
+
font-size: 11px;
|
|
77
|
+
color: var(--gray-500);
|
|
78
|
+
letter-spacing: 0.02em;
|
|
79
|
+
}
|
|
80
|
+
button {
|
|
81
|
+
font-family: var(--mono);
|
|
82
|
+
font-size: 12px;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
-webkit-appearance: none;
|
|
85
|
+
appearance: none;
|
|
86
|
+
}
|
|
87
|
+
.btn-primary {
|
|
88
|
+
background: var(--slate);
|
|
89
|
+
color: var(--ivory);
|
|
90
|
+
border: 1.5px solid var(--slate);
|
|
91
|
+
border-radius: 999px;
|
|
92
|
+
padding: 9px 16px;
|
|
93
|
+
transition: background 140ms ease, transform 80ms ease;
|
|
94
|
+
}
|
|
95
|
+
.btn-primary:hover { background: var(--gray-800); }
|
|
96
|
+
.btn-primary:active { transform: translateY(1px); }
|
|
97
|
+
.btn-primary.copied { background: var(--olive); border-color: var(--olive); }
|
|
98
|
+
.btn-ghost {
|
|
99
|
+
background: transparent;
|
|
100
|
+
color: var(--gray-800);
|
|
101
|
+
border: 1.5px solid var(--gray-200);
|
|
102
|
+
border-radius: 999px;
|
|
103
|
+
padding: 8px 15px;
|
|
104
|
+
transition: border-color 140ms ease, color 140ms ease;
|
|
105
|
+
}
|
|
106
|
+
.btn-ghost:hover { border-color: var(--gray-500); color: var(--slate); }
|
|
107
|
+
|
|
108
|
+
/* ---------- two-column layout ---------- */
|
|
109
|
+
.cols {
|
|
110
|
+
display: grid;
|
|
111
|
+
grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
|
|
112
|
+
gap: 24px;
|
|
113
|
+
align-items: start;
|
|
114
|
+
margin-top: 18px;
|
|
115
|
+
}
|
|
116
|
+
@media (max-width: 880px) {
|
|
117
|
+
.cols { grid-template-columns: 1fr; }
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.panel {
|
|
121
|
+
background: var(--white);
|
|
122
|
+
border: 1.5px solid var(--gray-200);
|
|
123
|
+
border-radius: 12px;
|
|
124
|
+
overflow: hidden;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/* ---------- left: editor ---------- */
|
|
128
|
+
.ed-toolbar {
|
|
129
|
+
display: flex;
|
|
130
|
+
align-items: center;
|
|
131
|
+
gap: 10px;
|
|
132
|
+
padding: 11px 16px;
|
|
133
|
+
border-bottom: 1.5px solid var(--gray-200);
|
|
134
|
+
background: var(--gray-50);
|
|
135
|
+
}
|
|
136
|
+
.ed-label {
|
|
137
|
+
font-family: var(--mono);
|
|
138
|
+
font-size: 11px;
|
|
139
|
+
letter-spacing: 0.1em;
|
|
140
|
+
color: var(--gray-500);
|
|
141
|
+
text-transform: uppercase;
|
|
142
|
+
}
|
|
143
|
+
.ed-toolbar .spacer { flex: 1; }
|
|
144
|
+
.counter {
|
|
145
|
+
font-family: var(--mono);
|
|
146
|
+
font-size: 11px;
|
|
147
|
+
color: var(--gray-800);
|
|
148
|
+
background: var(--white);
|
|
149
|
+
border: 1.5px solid var(--gray-200);
|
|
150
|
+
border-radius: 999px;
|
|
151
|
+
padding: 3px 10px;
|
|
152
|
+
white-space: nowrap;
|
|
153
|
+
font-variant-numeric: tabular-nums;
|
|
154
|
+
}
|
|
155
|
+
.editor {
|
|
156
|
+
font-family: var(--mono);
|
|
157
|
+
font-size: 13px;
|
|
158
|
+
line-height: 1.7;
|
|
159
|
+
padding: 18px;
|
|
160
|
+
min-height: 360px;
|
|
161
|
+
white-space: pre-wrap;
|
|
162
|
+
word-break: break-word;
|
|
163
|
+
background: var(--white);
|
|
164
|
+
color: var(--slate);
|
|
165
|
+
outline: none;
|
|
166
|
+
caret-color: var(--clay);
|
|
167
|
+
tab-size: 2;
|
|
168
|
+
}
|
|
169
|
+
.editor:focus-visible { outline: none; }
|
|
170
|
+
.slot {
|
|
171
|
+
background: var(--oat);
|
|
172
|
+
color: var(--clay-d);
|
|
173
|
+
border-radius: 4px;
|
|
174
|
+
padding: 0 3px;
|
|
175
|
+
font-weight: 600;
|
|
176
|
+
}
|
|
177
|
+
.slot.warn {
|
|
178
|
+
background: rgba(217, 119, 87, 0.14);
|
|
179
|
+
color: var(--clay-d);
|
|
180
|
+
text-decoration: underline dashed var(--clay) 1.5px;
|
|
181
|
+
text-underline-offset: 3px;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.legend {
|
|
185
|
+
border-top: 1.5px solid var(--gray-200);
|
|
186
|
+
padding: 12px 16px 14px;
|
|
187
|
+
background: var(--gray-50);
|
|
188
|
+
}
|
|
189
|
+
.legend-label {
|
|
190
|
+
font-family: var(--mono);
|
|
191
|
+
font-size: 10px;
|
|
192
|
+
letter-spacing: 0.1em;
|
|
193
|
+
text-transform: uppercase;
|
|
194
|
+
color: var(--gray-500);
|
|
195
|
+
margin-bottom: 8px;
|
|
196
|
+
}
|
|
197
|
+
.legend-chips { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
198
|
+
.chip {
|
|
199
|
+
font-family: var(--mono);
|
|
200
|
+
font-size: 11px;
|
|
201
|
+
background: var(--oat);
|
|
202
|
+
color: var(--clay-d);
|
|
203
|
+
border-radius: 4px;
|
|
204
|
+
padding: 2px 7px;
|
|
205
|
+
font-weight: 600;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/* ---------- right: preview ---------- */
|
|
209
|
+
.preview-panel { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
|
|
210
|
+
.preview-head {
|
|
211
|
+
font-family: var(--mono);
|
|
212
|
+
font-size: 11px;
|
|
213
|
+
letter-spacing: 0.1em;
|
|
214
|
+
text-transform: uppercase;
|
|
215
|
+
color: var(--gray-500);
|
|
216
|
+
padding: 0 2px 2px;
|
|
217
|
+
}
|
|
218
|
+
.sample {
|
|
219
|
+
border: 1.5px solid var(--gray-200);
|
|
220
|
+
border-radius: 10px;
|
|
221
|
+
overflow: hidden;
|
|
222
|
+
}
|
|
223
|
+
.sample-head {
|
|
224
|
+
display: flex;
|
|
225
|
+
align-items: center;
|
|
226
|
+
gap: 9px;
|
|
227
|
+
padding: 9px 13px;
|
|
228
|
+
border-bottom: 1.5px solid var(--gray-200);
|
|
229
|
+
background: var(--gray-50);
|
|
230
|
+
}
|
|
231
|
+
.badge {
|
|
232
|
+
font-family: var(--mono);
|
|
233
|
+
font-size: 10px;
|
|
234
|
+
letter-spacing: 0.08em;
|
|
235
|
+
color: var(--gray-500);
|
|
236
|
+
}
|
|
237
|
+
.cust {
|
|
238
|
+
font-family: var(--serif);
|
|
239
|
+
font-size: 14px;
|
|
240
|
+
font-weight: 500;
|
|
241
|
+
letter-spacing: -0.005em;
|
|
242
|
+
}
|
|
243
|
+
.sample-head .spacer { flex: 1; }
|
|
244
|
+
.plan {
|
|
245
|
+
font-family: var(--mono);
|
|
246
|
+
font-size: 10px;
|
|
247
|
+
letter-spacing: 0.05em;
|
|
248
|
+
text-transform: uppercase;
|
|
249
|
+
border-radius: 999px;
|
|
250
|
+
padding: 2px 8px;
|
|
251
|
+
border: 1.5px solid var(--gray-200);
|
|
252
|
+
color: var(--gray-800);
|
|
253
|
+
background: var(--white);
|
|
254
|
+
}
|
|
255
|
+
.plan.team { background: var(--oat); border-color: var(--oat); color: var(--clay-d); }
|
|
256
|
+
.plan.studio { background: var(--olive); border-color: var(--olive); color: var(--ivory); }
|
|
257
|
+
.rendered {
|
|
258
|
+
font-family: var(--mono);
|
|
259
|
+
font-size: 12.5px;
|
|
260
|
+
line-height: 1.6;
|
|
261
|
+
color: var(--gray-800);
|
|
262
|
+
white-space: pre-wrap;
|
|
263
|
+
word-break: break-word;
|
|
264
|
+
padding: 12px 13px 14px;
|
|
265
|
+
}
|
|
266
|
+
.filled {
|
|
267
|
+
background: var(--gray-50);
|
|
268
|
+
border-radius: 3px;
|
|
269
|
+
padding: 0 2px;
|
|
270
|
+
box-shadow: inset 0 0 0 1px var(--gray-200);
|
|
271
|
+
}
|
|
272
|
+
.missing {
|
|
273
|
+
background: rgba(217, 119, 87, 0.12);
|
|
274
|
+
color: var(--clay-d);
|
|
275
|
+
border-radius: 3px;
|
|
276
|
+
padding: 0 2px;
|
|
277
|
+
font-weight: 600;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
footer {
|
|
281
|
+
margin-top: 36px;
|
|
282
|
+
font-family: var(--mono);
|
|
283
|
+
font-size: 11px;
|
|
284
|
+
color: var(--gray-500);
|
|
285
|
+
letter-spacing: 0.02em;
|
|
286
|
+
}
|
|
287
|
+
</style>
|
|
288
|
+
</head>
|
|
289
|
+
<body>
|
|
290
|
+
<div class="wrap">
|
|
291
|
+
|
|
292
|
+
<header>
|
|
293
|
+
<div class="eyebrow">Birchline / editor / prompt-tuner</div>
|
|
294
|
+
<h1>Support reply draft prompt</h1>
|
|
295
|
+
<p class="sub">Edit the system prompt on the left and watch three real sample tickets re-render the filled template on the right, live as you type. When it reads well across all three moods, copy the template out.</p>
|
|
296
|
+
</header>
|
|
297
|
+
|
|
298
|
+
<div class="toolbar">
|
|
299
|
+
<button id="copyBtn" class="btn-primary">Copy prompt</button>
|
|
300
|
+
<button id="resetBtn" class="btn-ghost">Reset</button>
|
|
301
|
+
<div class="spacer"></div>
|
|
302
|
+
<div class="hint">slots use <strong>{{double_brace}}</strong> syntax</div>
|
|
303
|
+
</div>
|
|
304
|
+
|
|
305
|
+
<div class="cols">
|
|
306
|
+
|
|
307
|
+
<!-- left -->
|
|
308
|
+
<section class="panel">
|
|
309
|
+
<div class="ed-toolbar">
|
|
310
|
+
<span class="ed-label">Template</span>
|
|
311
|
+
<div class="spacer"></div>
|
|
312
|
+
<span id="counter" class="counter">0 chars · ~0 tokens</span>
|
|
313
|
+
</div>
|
|
314
|
+
<div id="editor" class="editor" contenteditable="true" spellcheck="false" autocapitalize="off" autocorrect="off"></div>
|
|
315
|
+
<div class="legend">
|
|
316
|
+
<div class="legend-label">Available slots</div>
|
|
317
|
+
<div id="legendChips" class="legend-chips"></div>
|
|
318
|
+
</div>
|
|
319
|
+
</section>
|
|
320
|
+
|
|
321
|
+
<!-- right -->
|
|
322
|
+
<section class="panel preview-panel">
|
|
323
|
+
<div class="preview-head">Live preview · 3 sample tickets</div>
|
|
324
|
+
<div id="samples"></div>
|
|
325
|
+
</section>
|
|
326
|
+
|
|
327
|
+
</div>
|
|
328
|
+
|
|
329
|
+
<footer>Highlighted slots fill from each sample's ticket fields. Anything underlined in dashed clay isn't a known field and will pass through unfilled.</footer>
|
|
330
|
+
|
|
331
|
+
</div>
|
|
332
|
+
|
|
333
|
+
<script>
|
|
334
|
+
(function () {
|
|
335
|
+
"use strict";
|
|
336
|
+
|
|
337
|
+
// ---------------------------------------------------------------------------
|
|
338
|
+
// Data
|
|
339
|
+
// ---------------------------------------------------------------------------
|
|
340
|
+
|
|
341
|
+
var DEFAULT_TEMPLATE =
|
|
342
|
+
'You are a support agent for Birchline, a project workspace for small teams.\n' +
|
|
343
|
+
'\n' +
|
|
344
|
+
'A customer named {{customer_name}} on the {{plan_tier}} plan wrote in about:\n' +
|
|
345
|
+
'"{{ticket_subject}}"\n' +
|
|
346
|
+
'\n' +
|
|
347
|
+
'Their message:\n' +
|
|
348
|
+
'{{ticket_body}}\n' +
|
|
349
|
+
'\n' +
|
|
350
|
+
'Write a reply that is {{tone}}, no more than 120 words, and ends with a single concrete next step.\n' +
|
|
351
|
+
'Never promise a refund without escalating. Sign off as "The Birchline team."';
|
|
352
|
+
|
|
353
|
+
var SAMPLES = [
|
|
354
|
+
{
|
|
355
|
+
label: 'SAMPLE 1',
|
|
356
|
+
planClass: 'free',
|
|
357
|
+
data: {
|
|
358
|
+
customer_name: 'Priya N.',
|
|
359
|
+
plan_tier: 'Free',
|
|
360
|
+
ticket_subject: 'Where did my board go?',
|
|
361
|
+
ticket_body: 'Hi — I made a board yesterday called "Spring launch" with my coworker and today I can’t find it anywhere. I’m new to Birchline and I’m not sure if I deleted it by accident or if I’m just looking in the wrong place. Can you help?',
|
|
362
|
+
tone: 'warm and patient'
|
|
363
|
+
}
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
label: 'SAMPLE 2',
|
|
367
|
+
planClass: 'team',
|
|
368
|
+
data: {
|
|
369
|
+
customer_name: 'Marcus D.',
|
|
370
|
+
plan_tier: 'Team',
|
|
371
|
+
ticket_subject: 'Sync keeps dropping comments',
|
|
372
|
+
ticket_body: 'This is the third time this week. I leave comments on cards from my laptop, switch to my phone on the train, and they’re gone. My team thinks I’m ignoring them. We pay for 14 seats and this is genuinely making us look bad to a client.',
|
|
373
|
+
tone: 'direct and apologetic'
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
label: 'SAMPLE 3',
|
|
378
|
+
planClass: 'studio',
|
|
379
|
+
data: {
|
|
380
|
+
customer_name: 'Lena K.',
|
|
381
|
+
plan_tier: 'Studio',
|
|
382
|
+
ticket_subject: 'Update billing entity on next invoice',
|
|
383
|
+
ticket_body: 'Hey folks! We just spun up a new holding company (Korhonen Studio Oy) and finance would love the May invoice to use that name + our new VAT ID, FI28361049. No rush at all, just want it sorted before the cycle runs. Thanks a million.',
|
|
384
|
+
tone: 'brisk and friendly'
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
];
|
|
388
|
+
|
|
389
|
+
var KNOWN_SLOTS = ['customer_name', 'plan_tier', 'ticket_subject', 'ticket_body', 'tone'];
|
|
390
|
+
var SLOT_RE = /\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g;
|
|
391
|
+
|
|
392
|
+
// ---------------------------------------------------------------------------
|
|
393
|
+
// DOM refs
|
|
394
|
+
// ---------------------------------------------------------------------------
|
|
395
|
+
|
|
396
|
+
var editor = document.getElementById('editor');
|
|
397
|
+
var counterEl = document.getElementById('counter');
|
|
398
|
+
var samplesEl = document.getElementById('samples');
|
|
399
|
+
var legendEl = document.getElementById('legendChips');
|
|
400
|
+
var copyBtn = document.getElementById('copyBtn');
|
|
401
|
+
var resetBtn = document.getElementById('resetBtn');
|
|
402
|
+
|
|
403
|
+
// ---------------------------------------------------------------------------
|
|
404
|
+
// Helpers
|
|
405
|
+
// ---------------------------------------------------------------------------
|
|
406
|
+
|
|
407
|
+
function escapeHtml(s) {
|
|
408
|
+
return s
|
|
409
|
+
.replace(/&/g, '&')
|
|
410
|
+
.replace(/</g, '<')
|
|
411
|
+
.replace(/>/g, '>')
|
|
412
|
+
.replace(/"/g, '"');
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// Read plain text out of the contenteditable. We rely on white-space:pre-wrap
|
|
416
|
+
// and only ever insert text + inline <span>s, so textContent is faithful as
|
|
417
|
+
// long as the browser hasn't injected block elements or <br>s. Normalize both.
|
|
418
|
+
function getPlainText() {
|
|
419
|
+
var out = '';
|
|
420
|
+
var walker = document.createTreeWalker(editor, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT, null);
|
|
421
|
+
var node;
|
|
422
|
+
while ((node = walker.nextNode())) {
|
|
423
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
424
|
+
out += node.nodeValue;
|
|
425
|
+
} else if (node.nodeType === Node.ELEMENT_NODE) {
|
|
426
|
+
var tag = node.tagName;
|
|
427
|
+
if (tag === 'BR') out += '\n';
|
|
428
|
+
// Some browsers wrap new lines in <div>; emit a newline before a div
|
|
429
|
+
// that isn't the first child and doesn't already start after one.
|
|
430
|
+
if (tag === 'DIV' && node !== editor.firstChild && out.length && out[out.length - 1] !== '\n') {
|
|
431
|
+
out += '\n';
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return out;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// ---- Caret save/restore by character offset ----
|
|
439
|
+
|
|
440
|
+
function getCaretOffset() {
|
|
441
|
+
var sel = window.getSelection();
|
|
442
|
+
if (!sel || sel.rangeCount === 0) return null;
|
|
443
|
+
var range = sel.getRangeAt(0);
|
|
444
|
+
if (!editor.contains(range.startContainer)) return null;
|
|
445
|
+
|
|
446
|
+
var pre = range.cloneRange();
|
|
447
|
+
pre.selectNodeContents(editor);
|
|
448
|
+
pre.setEnd(range.startContainer, range.startOffset);
|
|
449
|
+
|
|
450
|
+
// Count characters by walking text nodes within the pre-range. We mirror
|
|
451
|
+
// getPlainText's newline handling so offsets line up.
|
|
452
|
+
var frag = pre.cloneContents();
|
|
453
|
+
var off = 0;
|
|
454
|
+
var walker = document.createTreeWalker(frag, NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT, null);
|
|
455
|
+
var node, lastChar = '';
|
|
456
|
+
var first = true;
|
|
457
|
+
while ((node = walker.nextNode())) {
|
|
458
|
+
if (node.nodeType === Node.TEXT_NODE) {
|
|
459
|
+
off += node.nodeValue.length;
|
|
460
|
+
if (node.nodeValue.length) lastChar = node.nodeValue[node.nodeValue.length - 1];
|
|
461
|
+
} else {
|
|
462
|
+
if (node.tagName === 'BR') { off += 1; lastChar = '\n'; }
|
|
463
|
+
if (node.tagName === 'DIV' && !first && lastChar !== '\n') { off += 1; lastChar = '\n'; }
|
|
464
|
+
}
|
|
465
|
+
first = false;
|
|
466
|
+
}
|
|
467
|
+
return off;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function setCaretOffset(offset) {
|
|
471
|
+
if (offset == null) return;
|
|
472
|
+
var sel = window.getSelection();
|
|
473
|
+
if (!sel) return;
|
|
474
|
+
|
|
475
|
+
var walker = document.createTreeWalker(editor, NodeFilter.SHOW_TEXT, null);
|
|
476
|
+
var node;
|
|
477
|
+
var remaining = offset;
|
|
478
|
+
var lastNode = null;
|
|
479
|
+
|
|
480
|
+
while ((node = walker.nextNode())) {
|
|
481
|
+
lastNode = node;
|
|
482
|
+
var len = node.nodeValue.length;
|
|
483
|
+
if (remaining <= len) {
|
|
484
|
+
var range = document.createRange();
|
|
485
|
+
range.setStart(node, remaining);
|
|
486
|
+
range.collapse(true);
|
|
487
|
+
sel.removeAllRanges();
|
|
488
|
+
sel.addRange(range);
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
remaining -= len;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
// Past the end — place at end of last text node, or at end of editor.
|
|
495
|
+
var range2 = document.createRange();
|
|
496
|
+
if (lastNode) {
|
|
497
|
+
range2.setStart(lastNode, lastNode.nodeValue.length);
|
|
498
|
+
} else {
|
|
499
|
+
range2.selectNodeContents(editor);
|
|
500
|
+
range2.collapse(false);
|
|
501
|
+
}
|
|
502
|
+
range2.collapse(true);
|
|
503
|
+
sel.removeAllRanges();
|
|
504
|
+
sel.addRange(range2);
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// ---- Highlighting ----
|
|
508
|
+
|
|
509
|
+
function highlightHtml(text) {
|
|
510
|
+
var html = '';
|
|
511
|
+
var last = 0;
|
|
512
|
+
SLOT_RE.lastIndex = 0;
|
|
513
|
+
var m;
|
|
514
|
+
while ((m = SLOT_RE.exec(text)) !== null) {
|
|
515
|
+
html += escapeHtml(text.slice(last, m.index));
|
|
516
|
+
var name = m[1];
|
|
517
|
+
var cls = KNOWN_SLOTS.indexOf(name) !== -1 ? 'slot' : 'slot warn';
|
|
518
|
+
html += '<span class="' + cls + '">' + escapeHtml(m[0]) + '</span>';
|
|
519
|
+
last = m.index + m[0].length;
|
|
520
|
+
}
|
|
521
|
+
html += escapeHtml(text.slice(last));
|
|
522
|
+
return html;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
function renderEditor(text, caret) {
|
|
526
|
+
editor.innerHTML = highlightHtml(text);
|
|
527
|
+
if (caret != null && document.activeElement === editor) {
|
|
528
|
+
setCaretOffset(caret);
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
// ---- Preview ----
|
|
533
|
+
|
|
534
|
+
function fillHtml(text, data) {
|
|
535
|
+
var html = '';
|
|
536
|
+
var last = 0;
|
|
537
|
+
SLOT_RE.lastIndex = 0;
|
|
538
|
+
var m;
|
|
539
|
+
while ((m = SLOT_RE.exec(text)) !== null) {
|
|
540
|
+
html += escapeHtml(text.slice(last, m.index));
|
|
541
|
+
var name = m[1];
|
|
542
|
+
if (Object.prototype.hasOwnProperty.call(data, name)) {
|
|
543
|
+
html += '<span class="filled">' + escapeHtml(String(data[name])) + '</span>';
|
|
544
|
+
} else {
|
|
545
|
+
html += '<span class="missing">' + escapeHtml(m[0]) + '</span>';
|
|
546
|
+
}
|
|
547
|
+
last = m.index + m[0].length;
|
|
548
|
+
}
|
|
549
|
+
html += escapeHtml(text.slice(last));
|
|
550
|
+
return html;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
var sampleNodes = [];
|
|
554
|
+
|
|
555
|
+
function buildSamples() {
|
|
556
|
+
samplesEl.innerHTML = '';
|
|
557
|
+
sampleNodes = [];
|
|
558
|
+
SAMPLES.forEach(function (s) {
|
|
559
|
+
var card = document.createElement('div');
|
|
560
|
+
card.className = 'sample';
|
|
561
|
+
|
|
562
|
+
var head = document.createElement('div');
|
|
563
|
+
head.className = 'sample-head';
|
|
564
|
+
|
|
565
|
+
var badge = document.createElement('span');
|
|
566
|
+
badge.className = 'badge';
|
|
567
|
+
badge.textContent = s.label;
|
|
568
|
+
|
|
569
|
+
var cust = document.createElement('span');
|
|
570
|
+
cust.className = 'cust';
|
|
571
|
+
cust.textContent = s.data.customer_name;
|
|
572
|
+
|
|
573
|
+
var spacer = document.createElement('span');
|
|
574
|
+
spacer.className = 'spacer';
|
|
575
|
+
|
|
576
|
+
var plan = document.createElement('span');
|
|
577
|
+
plan.className = 'plan ' + s.planClass;
|
|
578
|
+
plan.textContent = s.data.plan_tier;
|
|
579
|
+
|
|
580
|
+
head.appendChild(badge);
|
|
581
|
+
head.appendChild(cust);
|
|
582
|
+
head.appendChild(spacer);
|
|
583
|
+
head.appendChild(plan);
|
|
584
|
+
|
|
585
|
+
var body = document.createElement('div');
|
|
586
|
+
body.className = 'rendered';
|
|
587
|
+
|
|
588
|
+
card.appendChild(head);
|
|
589
|
+
card.appendChild(body);
|
|
590
|
+
samplesEl.appendChild(card);
|
|
591
|
+
sampleNodes.push({ body: body, data: s.data });
|
|
592
|
+
});
|
|
593
|
+
samplesEl.style.display = 'flex';
|
|
594
|
+
samplesEl.style.flexDirection = 'column';
|
|
595
|
+
samplesEl.style.gap = '14px';
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
function buildLegend() {
|
|
599
|
+
legendEl.innerHTML = '';
|
|
600
|
+
KNOWN_SLOTS.forEach(function (name) {
|
|
601
|
+
var c = document.createElement('span');
|
|
602
|
+
c.className = 'chip';
|
|
603
|
+
c.textContent = '{{' + name + '}}';
|
|
604
|
+
legendEl.appendChild(c);
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
// ---- Counter ----
|
|
609
|
+
|
|
610
|
+
function updateCounter(text) {
|
|
611
|
+
var chars = text.length;
|
|
612
|
+
var tokens = Math.round(chars / 4.2);
|
|
613
|
+
counterEl.textContent = chars + ' chars · ~' + tokens + ' tokens';
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// ---- Master refresh ----
|
|
617
|
+
|
|
618
|
+
function refresh(opts) {
|
|
619
|
+
opts = opts || {};
|
|
620
|
+
var text = opts.text != null ? opts.text : getPlainText();
|
|
621
|
+
var caret = opts.preserveCaret ? getCaretOffset() : null;
|
|
622
|
+
|
|
623
|
+
renderEditor(text, caret);
|
|
624
|
+
updateCounter(text);
|
|
625
|
+
sampleNodes.forEach(function (sn) {
|
|
626
|
+
sn.body.innerHTML = fillHtml(text, sn.data);
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// ---------------------------------------------------------------------------
|
|
631
|
+
// Events
|
|
632
|
+
// ---------------------------------------------------------------------------
|
|
633
|
+
|
|
634
|
+
var raf = null;
|
|
635
|
+
editor.addEventListener('input', function () {
|
|
636
|
+
if (raf) cancelAnimationFrame(raf);
|
|
637
|
+
raf = requestAnimationFrame(function () {
|
|
638
|
+
raf = null;
|
|
639
|
+
refresh({ preserveCaret: true });
|
|
640
|
+
});
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
// Force plain-text paste so we never inherit foreign HTML.
|
|
644
|
+
editor.addEventListener('paste', function (e) {
|
|
645
|
+
e.preventDefault();
|
|
646
|
+
var txt = (e.clipboardData || window.clipboardData).getData('text/plain');
|
|
647
|
+
var sel = window.getSelection();
|
|
648
|
+
if (!sel || !sel.rangeCount) return;
|
|
649
|
+
var range = sel.getRangeAt(0);
|
|
650
|
+
range.deleteContents();
|
|
651
|
+
range.insertNode(document.createTextNode(txt));
|
|
652
|
+
range.collapse(false);
|
|
653
|
+
sel.removeAllRanges();
|
|
654
|
+
sel.addRange(range);
|
|
655
|
+
refresh({ preserveCaret: true });
|
|
656
|
+
});
|
|
657
|
+
|
|
658
|
+
// Insert literal newline on Enter so we don't get nested <div>s.
|
|
659
|
+
editor.addEventListener('keydown', function (e) {
|
|
660
|
+
if (e.key === 'Enter') {
|
|
661
|
+
e.preventDefault();
|
|
662
|
+
var sel = window.getSelection();
|
|
663
|
+
if (!sel || !sel.rangeCount) return;
|
|
664
|
+
var range = sel.getRangeAt(0);
|
|
665
|
+
range.deleteContents();
|
|
666
|
+
var nl = document.createTextNode('\n');
|
|
667
|
+
range.insertNode(nl);
|
|
668
|
+
range.setStartAfter(nl);
|
|
669
|
+
range.collapse(true);
|
|
670
|
+
sel.removeAllRanges();
|
|
671
|
+
sel.addRange(range);
|
|
672
|
+
refresh({ preserveCaret: true });
|
|
673
|
+
}
|
|
674
|
+
});
|
|
675
|
+
|
|
676
|
+
var copyTimer = null;
|
|
677
|
+
copyBtn.addEventListener('click', function () {
|
|
678
|
+
var text = getPlainText();
|
|
679
|
+
var done = function () {
|
|
680
|
+
copyBtn.textContent = 'Copied ✓';
|
|
681
|
+
copyBtn.classList.add('copied');
|
|
682
|
+
if (copyTimer) clearTimeout(copyTimer);
|
|
683
|
+
copyTimer = setTimeout(function () {
|
|
684
|
+
copyBtn.textContent = 'Copy prompt';
|
|
685
|
+
copyBtn.classList.remove('copied');
|
|
686
|
+
}, 1200);
|
|
687
|
+
};
|
|
688
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
689
|
+
navigator.clipboard.writeText(text).then(done, function () {
|
|
690
|
+
fallbackCopy(text); done();
|
|
691
|
+
});
|
|
692
|
+
} else {
|
|
693
|
+
fallbackCopy(text); done();
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
function fallbackCopy(text) {
|
|
698
|
+
var ta = document.createElement('textarea');
|
|
699
|
+
ta.value = text;
|
|
700
|
+
ta.style.position = 'fixed';
|
|
701
|
+
ta.style.left = '-9999px';
|
|
702
|
+
document.body.appendChild(ta);
|
|
703
|
+
ta.select();
|
|
704
|
+
try { document.execCommand('copy'); } catch (e) { /* ignore */ }
|
|
705
|
+
document.body.removeChild(ta);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
resetBtn.addEventListener('click', function () {
|
|
709
|
+
refresh({ text: DEFAULT_TEMPLATE });
|
|
710
|
+
});
|
|
711
|
+
|
|
712
|
+
// ---------------------------------------------------------------------------
|
|
713
|
+
// Boot
|
|
714
|
+
// ---------------------------------------------------------------------------
|
|
715
|
+
|
|
716
|
+
buildLegend();
|
|
717
|
+
buildSamples();
|
|
718
|
+
refresh({ text: DEFAULT_TEMPLATE });
|
|
719
|
+
})();
|
|
720
|
+
</script>
|
|
721
|
+
</body>
|
|
722
|
+
</html>
|