-
-
Notifications
You must be signed in to change notification settings - Fork 829
Expand file tree
/
Copy pathinit.rs
More file actions
101 lines (84 loc) · 2.41 KB
/
Copy pathinit.rs
File metadata and controls
101 lines (84 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use std::{
fs,
path::{Path, PathBuf},
};
use anyhow::{Context, Result, bail};
use crate::cli::InitOpts;
const TEMPLATE: &str = r#"version = 1
[[tasks]]
name = "setup"
command = ""
description = "Project setup (fill me)"
shortcuts = ["s"]
[[tasks]]
name = "dev"
command = ""
description = "Start dev server (fill me)"
dependencies = ["setup"]
shortcuts = ["d"]
[skills]
sync_tasks = true
install = ["quality-bun-feature-delivery"]
[skills.codex]
generate_openai_yaml = true
force_reload_after_sync = true
task_skill_allow_implicit_invocation = false
[commit.skill_gate]
mode = "block"
required = ["quality-bun-feature-delivery"]
[commit.skill_gate.min_version]
quality-bun-feature-delivery = 2
# Bun-focused optional test gate:
#
#[commit.testing]
#mode = "block"
#runner = "bun"
#bun_repo_strict = true
#require_related_tests = true
#ai_scratch_test_dir = ".ai/test"
#run_ai_scratch_tests = true
#allow_ai_scratch_to_satisfy_gate = false
#max_local_gate_seconds = 20
"#;
pub(crate) fn write_template(path: &Path) -> Result<()> {
if let Some(parent) = path.parent() {
if !parent.as_os_str().is_empty() {
fs::create_dir_all(parent)
.with_context(|| format!("failed to create directory {}", parent.display()))?;
}
}
fs::write(path, TEMPLATE).with_context(|| format!("failed to write {}", path.display()))?;
Ok(())
}
pub fn run(opts: InitOpts) -> Result<()> {
let target = resolve_path(opts.path);
if target.exists() {
bail!("{} already exists; refusing to overwrite", target.display());
}
write_template(&target)?;
println!("created {}", target.display());
Ok(())
}
fn resolve_path(path: Option<PathBuf>) -> PathBuf {
match path {
Some(p) if p.is_absolute() => p,
Some(p) => std::env::current_dir()
.unwrap_or_else(|_| PathBuf::from("."))
.join(p),
None => std::env::current_dir()
.unwrap_or_else(|_| PathBuf::from("."))
.join("flow.toml"),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn template_includes_codex_skill_baseline() {
assert!(TEMPLATE.contains("[skills]"));
assert!(TEMPLATE.contains("install = [\"quality-bun-feature-delivery\"]"));
assert!(TEMPLATE.contains("[skills.codex]"));
assert!(TEMPLATE.contains("[commit.skill_gate]"));
assert!(TEMPLATE.contains("quality-bun-feature-delivery = 2"));
}
}