@kujolang/paperclip 0.1.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/CHANGELOG.md +18 -0
- package/LICENSE +21 -0
- package/README.md +116 -0
- package/SECURITY.md +35 -0
- package/VERSION +1 -0
- package/bundled/components/changebucket/LICENSE +9 -0
- package/bundled/components/changebucket/changebucket.kujo +12 -0
- package/bundled/components/changebucket/src/analyze.kujo +240 -0
- package/bundled/components/changebucket/src/budget.kujo +92 -0
- package/bundled/components/changebucket/src/classify.kujo +221 -0
- package/bundled/components/changebucket/src/cli.kujo +324 -0
- package/bundled/components/changebucket/src/diffsrc.kujo +252 -0
- package/bundled/components/changebucket/src/render.kujo +346 -0
- package/bundled/components/changebucket/src/util.kujo +62 -0
- package/bundled/components/context/LICENSE +9 -0
- package/bundled/components/context/scent.kujo +3250 -0
- package/bundled/components/failure-evidence/LICENSE +9 -0
- package/bundled/components/failure-evidence/casefile.kujo +2061 -0
- package/bundled/components/patchbrief/LICENSE +9 -0
- package/bundled/components/patchbrief/patchbrief.kujo +153 -0
- package/bundled/components/patchbrief/schemas/patchbrief-handoff.schema.json +38 -0
- package/bundled/components/patchbrief/schemas/patchbrief-summary.schema.json +46 -0
- package/bundled/components/patchbrief/src/common.kujo +212 -0
- package/bundled/components/patchbrief/src/git.kujo +250 -0
- package/bundled/components/patchbrief/src/handoff.kujo +145 -0
- package/bundled/components/patchbrief/src/suggest_tests.kujo +137 -0
- package/bundled/components/patchbrief/src/summarize.kujo +309 -0
- package/bundled/kujo-components.lock.json +134 -0
- package/dist/manifest.js +14696 -0
- package/dist/ui/index.js +179 -0
- package/dist/worker.js +30536 -0
- package/docs/ARCHITECTURE.md +28 -0
- package/docs/CATALOG_SUBMISSION.md +25 -0
- package/docs/COMPATIBILITY.md +21 -0
- package/docs/CONFIGURATION.md +33 -0
- package/docs/INSTALLATION.md +53 -0
- package/docs/OPERATIONS.md +60 -0
- package/docs/README.md +18 -0
- package/docs/RELEASE_READINESS.md +46 -0
- package/docs/THREAT_MODEL.md +26 -0
- package/docs/TROUBLESHOOTING.md +12 -0
- package/docs/USAGE.md +95 -0
- package/examples/agent-workflow.md +20 -0
- package/package.json +71 -0
- package/schemas/changebucket-analysis.schema.json +25 -0
- package/schemas/context-pack.schema.json +23 -0
- package/schemas/failure-evidence.schema.json +18 -0
- package/schemas/review-pack.schema.json +19 -0
- package/skills/scoped-repository-context/SKILL.md +9 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kujolang <contact@kujolang.ai>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# PatchBrief — inspect git diffs and generate structured implementation briefs.
|
|
2
|
+
#
|
|
3
|
+
# Usage:
|
|
4
|
+
# kujo run patchbrief.kujo -- summarize [--format markdown|json] [--pretty]
|
|
5
|
+
# kujo run patchbrief.kujo -- suggest-tests
|
|
6
|
+
# kujo run patchbrief.kujo -- handoff [--format markdown|json] [--pretty]
|
|
7
|
+
# kujo run patchbrief.kujo -- version
|
|
8
|
+
# kujo run patchbrief.kujo -- help
|
|
9
|
+
|
|
10
|
+
from src.common import parse_subcommand, flag_value, has_flag, str_starts_with, print_lines
|
|
11
|
+
from src.git import is_git_repo
|
|
12
|
+
|
|
13
|
+
VERSION := "1.0.1"
|
|
14
|
+
|
|
15
|
+
func print_help() {
|
|
16
|
+
print_lines([
|
|
17
|
+
"PatchBrief v" + VERSION,
|
|
18
|
+
"",
|
|
19
|
+
"A local developer tool that inspects git diffs and generates",
|
|
20
|
+
"structured implementation briefs.",
|
|
21
|
+
"",
|
|
22
|
+
"Usage:",
|
|
23
|
+
" kujo run patchbrief.kujo -- summarize [--format markdown|json] [--pretty]",
|
|
24
|
+
" kujo run patchbrief.kujo -- suggest-tests",
|
|
25
|
+
" kujo run patchbrief.kujo -- handoff [--format markdown|json] [--pretty]",
|
|
26
|
+
" kujo run patchbrief.kujo -- version",
|
|
27
|
+
" kujo run patchbrief.kujo -- help",
|
|
28
|
+
"",
|
|
29
|
+
"Commands:",
|
|
30
|
+
" summarize Generate a summary of the current git diff",
|
|
31
|
+
" suggest-tests Suggest test commands based on changed files",
|
|
32
|
+
" handoff Generate a structured handoff note for reviewers",
|
|
33
|
+
" version Print version information",
|
|
34
|
+
" help Print this help message",
|
|
35
|
+
"",
|
|
36
|
+
"Options:",
|
|
37
|
+
" --format Output format: markdown (default) or json",
|
|
38
|
+
" --pretty Pretty-print JSON output when --format json is used",
|
|
39
|
+
"",
|
|
40
|
+
"Examples:",
|
|
41
|
+
" kujo run patchbrief.kujo -- summarize",
|
|
42
|
+
" kujo run patchbrief.kujo -- summarize --format json --pretty",
|
|
43
|
+
" kujo run patchbrief.kujo -- suggest-tests",
|
|
44
|
+
" kujo run patchbrief.kujo -- handoff",
|
|
45
|
+
"",
|
|
46
|
+
"Note: Use '--' before script arguments to avoid Kujo CLI flag parsing conflicts."
|
|
47
|
+
])
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
func print_version() {
|
|
51
|
+
print_lines([
|
|
52
|
+
"PatchBrief v" + VERSION,
|
|
53
|
+
"A Kujo ecosystem dogfood showcase tool.",
|
|
54
|
+
"https://github.com/kujolang/patchbrief"
|
|
55
|
+
])
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
func output_format(argv) {
|
|
59
|
+
mut fallback := "markdown"
|
|
60
|
+
if has_flag(argv, "--format") {
|
|
61
|
+
fallback = ""
|
|
62
|
+
}
|
|
63
|
+
format := flag_value(argv, "--format", fallback)
|
|
64
|
+
if format == "" || str_starts_with(format, "--") {
|
|
65
|
+
print("Error: Missing value for --format")
|
|
66
|
+
exit(2)
|
|
67
|
+
}
|
|
68
|
+
lower_format := to_lower(format)
|
|
69
|
+
if lower_format != "markdown" && lower_format != "json" {
|
|
70
|
+
print_lines([
|
|
71
|
+
"Error: Invalid format '" + format + "'.",
|
|
72
|
+
"Valid formats are: markdown, json"
|
|
73
|
+
])
|
|
74
|
+
exit(2)
|
|
75
|
+
}
|
|
76
|
+
return lower_format
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
func switch_to_caller_cwd() {
|
|
80
|
+
caller_cwd := env_or("PATCHBRIEF_CWD", "")
|
|
81
|
+
if caller_cwd != "" {
|
|
82
|
+
os_chdir(caller_cwd)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
func main() {
|
|
87
|
+
argv := args()
|
|
88
|
+
if len(argv) < 1 {
|
|
89
|
+
print_help()
|
|
90
|
+
exit(0)
|
|
91
|
+
}
|
|
92
|
+
subcommand := parse_subcommand(argv)
|
|
93
|
+
if subcommand == "" || subcommand == "help" {
|
|
94
|
+
if len(argv) > 0 {
|
|
95
|
+
first := to_string(argv[0])
|
|
96
|
+
if str_starts_with(first, "--") {
|
|
97
|
+
print_lines([
|
|
98
|
+
"Error: Command must come before PatchBrief flags.",
|
|
99
|
+
"Example: kujo run patchbrief.kujo -- summarize --format json",
|
|
100
|
+
""
|
|
101
|
+
])
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
print_help()
|
|
105
|
+
exit(0)
|
|
106
|
+
}
|
|
107
|
+
if subcommand == "version" {
|
|
108
|
+
print_version()
|
|
109
|
+
exit(0)
|
|
110
|
+
}
|
|
111
|
+
if subcommand == "summarize" {
|
|
112
|
+
format := output_format(argv)
|
|
113
|
+
pretty_json := has_flag(argv, "--pretty")
|
|
114
|
+
if format == "json" {
|
|
115
|
+
from src.summarize import summarize_json
|
|
116
|
+
switch_to_caller_cwd()
|
|
117
|
+
summarize_json(pretty_json)
|
|
118
|
+
} else {
|
|
119
|
+
from src.summarize import summarize_markdown
|
|
120
|
+
switch_to_caller_cwd()
|
|
121
|
+
summarize_markdown()
|
|
122
|
+
}
|
|
123
|
+
exit(0)
|
|
124
|
+
}
|
|
125
|
+
if subcommand == "suggest-tests" {
|
|
126
|
+
from src.suggest_tests import suggest_tests
|
|
127
|
+
switch_to_caller_cwd()
|
|
128
|
+
suggest_tests()
|
|
129
|
+
exit(0)
|
|
130
|
+
}
|
|
131
|
+
if subcommand == "handoff" {
|
|
132
|
+
format := output_format(argv)
|
|
133
|
+
pretty_json := has_flag(argv, "--pretty")
|
|
134
|
+
if format == "json" {
|
|
135
|
+
from src.handoff import handoff_json
|
|
136
|
+
switch_to_caller_cwd()
|
|
137
|
+
handoff_json(pretty_json)
|
|
138
|
+
} else {
|
|
139
|
+
from src.handoff import handoff_markdown
|
|
140
|
+
switch_to_caller_cwd()
|
|
141
|
+
handoff_markdown()
|
|
142
|
+
}
|
|
143
|
+
exit(0)
|
|
144
|
+
}
|
|
145
|
+
# Unknown subcommand
|
|
146
|
+
print_lines([
|
|
147
|
+
"Error: Unknown command '" + subcommand + "'",
|
|
148
|
+
"Run 'kujo run patchbrief.kujo -- help' for usage."
|
|
149
|
+
])
|
|
150
|
+
exit(2)
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
main()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/kujolang/patchbrief/schemas/handoff-1.0.json",
|
|
4
|
+
"title": "PatchBrief handoff JSON",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["format", "version", "generated_at", "repo", "branch", "summary", "analysis", "files", "risk_areas", "recent_commits", "reviewer_checklist"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"format": {"const": "patchbrief-handoff"},
|
|
9
|
+
"version": {"type": "string"},
|
|
10
|
+
"generated_at": {"type": "string"},
|
|
11
|
+
"repo": {"type": "string"},
|
|
12
|
+
"branch": {"type": "string"},
|
|
13
|
+
"summary": {
|
|
14
|
+
"type": "object",
|
|
15
|
+
"required": ["files_changed", "lines_added", "lines_removed", "likely_purpose"],
|
|
16
|
+
"properties": {
|
|
17
|
+
"files_changed": {"type": "integer", "minimum": 0},
|
|
18
|
+
"lines_added": {"type": "integer", "minimum": 0},
|
|
19
|
+
"lines_removed": {"type": "integer", "minimum": 0},
|
|
20
|
+
"likely_purpose": {"type": "string"}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"analysis": {
|
|
24
|
+
"type": "object",
|
|
25
|
+
"required": ["diff_bytes_analyzed", "diff_error", "diff_max_bytes", "diff_truncated"],
|
|
26
|
+
"properties": {
|
|
27
|
+
"diff_bytes_analyzed": {"type": "integer", "minimum": 0},
|
|
28
|
+
"diff_error": {"type": "boolean"},
|
|
29
|
+
"diff_max_bytes": {"type": "integer", "minimum": 1},
|
|
30
|
+
"diff_truncated": {"type": "boolean"}
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
"files": {"type": "array", "items": {"type": "string"}},
|
|
34
|
+
"risk_areas": {"type": "array", "items": {"type": "string"}},
|
|
35
|
+
"recent_commits": {"type": "array", "items": {"type": "string"}},
|
|
36
|
+
"reviewer_checklist": {"type": "array", "items": {"type": "string"}}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
+
"$id": "https://github.com/kujolang/patchbrief/schemas/summary-0.1.json",
|
|
4
|
+
"title": "PatchBrief summary JSON",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"required": ["tool", "version", "repo", "branch", "summary", "analysis", "files", "risk_areas", "likely_purpose", "recent_commits"],
|
|
7
|
+
"properties": {
|
|
8
|
+
"tool": {"const": "patchbrief"},
|
|
9
|
+
"version": {"type": "string"},
|
|
10
|
+
"repo": {"type": "string"},
|
|
11
|
+
"branch": {"type": "string"},
|
|
12
|
+
"summary": {
|
|
13
|
+
"type": "object",
|
|
14
|
+
"required": ["files_changed", "lines_added", "lines_removed"],
|
|
15
|
+
"properties": {
|
|
16
|
+
"files_changed": {"type": "integer", "minimum": 0},
|
|
17
|
+
"lines_added": {"type": "integer", "minimum": 0},
|
|
18
|
+
"lines_removed": {"type": "integer", "minimum": 0}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"analysis": {
|
|
22
|
+
"type": "object",
|
|
23
|
+
"required": ["diff_bytes_analyzed", "diff_error", "diff_max_bytes", "diff_truncated"],
|
|
24
|
+
"properties": {
|
|
25
|
+
"diff_bytes_analyzed": {"type": "integer", "minimum": 0},
|
|
26
|
+
"diff_error": {"type": "boolean"},
|
|
27
|
+
"diff_max_bytes": {"type": "integer", "minimum": 1},
|
|
28
|
+
"diff_truncated": {"type": "boolean"}
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": {
|
|
32
|
+
"type": "array",
|
|
33
|
+
"items": {
|
|
34
|
+
"type": "object",
|
|
35
|
+
"required": ["path", "language"],
|
|
36
|
+
"properties": {
|
|
37
|
+
"path": {"type": "string"},
|
|
38
|
+
"language": {"type": "string"}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"risk_areas": {"type": "array", "items": {"type": "string"}},
|
|
43
|
+
"likely_purpose": {"type": "string"},
|
|
44
|
+
"recent_commits": {"type": "array", "items": {"type": "string"}}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
# PatchBrief shared utilities.
|
|
2
|
+
# Provides helpers for CLI arg parsing, string formatting, and common operations.
|
|
3
|
+
|
|
4
|
+
TERMINAL_CONTROLS := parse_json("[\"\\u0007\",\"\\u0008\",\"\\u0009\",\"\\u000a\",\"\\u000b\",\"\\u000c\",\"\\u000d\",\"\\u000e\",\"\\u000f\",\"\\u001b\",\"\\u007f\"]")
|
|
5
|
+
TERMINAL_ESCAPES := ["\\u0007", "\\u0008", "\\u0009", "\\u000a", "\\u000b", "\\u000c", "\\u000d", "\\u000e", "\\u000f", "\\u001b", "\\u007f"]
|
|
6
|
+
MARKDOWN_ESCAPES := ["`", "[", "]", "<", ">", "(", ")", "!"]
|
|
7
|
+
|
|
8
|
+
export func is_trueish(value) {
|
|
9
|
+
return value == true || value == 1
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export func is_falseish(value) {
|
|
13
|
+
return value == false || value == 0
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
# Parse subcommand from CLI args.
|
|
17
|
+
# args() in Kujo returns only user arguments (script name is excluded).
|
|
18
|
+
# Returns argv[0] when it is a non-flag command token.
|
|
19
|
+
# PatchBrief intentionally requires command-first syntax.
|
|
20
|
+
# Check if a string starts with a prefix.
|
|
21
|
+
# Kujo's starts_with() may return int, so compare explicitly.
|
|
22
|
+
export func str_starts_with(s, prefix) {
|
|
23
|
+
return is_trueish(starts_with(s, prefix))
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# Check if a string contains a substring.
|
|
27
|
+
# Kujo's contains() returns int (1 or 0), so compare explicitly.
|
|
28
|
+
export func str_contains(s, substr) {
|
|
29
|
+
return is_trueish(contains(s, substr))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export func str_ends_with(s, suffix) {
|
|
33
|
+
return is_trueish(ends_with(s, suffix))
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export func dict_has_key(map_obj, key_name) {
|
|
37
|
+
return is_trueish(has_key(map_obj, key_name))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export func parse_subcommand(argv) {
|
|
41
|
+
if !is_array(argv) || len(argv) == 0 {
|
|
42
|
+
return ""
|
|
43
|
+
}
|
|
44
|
+
if str_starts_with(to_string(argv[0]), "-") {
|
|
45
|
+
return ""
|
|
46
|
+
}
|
|
47
|
+
return to_string(argv[0])
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export func has_flag(argv, name) {
|
|
51
|
+
if !is_array(argv) {
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
i := 0
|
|
55
|
+
while i < len(argv) {
|
|
56
|
+
if to_string(argv[i]) == name {
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
i = i + 1
|
|
60
|
+
}
|
|
61
|
+
return false
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export func flag_value(argv, name, fallback) {
|
|
65
|
+
if !is_array(argv) {
|
|
66
|
+
return fallback
|
|
67
|
+
}
|
|
68
|
+
i := 0
|
|
69
|
+
while i < len(argv) {
|
|
70
|
+
token := to_string(argv[i])
|
|
71
|
+
if token == name {
|
|
72
|
+
next_index := i + 1
|
|
73
|
+
if next_index < len(argv) {
|
|
74
|
+
return to_string(argv[next_index])
|
|
75
|
+
}
|
|
76
|
+
return fallback
|
|
77
|
+
}
|
|
78
|
+
prefix := name + "="
|
|
79
|
+
if str_starts_with(token, prefix) {
|
|
80
|
+
return substring(token, len(prefix), len(token))
|
|
81
|
+
}
|
|
82
|
+
i = i + 1
|
|
83
|
+
}
|
|
84
|
+
return fallback
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
# Trim whitespace from both ends of a string.
|
|
88
|
+
export func str_trim(s) {
|
|
89
|
+
return trim(s)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
# Convert a string to lowercase.
|
|
93
|
+
export func str_lower(s) {
|
|
94
|
+
return to_lower(s)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
# Join an array of strings with a separator.
|
|
98
|
+
export func str_join(arr, sep) {
|
|
99
|
+
mut result := ""
|
|
100
|
+
mut i := 0
|
|
101
|
+
while i < len(arr) {
|
|
102
|
+
if i > 0 {
|
|
103
|
+
result = result + sep
|
|
104
|
+
}
|
|
105
|
+
result = result + to_string(arr[i])
|
|
106
|
+
i = i + 1
|
|
107
|
+
}
|
|
108
|
+
return result
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export func print_lines(lines) {
|
|
112
|
+
idx := 0
|
|
113
|
+
while idx < len(lines) {
|
|
114
|
+
print(to_string(lines[idx]))
|
|
115
|
+
idx := idx + 1
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export func print_prefixed_lines(lines, prefix) {
|
|
120
|
+
idx := 0
|
|
121
|
+
while idx < len(lines) {
|
|
122
|
+
print(prefix + to_string(lines[idx]))
|
|
123
|
+
idx := idx + 1
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export func print_prefixed_or_fallback(lines, prefix, fallback) {
|
|
128
|
+
if len(lines) > 0 {
|
|
129
|
+
print_prefixed_lines(lines, prefix)
|
|
130
|
+
return
|
|
131
|
+
}
|
|
132
|
+
print_lines([fallback])
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export func print_wrapped_lines(lines, prefix, suffix) {
|
|
136
|
+
idx := 0
|
|
137
|
+
while idx < len(lines) {
|
|
138
|
+
print(prefix + to_string(lines[idx]) + suffix)
|
|
139
|
+
idx := idx + 1
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export func print_markdown_section(title) {
|
|
144
|
+
print_lines([
|
|
145
|
+
"",
|
|
146
|
+
"## " + title,
|
|
147
|
+
""
|
|
148
|
+
])
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export func print_markdown_paragraph(text) {
|
|
152
|
+
print_lines([to_string(text)])
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export func print_fenced(text) {
|
|
156
|
+
print_lines([
|
|
157
|
+
"```",
|
|
158
|
+
to_string(text),
|
|
159
|
+
"```"
|
|
160
|
+
])
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export func print_not_git_repo_error() {
|
|
164
|
+
print_lines(["Error: Not a git repository. Run patchbrief inside a git repo."])
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
# Render repository-controlled text safely in Markdown and terminals.
|
|
168
|
+
# JSON output intentionally keeps the original values and relies on JSON escaping.
|
|
169
|
+
export func sanitize_terminal_text(value) {
|
|
170
|
+
text := to_string(value)
|
|
171
|
+
idx := 0
|
|
172
|
+
while idx < len(TERMINAL_CONTROLS) {
|
|
173
|
+
text = replace(text, to_string(TERMINAL_CONTROLS[idx]), to_string(TERMINAL_ESCAPES[idx]))
|
|
174
|
+
idx := idx + 1
|
|
175
|
+
}
|
|
176
|
+
return text
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export func markdown_text(value) {
|
|
180
|
+
text := sanitize_terminal_text(value)
|
|
181
|
+
text = replace(text, "\\", "\\\\")
|
|
182
|
+
idx := 0
|
|
183
|
+
while idx < len(MARKDOWN_ESCAPES) {
|
|
184
|
+
char := to_string(MARKDOWN_ESCAPES[idx])
|
|
185
|
+
text = replace(text, char, "\\" + char)
|
|
186
|
+
idx := idx + 1
|
|
187
|
+
}
|
|
188
|
+
return text
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export func markdown_code(value) {
|
|
192
|
+
text := sanitize_terminal_text(value)
|
|
193
|
+
text = replace(text, "&", "&")
|
|
194
|
+
text = replace(text, "<", "<")
|
|
195
|
+
text = replace(text, ">", ">")
|
|
196
|
+
return "<code>" + text + "</code>"
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
# Get the current timestamp as an ISO-like string.
|
|
200
|
+
export func timestamp_now() {
|
|
201
|
+
try {
|
|
202
|
+
result := execute("date -u +%Y-%m-%dT%H:%M:%SZ", {"timeout_ms": 3000})
|
|
203
|
+
return trim(to_string(result))
|
|
204
|
+
} except err {
|
|
205
|
+
return "unknown"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
export func shell_quote(value) {
|
|
210
|
+
text := to_string(value)
|
|
211
|
+
return "'" + replace(text, "'", "'\"'\"'") + "'"
|
|
212
|
+
}
|