Repository navigation
feat(cron): optional per-job project directory for agent crons - #29564
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the optional field is additive, it reuses the chat folder's project-directory check, and a directory that can't be used fails the run instead of quietly running somewhere else. Notes
[DESIGN-REVIEWED] ae1da87 Description read[DESCRIPTION-READ] e23d219ebe50b23f9e3d2e579e15127661adcd3f074037903a6e0665bb70e3ec That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks: the new field is optional and off by default, path checking reuses the existing chat-folder What this change shipsInventory (7 items) — 7 justifiedIntent: let a scheduled agent job run inside a chosen repo so that repo's steering rules and
[FIRST-PRINCIPLES-REVIEWED] ae1da87 Description read[DESCRIPTION-READ] 40070ad8545591d13b383c8ba1112284949e9cf468a2db0dac74d055aa9c5b37 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
5c36860 to
27b98c0
Compare
27b98c0 to
bbc6e43
Compare
bbc6e43 to
dda7c3b
Compare
An agent cron's session ran in the bound agent's workspace or a per-run scratch directory, so a repo's own .kiro/steering/ and AGENTS.md never loaded for a cron doing repo work (#13349). A job may now carry `project_path`: when set, its agent session runs in that directory on every fire (it outranks the agent alias's workspace; every step of an agent_sequence uses it). When empty, nothing changes. - CronJob.project_path, default "". A record without the key loads as "" and fires unchanged; the key is written only when set, so existing stores keep their bytes. - resolve_project_path: absolute existing directory, not UNC-shaped, not is_sensitive_path after realpath; stored resolved. Refused on script and command jobs. Re-checked at every fire: a directory that can no longer be used fails the run (non-transient) instead of running without the project's rules. - CLI: `cron add --project-path DIR`, `cron update --project-path DIR` ('' clears), `cron list` prints it. MCP and the dashboard form do not take it yet. - Spec: learn-cron-dashboard.md "Project Directory (project_path)", cli.md, kirocrew-commands skill. Closes #13349 Refs #9201 #8952
dda7c3b to
ae1da87
Compare
bolichen97
left a comment
There was a problem hiding this comment.
Approving ae1da87. I read the full product diff and the test list at this head.
resolve_project_pathreuses the chat folder's_validate_project_dir(absolute or~, realpath, not a sensitive path, an existing directory) and adds a network-share refusal before and after resolving. So a cron job cannot root itself anywhere a dashboard project could not.- The path is checked on create, on update (before any field is assigned, so a refusal leaves the job untouched) and again at every fire. A fire-time refusal is marked not transient, so it counts as a failure instead of retrying.
- Script and command jobs refuse the field.
- The store writes
project_pathonly when it is set, so an existingcrons.jsonkeeps its bytes, and_KNOWN_JOB_KEYSlists it. - Both the single-agent and sequence paths pick the cwd through
cron_session_cwd, off the event loop. - Tests cover the round trip, refusals, update and clear, the fire cwd, the unchanged default, a removed directory, and the CLI flags.
Non-blocking note: a live session under cron:<job id> is reused without comparing cwd. So if project_path changes while a run is still held open by pending sub-agents, that next fire runs in the old directory. Sessions are normally reset after each run, so the window is small. It could share the existing agent-mismatch defer later.
No regex, glob or case-blind matching is added. The linked issue is T2. All 96 checks pass.
Problem / Motivation
Goal: A scheduled agent job can run in a chosen project directory, so that repo's own steering rules and
AGENTS.mdload for the job.An LLM-message cron has no per-job project directory. Its session runs in the bound agent's workspace, or in a per-run scratch directory (
workspace_root()/cron_<job_id>_<run_id>/) when no agent alias is bound. Neither is the repo the job works on, so the repo's.kiro/steering/**/*.mdnever loads. The reporter's maintenance cron committed straight to the shared checkout because the repo's "worktree + PR" rule never reached it (#13349). The triage comment on the issue confirmed the gap is the session cwd.Why it matters
A cron that does real repo work (opens a PR, builds, deploys) silently loses every policy the repo keeps in its steering files. The only workaround today is to copy the policy into the cron message, where it goes stale as the repo's rules change.
Not a goal
cron_add/cron_updateand the dashboard Schedule form do not take the field yet. Which directories an agent-authored job may root itself in is its own admission decision (feat(cron): bind scheduled jobs to a project's agents #9201, cron: project agents never show up in the Schedule page's agent picker, and the binding can't persist #8952).What changed (motivation → approach → change)
Symptom: repo steering never loads in a cron. Cause: the cron session's cwd is never the repo. Change: an optional per-job
project_paththat becomes the session cwd.CronJob.project_path(default""). The store reads a missing key as""and writes the key only when it is set, so an existingcrons.jsonkeeps its bytes and an older build round-trips the key as an unknown field.cron_service/fields.py:resolve_project_pathdelegates to the chat folder's_validate_project_dir(absolute or~,realpath, notis_sensitive_path, an existing directory), so there is one fence. It only adds a UNC refusal on the raw and resolved path. The resolved path is stored.build_jobandapply_job_updaterun it before any assignment. A script or command job is refused, because it opens no agent session.cron_session_cwd(job, resolved_cwd)is the one place that picks the cwd. An emptyproject_pathreturns the cwd_resolve_cron_agentchose, so nothing changes. A set one outranks the alias workspace: it is the per-job choice. It re-checks the path at every fire, off the loop. A directory that is gone or now sensitive fails the run with a non-transient error that names the--project-path ''fix. It never falls back to a cwd without the project's rules.cron_turn.py: both dispatch paths call it right after_resolve_cron_agent(single agent, and eachagent_sequencestep). The agent, crew identity, model pins and capability gates still come from the alias.kirocrew cron add --project-path DIR,kirocrew cron update JOB --project-path DIR(''clears), andkirocrew cron listprintsproject: <dir>. The kwarg rides in theadd_jobcall only when set, so other creates keep their call shape.learn-cron-dashboard.md§ "Project Directory (project_path)". Also updatedcli.mdand thekirocrew-commandsskill.The field name follows the consolidation note on #13408:
project_pathis the one field. #9201's takeover (#8952) can build on it.Backwards compatibility
Compatible: the field is optional with default
"", and an empty value takes the exact cwd path it took before. A record without the key loads and fires unchanged (test_a_record_written_before_the_field_loads_unchanged). A store with no project directories saves to the same bytes (thetest_cron_refactor_contract.pygolden-bytes tests pass unchanged).Removes nothing: the change only adds an optional field, two CLI flags and a list detail. No existing key, validator or path is narrowed.
Tests
test/test_cron_project_path.py:""and keeps the resolved cwd;tmp_pathchild), sensitive, script/command job;cwd=<project>while the agent andcrew_agentstill come from the alias;test/test_cron_sequence_member_alias.py::test_a_sequence_with_a_project_path_runs_every_step_there: each sequence step runs in the project directory as its own crew.test_cron_service_bindings.py: the pinned signature digests for_build_job,add_jobandadd_job_asyncwere updated for the new keyword.test_cron_string_field_validation.py:project_pathis listed as a field with noCRON_ADD_SCHEMAentry.Proof: PROVEN by hand-applied mutations on the committed head, each restored by path:
cron_session_cwdcalltest_a_fire_runs_the_session_in_the_project_directory,test_a_project_directory_that_is_gone_fails_the_runtest_a_sequence_with_a_project_path_runs_every_step_theretest_project_path_round_trips_through_the_store,test_cli_add_and_update_carry_project_pathtest_a_project_directory_that_is_gone_fails_the_run,test_the_fire_time_refusal_is_not_transienttest_a_sensitive_directory_is_refusedtest_script_and_command_jobs_refuse_a_project_pathTargeted runs (by path,
-n0): the cron, CLI-cron and gateway-cron test files, 517 + 166 passed. The full suite was not run locally.Manual verification
Not run on a live gateway or pod. The dispatch tests drive the real
_cron_callbackthrough_cron_run_single/_cron_run_sequencewith a mocked session manager and assert thecwdkwarg it receives. That kiro-cli then loads.kiro/steering/from the session cwd is existing, documented behaviour (src/kiro_crew/docs/steering-and-hooks.md), not something this PR changes. Windows: the UNC refusal reusesis_unc_shape. Nothing was run on a Windows host, so Windows behaviour is unverified.Related Issues
Closes #13349
Refs #9201 #8952
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributed under the project's Apache-2.0 license.